代码、公式高亮
Browse files- theme.py +73 -0
- toolbox.py +14 -3
theme.py
CHANGED
@@ -153,4 +153,77 @@ advanced_css = """
|
|
153 |
padding: 1em;
|
154 |
margin: 1em 2em 1em 0.5em;
|
155 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
"""
|
|
|
153 |
padding: 1em;
|
154 |
margin: 1em 2em 1em 0.5em;
|
155 |
}
|
156 |
+
|
157 |
+
|
158 |
+
|
159 |
+
|
160 |
+
.hll { background-color: #ffffcc }
|
161 |
+
.c { color: #3D7B7B; font-style: italic } /* Comment */
|
162 |
+
.err { border: 1px solid #FF0000 } /* Error */
|
163 |
+
.k { color: #008000; font-weight: bold } /* Keyword */
|
164 |
+
.o { color: #666666 } /* Operator */
|
165 |
+
.ch { color: #3D7B7B; font-style: italic } /* Comment.Hashbang */
|
166 |
+
.cm { color: #3D7B7B; font-style: italic } /* Comment.Multiline */
|
167 |
+
.cp { color: #9C6500 } /* Comment.Preproc */
|
168 |
+
.cpf { color: #3D7B7B; font-style: italic } /* Comment.PreprocFile */
|
169 |
+
.c1 { color: #3D7B7B; font-style: italic } /* Comment.Single */
|
170 |
+
.cs { color: #3D7B7B; font-style: italic } /* Comment.Special */
|
171 |
+
.gd { color: #A00000 } /* Generic.Deleted */
|
172 |
+
.ge { font-style: italic } /* Generic.Emph */
|
173 |
+
.gr { color: #E40000 } /* Generic.Error */
|
174 |
+
.gh { color: #000080; font-weight: bold } /* Generic.Heading */
|
175 |
+
.gi { color: #008400 } /* Generic.Inserted */
|
176 |
+
.go { color: #717171 } /* Generic.Output */
|
177 |
+
.gp { color: #000080; font-weight: bold } /* Generic.Prompt */
|
178 |
+
.gs { font-weight: bold } /* Generic.Strong */
|
179 |
+
.gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
180 |
+
.gt { color: #0044DD } /* Generic.Traceback */
|
181 |
+
.kc { color: #008000; font-weight: bold } /* Keyword.Constant */
|
182 |
+
.kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
|
183 |
+
.kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
|
184 |
+
.kp { color: #008000 } /* Keyword.Pseudo */
|
185 |
+
.kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
|
186 |
+
.kt { color: #B00040 } /* Keyword.Type */
|
187 |
+
.m { color: #666666 } /* Literal.Number */
|
188 |
+
.s { color: #BA2121 } /* Literal.String */
|
189 |
+
.na { color: #687822 } /* Name.Attribute */
|
190 |
+
.nb { color: #008000 } /* Name.Builtin */
|
191 |
+
.nc { color: #0000FF; font-weight: bold } /* Name.Class */
|
192 |
+
.no { color: #880000 } /* Name.Constant */
|
193 |
+
.nd { color: #AA22FF } /* Name.Decorator */
|
194 |
+
.ni { color: #717171; font-weight: bold } /* Name.Entity */
|
195 |
+
.ne { color: #CB3F38; font-weight: bold } /* Name.Exception */
|
196 |
+
.nf { color: #0000FF } /* Name.Function */
|
197 |
+
.nl { color: #767600 } /* Name.Label */
|
198 |
+
.nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
|
199 |
+
.nt { color: #008000; font-weight: bold } /* Name.Tag */
|
200 |
+
.nv { color: #19177C } /* Name.Variable */
|
201 |
+
.ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
|
202 |
+
.w { color: #bbbbbb } /* Text.Whitespace */
|
203 |
+
.mb { color: #666666 } /* Literal.Number.Bin */
|
204 |
+
.mf { color: #666666 } /* Literal.Number.Float */
|
205 |
+
.mh { color: #666666 } /* Literal.Number.Hex */
|
206 |
+
.mi { color: #666666 } /* Literal.Number.Integer */
|
207 |
+
.mo { color: #666666 } /* Literal.Number.Oct */
|
208 |
+
.sa { color: #BA2121 } /* Literal.String.Affix */
|
209 |
+
.sb { color: #BA2121 } /* Literal.String.Backtick */
|
210 |
+
.sc { color: #BA2121 } /* Literal.String.Char */
|
211 |
+
.dl { color: #BA2121 } /* Literal.String.Delimiter */
|
212 |
+
.sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
|
213 |
+
.s2 { color: #BA2121 } /* Literal.String.Double */
|
214 |
+
.se { color: #AA5D1F; font-weight: bold } /* Literal.String.Escape */
|
215 |
+
.sh { color: #BA2121 } /* Literal.String.Heredoc */
|
216 |
+
.si { color: #A45A77; font-weight: bold } /* Literal.String.Interpol */
|
217 |
+
.sx { color: #008000 } /* Literal.String.Other */
|
218 |
+
.sr { color: #A45A77 } /* Literal.String.Regex */
|
219 |
+
.s1 { color: #BA2121 } /* Literal.String.Single */
|
220 |
+
.ss { color: #19177C } /* Literal.String.Symbol */
|
221 |
+
.bp { color: #008000 } /* Name.Builtin.Pseudo */
|
222 |
+
.fm { color: #0000FF } /* Name.Function.Magic */
|
223 |
+
.vc { color: #19177C } /* Name.Variable.Class */
|
224 |
+
.vg { color: #19177C } /* Name.Variable.Global */
|
225 |
+
.vi { color: #19177C } /* Name.Variable.Instance */
|
226 |
+
.vm { color: #19177C } /* Name.Variable.Magic */
|
227 |
+
.il { color: #666666 } /* Literal.Number.Integer.Long */
|
228 |
+
|
229 |
"""
|
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\"
|
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', 'codehilite', 'tables', 'sane_lists']) + suf
|
264 |
|
265 |
|
266 |
def close_up_code_segment_during_stream(gpt_reply):
|