优化isay 代码,考虑代码块内有```和有制表符的情况, 优化界面显示

This commit is contained in:
w_xiaolizu
2023-06-15 12:48:09 +08:00
parent c8c4d37616
commit d4befe6964
5 changed files with 45 additions and 10 deletions

View File

@ -0,0 +1,5 @@
#! .\venv\
# encoding: utf-8
# @Time : 2023/6/15
# @Author : Spike
# @Descr :

View File

@ -0,0 +1,5 @@
#! .\venv\
# encoding: utf-8
# @Time : 2023/6/14
# @Author : Spike
# @Descr :

View File

@ -8,6 +8,7 @@
--message-bot-background-color-light: #FFFFFF; --message-bot-background-color-light: #FFFFFF;
--message-bot-background-color-dark: #2C2C2C; --message-bot-background-color-dark: #2C2C2C;
} }
#debug_mes { #debug_mes {
position: absolute; position: absolute;
bottom: 0; bottom: 0;
@ -136,6 +137,10 @@ footer {
transition: height 0.3s ease; transition: height 0.3s ease;
} }
span.svelte-1gfkn6j {
background: unset !important;
}
.wrap.svelte-18telvq.svelte-18telvq { .wrap.svelte-18telvq.svelte-18telvq {
padding: var(--block-padding) !important; padding: var(--block-padding) !important;
height: 100% !important; height: 100% !important;

View File

@ -135,6 +135,9 @@ def adjust_theme():
return set_theme return set_theme
with open("docs/assets/custom.css", "r", encoding="utf-8") as f:
customCSS = f.read()
custom_css = customCSS
advanced_css = """ advanced_css = """
#debug_mes { #debug_mes {
position: absolute; position: absolute;

View File

@ -259,19 +259,36 @@ def report_execption(chatbot, history, a, b):
def text_divide_paragraph(input_str): def text_divide_paragraph(input_str):
"""
将文本按照段落分隔符分割开生成带有段落标签的HTML代码。
"""
if input_str: if input_str:
code_blocks = re.findall('```.*?```', input_str, re.DOTALL) # 提取所有的代码块
for block in code_blocks: code_blocks = re.findall(r'```[\s\S]*?```', input_str)
input_str = input_str.replace(block, f'{{{{{{{{{{{code_blocks.index(block)}}}}}}}}}}}')
# 将除了三个反引号之间的文本块以外的 "\n" 替换为 "\n\n"
input_str = re.sub(r'(?!```)(?<!\n)\n(?!(\n|^)( {0,3}[\*\+\-]|[0-9]+\.))', '\n\n', input_str) # 将提取到的代码块用占位符替换
# 还原未处理的文本块
for i, block in enumerate(code_blocks): for i, block in enumerate(code_blocks):
input_str = input_str.replace(f'{{{{{{{{{{{i}}}}}}}}}}}', block) input_str = input_str.replace(block, f'{{{{CODE_BLOCK_{i}}}}}')
# 判断输入文本是否有反引号
if code_blocks:
# 将非代码块部分的单个换行符替换为双换行符,并处理四个空格的行
sections = re.split(r'({{{{\w+}}}})', input_str)
for idx, section in enumerate(sections):
if 'CODE_BLOCK' in section or section.startswith(' '):
continue
sections[idx] = re.sub(r'(?!```)(?<!\n)\n(?!(\n|^)( {0,3}[\*\+\-]|[0-9]+\.))', '\n\n', section)
input_str = ''.join(sections)
# 将占位符替换回原代码块
for i, block in enumerate(code_blocks):
input_str = input_str.replace(f'{{{{CODE_BLOCK_{i}}}}}', block.replace('\n', '\n'))
else:
# 对于没有反引号的字符串,针对四个空格之前的换行符进行处理
lines = input_str.split('\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')):
pass
input_str = '\n'.join(lines)
return input_str return input_str