mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-21 23:57:58 +01:00
UI: prevent flickering while streaming lists / bullet points
This commit is contained in:
parent
3691451d00
commit
b1187fc9a5
@ -85,15 +85,20 @@ def convert_to_markdown(string):
|
||||
|
||||
# Unfinished list, like "\n1.". A |delete| string is added and then
|
||||
# removed to force a <ol> or <ul> to be generated instead of a <p>.
|
||||
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):]
|
||||
|
Loading…
Reference in New Issue
Block a user