Support quotes in markdown

merge-requests/21/head
Bob Mottram 2021-02-26 23:00:06 +00:00
parent 8f3bd705ad
commit fc4e2fc702
3 changed files with 32 additions and 1 deletions

View File

@ -5797,7 +5797,7 @@ class PubServer(BaseHTTPRequestHandler):
# if there is no theme-specific help image then use the default one
if not os.path.isfile(mediaFilename):
mediaFilename = \
baseDir + '/theme/default/helpimages/' + iconFilename
baseDir + '/theme/default/helpimages/' + iconFilename
if self._etag_exists(mediaFilename):
# The file has not changed
self._304()

View File

@ -3288,6 +3288,11 @@ def testMarkdownToHtml():
markdown = 'This is just plain text'
assert markdownToHtml(markdown) == markdown
markdown = 'This is a quotation:\n' + \
'> Some quote or other'
assert markdownToHtml(markdown) == 'This is a quotation:<br>' + \
'<blockquote><i>Some quote or other</i></blockquote>'
markdown = 'This is **bold**'
assert markdownToHtml(markdown) == 'This is <b>bold</b>'

View File

@ -66,8 +66,33 @@ def _markdownEmphasisHtml(markdown: str) -> str:
return markdown
def _markdownReplaceQuotes(markdown: str) -> str:
"""Replaces > quotes with html blockquote
"""
if '> ' not in markdown:
return markdown
lines = markdown.split('\n')
result = ''
for line in lines:
if '> ' not in line:
result += line + '\n'
continue
lineStr = line.strip()
if not lineStr.startswith('> '):
result += line + '\n'
continue
lineStr = lineStr.replace('> ', '', 1).strip()
result += '<blockquote><i>' + lineStr + '</i></blockquote>\n'
if result.endswith('\n') and \
not markdown.endswith('\n'):
result = result[:len(result) -1]
return result
def _markdownReplaceLinks(markdown: str, images=False) -> str:
"""Replaces markdown links with html
Optionally replace image links
"""
replaceLinks = {}
text = markdown
@ -106,6 +131,7 @@ def _markdownReplaceLinks(markdown: str, images=False) -> str:
def markdownToHtml(markdown: str) -> str:
"""Converts markdown formatted text to html
"""
markdown = _markdownReplaceQuotes(markdown)
markdown = _markdownEmphasisHtml(markdown)
markdown = _markdownReplaceLinks(markdown, True)
markdown = _markdownReplaceLinks(markdown)