Spaces:
Sleeping
Sleeping
Chuan Hu
commited on
修正某些情况下代码块显示异常问题,感谢@RMStonight
Browse files- ChuanhuChatbot.py +12 -5
ChuanhuChatbot.py
CHANGED
@@ -25,18 +25,25 @@ else:
|
|
25 |
|
26 |
def parse_text(text):
|
27 |
lines = text.split("\n")
|
|
|
28 |
for i,line in enumerate(lines):
|
29 |
if "```" in line:
|
|
|
30 |
items = line.split('`')
|
31 |
-
if
|
32 |
lines[i] = f'<pre><code class="{items[-1]}">'
|
33 |
else:
|
34 |
lines[i] = f'</code></pre>'
|
35 |
else:
|
36 |
-
if i>0:
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
40 |
return "".join(lines)
|
41 |
|
42 |
def get_response(system, context, myKey, raw = False):
|
|
|
25 |
|
26 |
def parse_text(text):
|
27 |
lines = text.split("\n")
|
28 |
+
count = 0
|
29 |
for i,line in enumerate(lines):
|
30 |
if "```" in line:
|
31 |
+
count += 1
|
32 |
items = line.split('`')
|
33 |
+
if count % 2 == 1:
|
34 |
lines[i] = f'<pre><code class="{items[-1]}">'
|
35 |
else:
|
36 |
lines[i] = f'</code></pre>'
|
37 |
else:
|
38 |
+
if i > 0:
|
39 |
+
if count % 2 == 1:
|
40 |
+
line = line.replace("&", "&")
|
41 |
+
line = line.replace("\"", """)
|
42 |
+
line = line.replace("\'", "'")
|
43 |
+
line = line.replace("<", "<")
|
44 |
+
line = line.replace(">", ">")
|
45 |
+
line = line.replace(" ", " ")
|
46 |
+
lines[i] = '<br/>'+line
|
47 |
return "".join(lines)
|
48 |
|
49 |
def get_response(system, context, myKey, raw = False):
|