Keldos commited on
Commit
bf090a3
1 Parent(s): 0f2f299

fix: 修改parse_text,删去列表中可能的空行

Browse files
Files changed (1) hide show
  1. utils.py +13 -0
utils.py CHANGED
@@ -8,6 +8,7 @@ import datetime
8
  import hashlib
9
  import csv
10
  import requests
 
11
 
12
  import gradio as gr
13
  from pypinyin import lazy_pinyin
@@ -40,13 +41,25 @@ def count_token(message):
40
 
41
  def parse_text(text):
42
  in_code_block = False
 
43
  new_lines = []
44
  for line in text.split("\n"):
45
  if line.strip().startswith("```"):
46
  in_code_block = not in_code_block
 
 
 
 
 
 
 
 
47
  if in_code_block:
48
  if line.strip() != "":
49
  new_lines.append(line)
 
 
 
50
  else:
51
  new_lines.append(line)
52
  if in_code_block:
 
8
  import hashlib
9
  import csv
10
  import requests
11
+ import re
12
 
13
  import gradio as gr
14
  from pypinyin import lazy_pinyin
 
41
 
42
  def parse_text(text):
43
  in_code_block = False
44
+ in_list = False
45
  new_lines = []
46
  for line in text.split("\n"):
47
  if line.strip().startswith("```"):
48
  in_code_block = not in_code_block
49
+ else:
50
+ if re.match(r'(\*|-|\d+\.)\s', line):
51
+ if not in_list:
52
+ in_list = True
53
+ elif in_list and line.strip() != "":
54
+ in_list = False
55
+ new_lines.append("")
56
+
57
  if in_code_block:
58
  if line.strip() != "":
59
  new_lines.append(line)
60
+ elif in_list:
61
+ if line.strip() != "":
62
+ new_lines.append(line)
63
  else:
64
  new_lines.append(line)
65
  if in_code_block: