From 2333b4e8ef60ef4d76a613fb88e836d4b1bdf5a7 Mon Sep 17 00:00:00 2001 From: w_xiaolizu Date: Sun, 18 Jun 2023 18:45:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=B8=80=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E4=BC=98=E5=8C=96=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- toolbox.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/toolbox.py b/toolbox.py index 2d98f88..f6cb609 100644 --- a/toolbox.py +++ b/toolbox.py @@ -1,21 +1,16 @@ import markdown import importlib -import time import inspect -import re import gradio as gr import func_box -import os from latex2mathml.converter import convert as tex2mathml from functools import wraps, lru_cache -import logging import shutil import os import time import glob import sys from concurrent.futures import ThreadPoolExecutor -import html ############################### 插件输入输出接驳区 ####################################### """ @@ -297,7 +292,7 @@ def text_divide_paragraph(input_str): return input_str -@lru_cache(maxsize=128) # 使用 lru缓存 加快转换速度 +@lru_cache(maxsize=128) # 使用 lru缓存 加快转换速度 def markdown_convertion(txt): """ 将Markdown格式的文本转换为HTML格式。如果包含数学公式,则先将公式转换为HTML格式。 @@ -306,14 +301,15 @@ def markdown_convertion(txt): suf = '' if txt.startswith(pre) and txt.endswith(suf): # print('警告,输入了已经经过转化的字符串,二次转化可能出问题') - return txt # 已经被转化过,不需要再次转化 - + return txt # 已经被转化过,不需要再次转化 + markdown_extension_configs = { 'mdx_math': { 'enable_dollar_delimiter': True, 'use_gitlab_delimiters': False, }, } + find_equation_pattern = r'\n', '') return content def no_code(txt): - if '```' not in txt: + if '```' not in txt: return True else: - if '```reference' in txt: return True # newbing - else: return False + if '```reference' in txt: + return True # newbing + else: + return False - if ('$$' in txt) and no_code(txt): # 有$标识的公式符号,且没有代码段```的标识 + if ('$' in txt) and no_code(txt): # 有$标识的公式符号,且没有代码段```的标识 # convert everything to html format split = markdown.markdown(text='---') - find_equation_pattern = r'