From 393b73aacb75c541475ba169ca843abf70665d65 Mon Sep 17 00:00:00 2001 From: Alexander PapaTutuWawa Date: Sat, 10 Apr 2021 09:50:13 +0200 Subject: [PATCH] Replace commonmark.py with python-markdown --- makesite.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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({