Spaces:
Runtime error
Runtime error
修复小BUG
Browse files- toolbox.py +11 -0
toolbox.py
CHANGED
|
@@ -237,10 +237,21 @@ def markdown_convertion(txt):
|
|
| 237 |
return content
|
| 238 |
else:
|
| 239 |
return tex2mathml_catch_exception(content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
if ('$' in txt) and ('```' not in txt): # 有$标识的公式符号,且没有代码段```的标识
|
| 241 |
# convert everything to html format
|
| 242 |
split = markdown.markdown(text='---')
|
| 243 |
convert_stage_1 = markdown.markdown(text=txt, extensions=['mdx_math', 'fenced_code', 'tables', 'sane_lists'], extension_configs=markdown_extension_configs)
|
|
|
|
| 244 |
# re.DOTALL: Make the '.' special character match any character at all, including a newline; without this flag, '.' will match anything except a newline. Corresponds to the inline flag (?s).
|
| 245 |
# 1. convert to easy-to-copy tex (do not render math)
|
| 246 |
convert_stage_2_1, n = re.subn(find_equation_pattern, replace_math_no_render, convert_stage_1, flags=re.DOTALL)
|
|
|
|
| 237 |
return content
|
| 238 |
else:
|
| 239 |
return tex2mathml_catch_exception(content)
|
| 240 |
+
|
| 241 |
+
def markdown_bug_hunt(content):
|
| 242 |
+
"""
|
| 243 |
+
解决一个mdx_math的bug(单$包裹begin命令时多余<script>)
|
| 244 |
+
"""
|
| 245 |
+
content = content.replace('<script type="math/tex">\n<script type="math/tex; mode=display">', '<script type="math/tex; mode=display">')
|
| 246 |
+
content = content.replace('</script>\n</script>', '</script>')
|
| 247 |
+
return content
|
| 248 |
+
|
| 249 |
+
|
| 250 |
if ('$' in txt) and ('```' not in txt): # 有$标识的公式符号,且没有代码段```的标识
|
| 251 |
# convert everything to html format
|
| 252 |
split = markdown.markdown(text='---')
|
| 253 |
convert_stage_1 = markdown.markdown(text=txt, extensions=['mdx_math', 'fenced_code', 'tables', 'sane_lists'], extension_configs=markdown_extension_configs)
|
| 254 |
+
convert_stage_1 = markdown_bug_hunt(convert_stage_1)
|
| 255 |
# re.DOTALL: Make the '.' special character match any character at all, including a newline; without this flag, '.' will match anything except a newline. Corresponds to the inline flag (?s).
|
| 256 |
# 1. convert to easy-to-copy tex (do not render math)
|
| 257 |
convert_stage_2_1, n = re.subn(find_equation_pattern, replace_math_no_render, convert_stage_1, flags=re.DOTALL)
|