diff --git a/makesite.py b/makesite.py index 47cfbec..581d62a 100644 --- a/makesite.py +++ b/makesite.py @@ -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({