Handle multi-line markdown quotes

merge-requests/21/head
Bob Mottram 2021-02-26 23:13:33 +00:00
parent fc4e2fc702
commit b07bc917f4
2 changed files with 18 additions and 1 deletions

View File

@ -3293,6 +3293,13 @@ def testMarkdownToHtml():
assert markdownToHtml(markdown) == 'This is a quotation:<br>' + \
'<blockquote><i>Some quote or other</i></blockquote>'
markdown = 'This is a multi-line quotation:\n' + \
'> The first line\n' + \
'> The second line'
assert markdownToHtml(markdown) == \
'This is a multi-line quotation:<br>' + \
'<blockquote><i>The first line The second line</i></blockquote>'
markdown = 'This is **bold**'
assert markdownToHtml(markdown) == 'This is <b>bold</b>'

View File

@ -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 += '<blockquote><i>' + lineStr + '</i></blockquote>\n'
if prevQuoteLine:
newPrevLine = prevQuoteLine.replace('</i></blockquote>\n', '')
result = result.replace(prevQuoteLine, newPrevLine) + ' '
lineStr += '</i></blockquote>\n'
else:
lineStr = '<blockquote><i>' + lineStr + '</i></blockquote>\n'
result += lineStr
prevQuoteLine = lineStr
if result.endswith('\n') and \
not markdown.endswith('\n'):