From 2df4742815f2076abe16134752cd4798847fc128 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 7 Apr 2023 18:14:27 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=AC=E5=BC=8F?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- toolbox.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/toolbox.py b/toolbox.py index 0b1c85c..75cc847 100644 --- a/toolbox.py +++ b/toolbox.py @@ -6,7 +6,7 @@ import traceback import importlib import inspect import re -from show_math import convert as convert_math +from latex2mathml.converter import convert as tex2mathml from functools import wraps, lru_cache @@ -203,8 +203,51 @@ def markdown_convertion(txt): """ pre = '
' suf = '
' - if ('$' in txt) and ('```' not in txt): - return pre + markdown.markdown(txt, extensions=['fenced_code', 'tables']) + '

' + markdown.markdown(convert_math(txt, splitParagraphs=False), extensions=['fenced_code', 'tables']) + suf + markdown_extension_configs = { + 'mdx_math': { + 'enable_dollar_delimiter': True, + 'use_gitlab_delimiters': False, + }, + } + find_equation_pattern = r'\n', '') + return content + + if ('$' in txt) and ('```' not in txt): # 有$标识的公式符号,且没有代码段```的标识 # convert everything to html format split = markdown.markdown(text='---') convert_stage_1 = markdown.markdown(text=txt, extensions=['mdx_math', 'fenced_code', 'tables', 'sane_lists'], extension_configs=markdown_extension_configs) + convert_stage_1 = markdown_bug_hunt(convert_stage_1) # 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). # 1. convert to easy-to-copy tex (do not render math) convert_stage_2_1, n = re.subn(find_equation_pattern, replace_math_no_render, convert_stage_1, flags=re.DOTALL)