diff --git a/shared_utils/advanced_markdown_format.py b/shared_utils/advanced_markdown_format.py
index f2849d0..f6feb0e 100644
--- a/shared_utils/advanced_markdown_format.py
+++ b/shared_utils/advanced_markdown_format.py
@@ -10,6 +10,26 @@ from shared_utils.config_loader import get_conf as get_conf
pj = os.path.join
default_user_name = 'default_user'
+markdown_extension_configs = {
+ 'mdx_math': {
+ 'enable_dollar_delimiter': True,
+ 'use_gitlab_delimiters': False,
+ },
+}
+
+
+code_highlight_configs = {
+ "pymdownx.superfences": {
+ 'css_class': 'codehilite',
+ },
+ "pymdownx.highlight": {
+ 'css_class': 'codehilite',
+ 'guess_lang': True,
+ # 'auto_title': True,
+ # 'linenums': True
+ }
+}
+
def text_divide_paragraph(text):
"""
将文本按照段落分隔符分割开,生成带有段落标签的HTML代码。
@@ -33,6 +53,7 @@ def text_divide_paragraph(text):
text = "".join(lines)
return pre + text + suf
+
def tex2mathml_catch_exception(content, *args, **kwargs):
try:
content = tex2mathml(content, *args, **kwargs)
@@ -40,6 +61,7 @@ def tex2mathml_catch_exception(content, *args, **kwargs):
content = content
return content
+
def replace_math_no_render(match):
content = match.group(1)
if 'mode=display' in match.group(0):
@@ -48,6 +70,7 @@ def replace_math_no_render(match):
else:
return f"${content}$"
+
def replace_math_render(match):
content = match.group(1)
if 'mode=display' in match.group(0):
@@ -60,6 +83,7 @@ def replace_math_render(match):
else:
return tex2mathml_catch_exception(content)
+
def markdown_bug_hunt(content):
"""
解决一个mdx_math的bug(单$包裹begin命令时多余\n', '')
return content
+
def is_equation(txt):
"""
判定是否为公式 | 测试1 写出洛伦兹定律,使用tex格式公式 测试2 给出柯西不等式,使用latex格式 测试3 写出麦克斯韦方程组
@@ -99,6 +124,7 @@ def is_equation(txt):
contain_any_eq = True
return contain_any_eq
+
def fix_markdown_indent(txt):
# fix markdown indent
if (' - ' not in txt) or ('. ' not in txt):
@@ -119,6 +145,7 @@ def fix_markdown_indent(txt):
lines[i] = ' ' * num_spaces_should_be + stripped_string
return '\n'.join(lines)
+
FENCED_BLOCK_RE = re.compile(
dedent(r'''
(?P^[ \t]*(?:~{3,}|`{3,}))[ ]* # opening fence
@@ -132,6 +159,7 @@ FENCED_BLOCK_RE = re.compile(
re.MULTILINE | re.DOTALL | re.VERBOSE
)
+
def get_line_range(re_match_obj, txt):
start_pos, end_pos = re_match_obj.regs[0]
num_newlines_before = txt[:start_pos+1].count('\n')
@@ -139,6 +167,7 @@ def get_line_range(re_match_obj, txt):
line_end = num_newlines_before + txt[start_pos:end_pos].count('\n')+1
return line_start, line_end
+
def fix_code_segment_indent(txt):
lines = []
change_any = False
@@ -175,6 +204,7 @@ def fix_code_segment_indent(txt):
else:
return txt
+
@lru_cache(maxsize=128) # 使用 lru缓存 加快转换速度
def markdown_convertion(txt):
"""
@@ -186,12 +216,6 @@ def markdown_convertion(txt):
# print('警告,输入了已经经过转化的字符串,二次转化可能出问题')
return txt # 已经被转化过,不需要再次转化
- markdown_extension_configs = {
- 'mdx_math': {
- 'enable_dollar_delimiter': True,
- 'use_gitlab_delimiters': False,
- },
- }
find_equation_pattern = r'