镜像自地址
https://github.com/binary-husky/gpt_academic.git
已同步 2025-12-06 06:26:47 +00:00
prevent html rendering for input
这个提交包含在:
@@ -2,6 +2,7 @@ import markdown
|
|||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import math
|
import math
|
||||||
|
import html
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
@@ -421,6 +422,14 @@ def special_render_issues_for_mermaid(text):
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def contain_html_tag(text):
|
||||||
|
"""
|
||||||
|
判断文本中是否包含HTML标签。
|
||||||
|
"""
|
||||||
|
pattern = r'</?([a-zA-Z0-9_]{3,16})>|<script\s+[^>]*src=["\']([^"\']+)["\'][^>]*>'
|
||||||
|
return re.search(pattern, text) is not None
|
||||||
|
|
||||||
|
|
||||||
def compat_non_markdown_input(text):
|
def compat_non_markdown_input(text):
|
||||||
"""
|
"""
|
||||||
改善非markdown输入的显示效果,例如将空格转换为 ,将换行符转换为</br>等。
|
改善非markdown输入的显示效果,例如将空格转换为 ,将换行符转换为</br>等。
|
||||||
@@ -429,9 +438,10 @@ def compat_non_markdown_input(text):
|
|||||||
# careful input:markdown输入
|
# careful input:markdown输入
|
||||||
text = special_render_issues_for_mermaid(text) # 处理特殊的渲染问题
|
text = special_render_issues_for_mermaid(text) # 处理特殊的渲染问题
|
||||||
return text
|
return text
|
||||||
elif "</div>" in text:
|
elif ("<" in text) and (">" in text) and contain_html_tag(text):
|
||||||
# careful input:html输入
|
# careful input:html输入
|
||||||
return text
|
escaped_text = html.escape(text)
|
||||||
|
return escaped_text
|
||||||
else:
|
else:
|
||||||
# whatever input:非markdown输入
|
# whatever input:非markdown输入
|
||||||
lines = text.split("\n")
|
lines = text.split("\n")
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户