perf: View the internal message and convert the content into markdown

This commit is contained in:
feng
2024-08-27 16:46:41 +08:00
committed by feng626
parent 25a473dc99
commit b9e64747ac
5 changed files with 52 additions and 29 deletions

View File

@@ -13,6 +13,7 @@ from collections import OrderedDict
from functools import wraps
from itertools import chain
import html2text
import psutil
from django.conf import settings
from django.templatetags.static import static
@@ -421,3 +422,14 @@ def distinct(seq, key=None):
def is_macos():
return platform.system() == 'Darwin'
def convert_html_to_markdown(html_str):
h = html2text.HTML2Text()
h.body_width = 0
h.ignore_links = True
markdown = h.handle(html_str)
markdown = markdown.replace('\n\n', '\n')
markdown = markdown.replace('\n ', '\n')
return markdown