Skip to content

Commit

Permalink
fix&feat: 修复原始消息中LaTeX被误渲染的问题; 原始消息改用等宽字体
Browse files Browse the repository at this point in the history
fix #955.
origin commit: 3dc27c7

ammended: 适配了之前的消息内容写法
  • Loading branch information
Keldos-Li committed Nov 18, 2023
1 parent a8d9818 commit 1150a69
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChuanhuChatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def create_new_model():
label="Chuanhu Chat",
elem_id="chuanhu-chatbot",
latex_delimiters=latex_delimiters_set,
sanitize_html=False,
# height=700,
show_label=False,
avatar_images=[config.user_avatar, config.bot_avatar],
Expand Down
2 changes: 1 addition & 1 deletion modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def convert_bot_before_marked(chat_message):
if '<div class="md-message">' in chat_message:
return chat_message
else:
raw = f'<div class="raw-message hideM"><pre>{clip_rawtext(chat_message)}</pre></div>'
raw = f'<div class="raw-message hideM"><pre class="fake-pre">{clip_rawtext(chat_message)}</pre></div>'
# really_raw = f'{START_OF_OUTPUT_MARK}<div class="really-raw hideM">{clip_rawtext(chat_message, need_escape=False)}\n</div>{END_OF_OUTPUT_MARK}'

code_block_pattern = re.compile(r"```(.*?)(?:```|$)", re.DOTALL)
Expand Down
6 changes: 5 additions & 1 deletion web_assets/javascript/message-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ function addChuanhuButton(botElement) {
function removeMarkdownText(message) {
var rawDiv = message.querySelector('.raw-message');
if (rawDiv) {
rawDiv.innerHTML = rawDiv.querySelector('pre')?.innerHTML || rawDiv.innerHTML;
// 判断pre是否存在fake-pre类,如果不存在,则为20231118之前的历史记录格式,需要转换,增加fake-pre类用于适配
if (!rawDiv.querySelector('pre')?.classList.contains('fake-pre')) {
rawDiv.innerHTML = rawDiv.innerHTML.replace(/<pre>/g, '<pre class="fake-pre">');
}
// rawDiv.innerHTML = rawDiv.querySelector('pre')?.innerHTML || rawDiv.innerHTML;
rawDiv.classList.remove('hideM');
}
var mdDiv = message.querySelector('.md-message');
Expand Down
8 changes: 8 additions & 0 deletions web_assets/stylesheet/chatbot.css
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ hr.append-display {
.message .raw-message p {
margin:0 !important;
}
.message .raw-message pre.fake-pre {
background: unset;
margin: unset;
font-size: unset;
/* font-family: unset; */
padding: unset;
white-space: inherit;
}
.message .raw-message {
display: block;
padding: 0 !important;
Expand Down

0 comments on commit 1150a69

Please sign in to comment.