mirror of https://gitlab.com/bashrc2/epicyon
Handle multi-line markdown quotes
parent
fc4e2fc702
commit
b07bc917f4
7
tests.py
7
tests.py
|
@ -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>'
|
||||
|
||||
|
|
|
@ -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'):
|
||||
|
|
Loading…
Reference in New Issue