mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-25 17:29:22 +01: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 = 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'])
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user