Tuchuanhuhuhu commited on
Commit
ad19a5d
·
1 Parent(s): b8b193d

为代码块加入黑色背景

Browse files
Files changed (1) hide show
  1. ChuanhuChatbot.py +9 -3
ChuanhuChatbot.py CHANGED
@@ -40,12 +40,14 @@ def parse_text(text):
40
  lines = text.split("\n")
41
  lines = [line for line in lines if line != ""]
42
  count = 0
 
43
  for i, line in enumerate(lines):
44
  if "```" in line:
45
  count += 1
46
  items = line.split('`')
47
  if count % 2 == 1:
48
- lines[i] = f'<pre><code class="{items[-1]}">'
 
49
  else:
50
  lines[i] = f'</code></pre>'
51
  else:
@@ -59,8 +61,12 @@ def parse_text(text):
59
  line = line.replace("<", "&lt;")
60
  line = line.replace(">", "&gt;")
61
  line = line.replace(" ", "&nbsp;")
62
- lines[i] = '<br>'+line
63
- return "".join(lines).replace("<br>\n", "<br>")
 
 
 
 
64
  # text = "</br>".join([ i for i in "".join(lines).split("<br/>") if i != ""])
65
 
66
  def predict(inputs, top_p, temperature, openai_api_key, chatbot=[], history=[], system_prompt=initial_prompt, retry=False, summary=False): # repetition_penalty, top_k
 
40
  lines = text.split("\n")
41
  lines = [line for line in lines if line != ""]
42
  count = 0
43
+ firstline = False
44
  for i, line in enumerate(lines):
45
  if "```" in line:
46
  count += 1
47
  items = line.split('`')
48
  if count % 2 == 1:
49
+ lines[i] = f'<pre><code class="{items[-1]}" style="display: block; white-space: pre; padding: 0 1em 1em 1em; color: #fff; background: #000;">'
50
+ firstline = True
51
  else:
52
  lines[i] = f'</code></pre>'
53
  else:
 
61
  line = line.replace("<", "&lt;")
62
  line = line.replace(">", "&gt;")
63
  line = line.replace(" ", "&nbsp;")
64
+ if firstline:
65
+ lines[i] = line
66
+ firstline = False
67
+ else:
68
+ lines[i] = '<br>'+line
69
+ return "".join(lines)
70
  # text = "</br>".join([ i for i in "".join(lines).split("<br/>") if i != ""])
71
 
72
  def predict(inputs, top_p, temperature, openai_api_key, chatbot=[], history=[], system_prompt=initial_prompt, retry=False, summary=False): # repetition_penalty, top_k