mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-29 10:59:32 +01:00
UI: improve HTML rendering for lists with sub-lists
This commit is contained in:
parent
5fa9336dab
commit
3d19746a5d
@ -404,7 +404,7 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* {
|
|||||||
.message-body h3,
|
.message-body h3,
|
||||||
.message-body h4 {
|
.message-body h4 {
|
||||||
color: var(--body-text-color);
|
color: var(--body-text-color);
|
||||||
margin: 20px 0 10px 0;
|
margin: 20px 0 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark .message q {
|
.dark .message q {
|
||||||
@ -456,6 +456,10 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* {
|
|||||||
overflow: scroll;
|
overflow: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.prose ul ul {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.message-body code {
|
.message-body code {
|
||||||
white-space: pre-wrap !important;
|
white-space: pre-wrap !important;
|
||||||
word-wrap: break-word !important;
|
word-wrap: break-word !important;
|
||||||
|
@ -104,6 +104,8 @@ def convert_to_markdown(string):
|
|||||||
result = ''
|
result = ''
|
||||||
is_code = False
|
is_code = False
|
||||||
is_latex = False
|
is_latex = False
|
||||||
|
previous_line_empty = True
|
||||||
|
|
||||||
for line in string.split('\n'):
|
for line in string.split('\n'):
|
||||||
stripped_line = line.strip()
|
stripped_line = line.strip()
|
||||||
|
|
||||||
@ -120,13 +122,20 @@ def convert_to_markdown(string):
|
|||||||
elif stripped_line.endswith('\\\\]'):
|
elif stripped_line.endswith('\\\\]'):
|
||||||
is_latex = False
|
is_latex = False
|
||||||
|
|
||||||
result += line
|
# Preserve indentation for lists and code blocks
|
||||||
|
if stripped_line.startswith('-') or stripped_line.startswith('*') or stripped_line.startswith('+') or stripped_line.startswith('>') or re.match(r'\d+\.', stripped_line):
|
||||||
# Don't add an extra \n for tables, code, or LaTeX
|
result += line + '\n'
|
||||||
if is_code or is_latex or line.startswith('|'):
|
previous_line_empty = False
|
||||||
result += '\n'
|
elif is_code or is_latex or line.startswith('|'):
|
||||||
|
result += line + '\n'
|
||||||
|
previous_line_empty = False
|
||||||
else:
|
else:
|
||||||
result += '\n\n'
|
if previous_line_empty:
|
||||||
|
result += line.strip() + '\n'
|
||||||
|
else:
|
||||||
|
result += line.strip() + '\n\n'
|
||||||
|
|
||||||
|
previous_line_empty = stripped_line == ''
|
||||||
|
|
||||||
result = result.strip()
|
result = result.strip()
|
||||||
if is_code:
|
if is_code:
|
||||||
@ -145,14 +154,15 @@ def convert_to_markdown(string):
|
|||||||
result = re.sub(list_item_pattern, r'\g<1> ' + delete_str, result)
|
result = re.sub(list_item_pattern, r'\g<1> ' + delete_str, result)
|
||||||
|
|
||||||
# Convert to HTML using markdown
|
# Convert to HTML using markdown
|
||||||
html_output = markdown.markdown(result, extensions=['fenced_code', 'tables'])
|
html_output = markdown.markdown(result, extensions=['fenced_code', 'tables'], tab_length=2)
|
||||||
|
|
||||||
# Remove the delete string from the HTML output
|
# Remove the delete string from the HTML output
|
||||||
pos = html_output.rfind(delete_str)
|
pos = html_output.rfind(delete_str)
|
||||||
if pos > -1:
|
if pos > -1:
|
||||||
html_output = html_output[:pos] + html_output[pos + len(delete_str):]
|
html_output = html_output[:pos] + html_output[pos + len(delete_str):]
|
||||||
else:
|
else:
|
||||||
html_output = markdown.markdown(result, extensions=['fenced_code', 'tables'])
|
# Convert to HTML using markdown
|
||||||
|
html_output = markdown.markdown(result, extensions=['fenced_code', 'tables'], tab_length=2)
|
||||||
|
|
||||||
# Unescape code blocks
|
# Unescape code blocks
|
||||||
pattern = re.compile(r'<code[^>]*>(.*?)</code>', re.DOTALL)
|
pattern = re.compile(r'<code[^>]*>(.*?)</code>', re.DOTALL)
|
||||||
|
Loading…
Reference in New Issue
Block a user