3v324v23 commited on
Commit
28a4188
2 Parent(s): 9ca7a90 c2dcab0

Merge branch 'master' into dev

Browse files
Files changed (2) hide show
  1. README.md +2 -1
  2. toolbox.py +14 -3
README.md CHANGED
@@ -69,10 +69,11 @@ huggingface免科学上网[在线体验](https://huggingface.co/spaces/qingxu98/
69
 
70
  - 如果输出包含公式,会同时以tex形式和渲染形式显示,方便复制和阅读
71
  <div align="center">
72
- <img src="img/demo.jpg" width="500" >
73
  </div>
74
 
75
 
 
76
  - 懒得看项目代码?整个工程直接给chatgpt炫嘴里
77
  <div align="center">
78
  <img src="https://user-images.githubusercontent.com/96192199/226935232-6b6a73ce-8900-4aee-93f9-733c7e6fef53.png" width="700" >
 
69
 
70
  - 如果输出包含公式,会同时以tex形式和渲染形式显示,方便复制和阅读
71
  <div align="center">
72
+ <img src="https://user-images.githubusercontent.com/96192199/230598842-1d7fcddd-815d-40ee-af60-baf488a199df.png" width="700" >
73
  </div>
74
 
75
 
76
+
77
  - 懒得看项目代码?整个工程直接给chatgpt炫嘴里
78
  <div align="center">
79
  <img src="https://user-images.githubusercontent.com/96192199/226935232-6b6a73ce-8900-4aee-93f9-733c7e6fef53.png" width="700" >
toolbox.py CHANGED
@@ -224,7 +224,7 @@ def markdown_convertion(txt):
224
  content = content.replace('\n', '</br>')
225
  return f"<font color=\"#00FF00\">$$</font><font color=\"#FF00FF\">{content}</font><font color=\"#00FF00\">$$</font>"
226
  else:
227
- return f"<font color=\"#00FF00\">$</font><font color=\"#FF00FF\">${content}</font><font color=\"#00FF00\">$</font>"
228
 
229
  def replace_math_render(match):
230
  content = match.group(1)
@@ -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'], 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)
@@ -249,7 +260,7 @@ def markdown_convertion(txt):
249
  # cat them together
250
  return pre + convert_stage_2_1 + f'{split}' + convert_stage_2_2 + suf
251
  else:
252
- return pre + markdown.markdown(txt, extensions=['fenced_code', 'tables']) + suf
253
 
254
 
255
  def close_up_code_segment_during_stream(gpt_reply):
 
224
  content = content.replace('\n', '</br>')
225
  return f"<font color=\"#00FF00\">$$</font><font color=\"#FF00FF\">{content}</font><font color=\"#00FF00\">$$</font>"
226
  else:
227
+ return f"<font color=\"#00FF00\">$</font><font color=\"#FF00FF\">{content}</font><font color=\"#00FF00\">$</font>"
228
 
229
  def replace_math_render(match):
230
  content = match.group(1)
 
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)
 
260
  # cat them together
261
  return pre + convert_stage_2_1 + f'{split}' + convert_stage_2_2 + suf
262
  else:
263
+ return pre + markdown.markdown(txt, extensions=['fenced_code', 'tables', 'sane_lists']) + suf
264
 
265
 
266
  def close_up_code_segment_during_stream(gpt_reply):