From b07bc917f4ebbaae900a80490df36a0c60f0a6a2 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 26 Feb 2021 23:13:33 +0000 Subject: [PATCH] Handle multi-line markdown quotes --- tests.py | 7 +++++++ webapp_utils.py | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tests.py b/tests.py index db321f23c..e4dace257 100644 --- a/tests.py +++ b/tests.py @@ -3293,6 +3293,13 @@ def testMarkdownToHtml(): assert markdownToHtml(markdown) == 'This is a quotation:
' + \ '
Some quote or other
' + markdown = 'This is a multi-line quotation:\n' + \ + '> The first line\n' + \ + '> The second line' + assert markdownToHtml(markdown) == \ + 'This is a multi-line quotation:
' + \ + '
The first line The second line
' + markdown = 'This is **bold**' assert markdownToHtml(markdown) == 'This is bold' diff --git a/webapp_utils.py b/webapp_utils.py index 29c965100..7a3fe6b1d 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -73,16 +73,26 @@ def _markdownReplaceQuotes(markdown: str) -> str: return markdown lines = markdown.split('\n') result = '' + prevQuoteLine = None for line in lines: if '> ' not in line: result += line + '\n' + prevQuoteLine = None continue lineStr = line.strip() if not lineStr.startswith('> '): result += line + '\n' + prevQuoteLine = None continue lineStr = lineStr.replace('> ', '', 1).strip() - result += '
' + lineStr + '
\n' + if prevQuoteLine: + newPrevLine = prevQuoteLine.replace('\n', '') + result = result.replace(prevQuoteLine, newPrevLine) + ' ' + lineStr += '\n' + else: + lineStr = '
' + lineStr + '
\n' + result += lineStr + prevQuoteLine = lineStr if result.endswith('\n') and \ not markdown.endswith('\n'):