Keldos commited on
Commit
1150a69
·
1 Parent(s): a8d9818

fix&feat: 修复原始消息中LaTeX被误渲染的问题; 原始消息改用等宽字体

Browse files

fix #955.
origin commit: 3dc27c72e3bc0cbd2b1f4ea95a805f34f50eab07

ammended: 适配了之前的消息内容写法

ChuanhuChatbot.py CHANGED
@@ -135,6 +135,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
135
  label="Chuanhu Chat",
136
  elem_id="chuanhu-chatbot",
137
  latex_delimiters=latex_delimiters_set,
 
138
  # height=700,
139
  show_label=False,
140
  avatar_images=[config.user_avatar, config.bot_avatar],
 
135
  label="Chuanhu Chat",
136
  elem_id="chuanhu-chatbot",
137
  latex_delimiters=latex_delimiters_set,
138
+ sanitize_html=False,
139
  # height=700,
140
  show_label=False,
141
  avatar_images=[config.user_avatar, config.bot_avatar],
modules/utils.py CHANGED
@@ -233,7 +233,7 @@ def convert_bot_before_marked(chat_message):
233
  if '<div class="md-message">' in chat_message:
234
  return chat_message
235
  else:
236
- raw = f'<div class="raw-message hideM"><pre>{clip_rawtext(chat_message)}</pre></div>'
237
  # 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}'
238
 
239
  code_block_pattern = re.compile(r"```(.*?)(?:```|$)", re.DOTALL)
 
233
  if '<div class="md-message">' in chat_message:
234
  return chat_message
235
  else:
236
+ raw = f'<div class="raw-message hideM"><pre class="fake-pre">{clip_rawtext(chat_message)}</pre></div>'
237
  # 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}'
238
 
239
  code_block_pattern = re.compile(r"```(.*?)(?:```|$)", re.DOTALL)
web_assets/javascript/message-button.js CHANGED
@@ -95,7 +95,11 @@ function addChuanhuButton(botElement) {
95
  function removeMarkdownText(message) {
96
  var rawDiv = message.querySelector('.raw-message');
97
  if (rawDiv) {
98
- rawDiv.innerHTML = rawDiv.querySelector('pre')?.innerHTML || rawDiv.innerHTML;
 
 
 
 
99
  rawDiv.classList.remove('hideM');
100
  }
101
  var mdDiv = message.querySelector('.md-message');
 
95
  function removeMarkdownText(message) {
96
  var rawDiv = message.querySelector('.raw-message');
97
  if (rawDiv) {
98
+ // 判断pre是否存在fake-pre类,如果不存在,则为20231118之前的历史记录格式,需要转换,增加fake-pre类用于适配
99
+ if (!rawDiv.querySelector('pre')?.classList.contains('fake-pre')) {
100
+ rawDiv.innerHTML = rawDiv.innerHTML.replace(/<pre>/g, '<pre class="fake-pre">');
101
+ }
102
+ // rawDiv.innerHTML = rawDiv.querySelector('pre')?.innerHTML || rawDiv.innerHTML;
103
  rawDiv.classList.remove('hideM');
104
  }
105
  var mdDiv = message.querySelector('.md-message');
web_assets/stylesheet/chatbot.css CHANGED
@@ -216,6 +216,14 @@ hr.append-display {
216
  .message .raw-message p {
217
  margin:0 !important;
218
  }
 
 
 
 
 
 
 
 
219
  .message .raw-message {
220
  display: block;
221
  padding: 0 !important;
 
216
  .message .raw-message p {
217
  margin:0 !important;
218
  }
219
+ .message .raw-message pre.fake-pre {
220
+ background: unset;
221
+ margin: unset;
222
+ font-size: unset;
223
+ /* font-family: unset; */
224
+ padding: unset;
225
+ white-space: inherit;
226
+ }
227
  .message .raw-message {
228
  display: block;
229
  padding: 0 !important;