Replace commonmark.py with python-markdown
This commit is contained in:
parent
1818105d98
commit
393b73aacb
19
makesite.py
19
makesite.py
@ -36,6 +36,12 @@ import json
|
|||||||
import datetime
|
import datetime
|
||||||
import optparse
|
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):
|
def fread(filename):
|
||||||
"""Read file and close the file."""
|
"""Read file and close the file."""
|
||||||
@ -100,13 +106,12 @@ def read_content(filename):
|
|||||||
|
|
||||||
# Convert Markdown content to HTML.
|
# Convert Markdown content to HTML.
|
||||||
if filename.endswith(('.md', '.mkd', '.mkdn', '.mdown', '.markdown')):
|
if filename.endswith(('.md', '.mkd', '.mkdn', '.mdown', '.markdown')):
|
||||||
try:
|
if _test == 'ImportError':
|
||||||
if _test == 'ImportError':
|
raise ImportError('Error forced by test')
|
||||||
raise ImportError('Error forced by test')
|
if has_markdown:
|
||||||
import commonmark
|
text = markdown.markdown(text, extensions=['codehilite', 'fenced_code'])
|
||||||
text = commonmark.commonmark(text)
|
else:
|
||||||
except ImportError as e:
|
log('WARNING: Cannot render Markdown in {}: python-markdown not available', filename)
|
||||||
log('WARNING: Cannot render Markdown in {}: {}', filename, str(e))
|
|
||||||
|
|
||||||
# Update the dictionary with content and RFC 2822 date.
|
# Update the dictionary with content and RFC 2822 date.
|
||||||
content.update({
|
content.update({
|
||||||
|
Loading…
Reference in New Issue
Block a user