优化代码! 真的最有一次优化isay的逻辑了!!!!
This commit is contained in:
13
toolbox.py
13
toolbox.py
@ -259,6 +259,7 @@ def report_execption(chatbot, history, a, b):
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def text_divide_paragraph(input_str):
|
||||
if input_str:
|
||||
# 提取所有的代码块
|
||||
@ -284,13 +285,13 @@ def text_divide_paragraph(input_str):
|
||||
else:
|
||||
# 对于没有反引号的字符串,针对四个空格之前的换行符进行处理
|
||||
lines = input_str.split('\n')
|
||||
if not any(line.startswith(' ') for line in lines):
|
||||
for idx, line in enumerate(lines[:-1]):
|
||||
if not line.strip():
|
||||
continue
|
||||
if not (lines[idx + 1].startswith(' ') or lines[idx + 1].startswith('\t')):
|
||||
lines[idx] += '\n' # 将一个换行符替换为两个换行符
|
||||
for idx, line in enumerate(lines[:-1]):
|
||||
if not line.strip():
|
||||
continue
|
||||
if not (lines[idx + 1].startswith(' ') or lines[idx + 1].startswith('\t')):
|
||||
lines[idx] += '\n' # 将一个换行符替换为两个换行符
|
||||
input_str = '\n'.join(lines)
|
||||
|
||||
return input_str
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user