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>' + \ assert markdownToHtml(markdown) == 'This is a quotation:<br>' + \
'<blockquote><i>Some quote or other</i></blockquote>' '<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**' markdown = 'This is **bold**'
assert markdownToHtml(markdown) == 'This is <b>bold</b>' assert markdownToHtml(markdown) == 'This is <b>bold</b>'

View File

@ -73,16 +73,26 @@ def _markdownReplaceQuotes(markdown: str) -> str:
return markdown return markdown
lines = markdown.split('\n') lines = markdown.split('\n')
result = '' result = ''
prevQuoteLine = None
for line in lines: for line in lines:
if '> ' not in line: if '> ' not in line:
result += line + '\n' result += line + '\n'
prevQuoteLine = None
continue continue
lineStr = line.strip() lineStr = line.strip()
if not lineStr.startswith('> '): if not lineStr.startswith('> '):
result += line + '\n' result += line + '\n'
prevQuoteLine = None
continue continue
lineStr = lineStr.replace('> ', '', 1).strip() 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 \ if result.endswith('\n') and \
not markdown.endswith('\n'): not markdown.endswith('\n'):