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>' + \
|
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>'
|
||||||
|
|
||||||
|
|
|
@ -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'):
|
||||||
|
|
Loading…
Reference in New Issue