File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 2
2
import re
3
3
import os
4
4
import math
5
+ import html
5
6
6
7
from loguru import logger
7
8
from textwrap import dedent
@@ -421,6 +422,14 @@ def get_special_case():
421
422
return text
422
423
423
424
425
+ def contain_html_tag (text ):
426
+ """
427
+ 判断文本中是否包含HTML标签。
428
+ """
429
+ pattern = r'</?([a-zA-Z0-9_]{3,16})>|<script\s+[^>]*src=["\']([^"\']+)["\'][^>]*>'
430
+ return re .search (pattern , text ) is not None
431
+
432
+
424
433
def compat_non_markdown_input (text ):
425
434
"""
426
435
改善非markdown输入的显示效果,例如将空格转换为 ,将换行符转换为</br>等。
@@ -429,9 +438,10 @@ def compat_non_markdown_input(text):
429
438
# careful input:markdown输入
430
439
text = special_render_issues_for_mermaid (text ) # 处理特殊的渲染问题
431
440
return text
432
- elif "</div >" in text :
441
+ elif ( "<" in text ) and ( " >" in text ) and contain_html_tag ( text ) :
433
442
# careful input:html输入
434
- return text
443
+ escaped_text = html .escape (text )
444
+ return escaped_text
435
445
else :
436
446
# whatever input:非markdown输入
437
447
lines = text .split ("\n " )
You can’t perform that action at this time.
0 commit comments