Prevent <ul> lists from flickering during streaming

This commit is contained in:
oobabooga 2023-08-28 20:45:07 -07:00
parent 8b56fc993a
commit 9a202f7fb2

View File

@ -66,14 +66,14 @@ def convert_to_markdown(string):
result = result.strip() result = result.strip()
# Unfinished list, like "\n1.". A |delete| string is added and then # Unfinished list, like "\n1.". A |delete| string is added and then
# removed to force a <ol> to be generated instead of a <p>. # removed to force a <ol> or <ul> to be generated instead of a <p>.
if re.search(r'(\d+\.?)$', result): if re.search(r'(\n\d+\.?|\n\*\s*)$', result):
delete_str = '|delete|' delete_str = '|delete|'
if not result.endswith('.'): if re.search(r'(\d+\.?)$', result) and not result.endswith('.'):
result += '.' result += '.'
result = re.sub(r'(\d+\.)$', r'\g<1> ' + delete_str, result) result = re.sub(r'(\n\d+\.?|\n\*\s*)$', r'\g<1> ' + delete_str, result)
html_output = markdown.markdown(result, extensions=['fenced_code', 'tables']) html_output = markdown.markdown(result, extensions=['fenced_code', 'tables'])
pos = html_output.rfind(delete_str) pos = html_output.rfind(delete_str)