mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-10-01 01:26:03 -04:00
Better handle new line characters in code blocks
This commit is contained in:
parent
207a031e8d
commit
c728f2b5f0
@ -49,7 +49,22 @@ def convert_to_markdown(string):
|
|||||||
string = string.replace('\\end{code}', '```')
|
string = string.replace('\\end{code}', '```')
|
||||||
string = re.sub(r"(.)```", r"\1\n```", string)
|
string = re.sub(r"(.)```", r"\1\n```", string)
|
||||||
|
|
||||||
string = fix_newlines(string)
|
result = ''
|
||||||
|
is_code = False
|
||||||
|
for line in string.split('\n'):
|
||||||
|
if line.lstrip(' ').startswith('```'):
|
||||||
|
is_code = not is_code
|
||||||
|
|
||||||
|
result += line
|
||||||
|
if is_code:
|
||||||
|
result += '\n'
|
||||||
|
else:
|
||||||
|
result += '\n\n'
|
||||||
|
|
||||||
|
if is_code:
|
||||||
|
result = result + '```' # Unfinished code block
|
||||||
|
|
||||||
|
string = result.strip()
|
||||||
return markdown.markdown(string, extensions=['fenced_code'])
|
return markdown.markdown(string, extensions=['fenced_code'])
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user