mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-22 08:07:56 +01:00
Properly handle blockquote blocks
This commit is contained in:
parent
27f3a78834
commit
5342f72968
@ -33,15 +33,20 @@ def fix_newlines(string):
|
||||
string = string.strip()
|
||||
return string
|
||||
|
||||
# This could probably be generalized and improved
|
||||
|
||||
def replace_blockquote(m):
|
||||
return m.group().replace('\n', '\n> ').replace('\\begin{blockquote}', '').replace('\\end{blockquote}', '')
|
||||
|
||||
def convert_to_markdown(string):
|
||||
|
||||
# Blockquote
|
||||
pattern = re.compile(r'\\begin{blockquote}(.*?)\\end{blockquote}', re.DOTALL)
|
||||
string = pattern.sub(replace_blockquote, string)
|
||||
|
||||
# Code
|
||||
string = string.replace('\\begin{code}', '```')
|
||||
string = string.replace('\\end{code}', '```')
|
||||
string = string.replace('\\begin{blockquote}', '> ')
|
||||
string = string.replace('\\end{blockquote}', '')
|
||||
string = re.sub(r"(.)```", r"\1\n```", string)
|
||||
|
||||
string = fix_newlines(string)
|
||||
return markdown.markdown(string, extensions=['fenced_code'])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user