优化isay 代码,考虑代码块内有```和有制表符的情况, 优化界面显示
This commit is contained in:
5
crazy_functions/KDOCS_轻文档分析.py
Normal file
5
crazy_functions/KDOCS_轻文档分析.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#! .\venv\
|
||||||
|
# encoding: utf-8
|
||||||
|
# @Time : 2023/6/15
|
||||||
|
# @Author : Spike
|
||||||
|
# @Descr :
|
||||||
5
crazy_functions/crazy_box.py
Normal file
5
crazy_functions/crazy_box.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#! .\venv\
|
||||||
|
# encoding: utf-8
|
||||||
|
# @Time : 2023/6/14
|
||||||
|
# @Author : Spike
|
||||||
|
# @Descr :
|
||||||
@ -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;
|
||||||
|
|||||||
3
theme.py
3
theme.py
@ -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;
|
||||||
|
|||||||
37
toolbox.py
37
toolbox.py
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user