Replace commonmark.py with python-markdown

This commit is contained in:
PapaTutuWawa 2021-04-10 09:50:13 +02:00
parent 1818105d98
commit 393b73aacb

View File

@ -36,6 +36,12 @@ import json
import datetime
import optparse
try:
import markdown
has_markdown = True
except ImportError as err:
print(f'Could not import markdown: {err}. Markdown cannot be rendered!')
has_markdown = False
def fread(filename):
"""Read file and close the file."""
@ -100,13 +106,12 @@ def read_content(filename):
# Convert Markdown content to HTML.
if filename.endswith(('.md', '.mkd', '.mkdn', '.mdown', '.markdown')):
try:
if _test == 'ImportError':
raise ImportError('Error forced by test')
import commonmark
text = commonmark.commonmark(text)
except ImportError as e:
log('WARNING: Cannot render Markdown in {}: {}', filename, str(e))
if _test == 'ImportError':
raise ImportError('Error forced by test')
if has_markdown:
text = markdown.markdown(text, extensions=['codehilite', 'fenced_code'])
else:
log('WARNING: Cannot render Markdown in {}: python-markdown not available', filename)
# Update the dictionary with content and RFC 2822 date.
content.update({