Chuan Hu commited on
Commit
9e5a8ac
·
unverified ·
1 Parent(s): d593331

修正某些情况下代码块显示异常问题,感谢@RMStonight

Browse files
Files changed (1) hide show
  1. 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 items[-1]:
32
  lines[i] = f'<pre><code class="{items[-1]}">'
33
  else:
34
  lines[i] = f'</code></pre>'
35
  else:
36
- if i>0:
37
- line = line.replace("<", "&lt;")
38
- line = line.replace(">", "&gt;")
39
- lines[i] = '<br/>'+line.replace(" ", "&nbsp;")
 
 
 
 
 
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("&", "&amp;")
41
+ line = line.replace("\"", "&quot;")
42
+ line = line.replace("\'", "&apos;")
43
+ line = line.replace("<", "&lt;")
44
+ line = line.replace(">", "&gt;")
45
+ line = line.replace(" ", "&nbsp;")
46
+ lines[i] = '<br/>'+line
47
  return "".join(lines)
48
 
49
  def get_response(system, context, myKey, raw = False):