From b1187fc9a569946bb6292b4c22769ea81bf1ffcd Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 25 Jun 2024 19:19:45 -0700 Subject: [PATCH] UI: prevent flickering while streaming lists / bullet points --- modules/html_generator.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/html_generator.py b/modules/html_generator.py index 7e50f561..3966f2a1 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -85,15 +85,20 @@ def convert_to_markdown(string): # Unfinished list, like "\n1.". A |delete| string is added and then # removed to force a
. - if re.search(r'(\n\d+\.?|\n\*\s*)$', result): + list_item_pattern = r'(\n\d+\.?|\n\*\s*|\n\s*[-*+]\s*)$' + if re.search(list_item_pattern, result): delete_str = '|delete|' if re.search(r'(\d+\.?)$', result) and not result.endswith('.'): result += '.' - result = re.sub(r'(\n\d+\.?|\n\*\s*)$', r'\g<1> ' + delete_str, result) + # Add the delete string after the list item + result = re.sub(list_item_pattern, r'\g<1> ' + delete_str, result) + # Convert to HTML using markdown html_output = markdown.markdown(result, extensions=['fenced_code', 'tables']) + + # Remove the delete string from the HTML output pos = html_output.rfind(delete_str) if pos > -1: html_output = html_output[:pos] + html_output[pos + len(delete_str):]