Replace commonmark.py with python-markdown
This commit is contained in:
parent
1818105d98
commit
393b73aacb
15
makesite.py
15
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')
|
||||||
import commonmark
|
if has_markdown:
|
||||||
text = commonmark.commonmark(text)
|
text = markdown.markdown(text, extensions=['codehilite', 'fenced_code'])
|
||||||
except ImportError as e:
|
else:
|
||||||
log('WARNING: Cannot render Markdown in {}: {}', filename, str(e))
|
log('WARNING: Cannot render Markdown in {}: python-markdown not available', filename)
|
||||||
|
|
||||||
# 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