From 5342f729684ae6e8647eb0a952c8fce7d7041f3e Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sun, 16 Apr 2023 18:00:12 -0300 Subject: [PATCH] Properly handle blockquote blocks --- modules/html_generator.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/html_generator.py b/modules/html_generator.py index 860efbfc..ca4f11ff 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -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'])