From 82d61335b02f7a12cc778f5f3302314275e451e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 14 Feb 2020 10:14:29 +0200 Subject: [PATCH] The "render_docs" command checks if markdown and pygments is installed. cc: #329 --- hc/front/management/commands/pygmentize.py | 2 +- hc/front/management/commands/render_docs.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hc/front/management/commands/pygmentize.py b/hc/front/management/commands/pygmentize.py index 4ae89f96..3d32a217 100644 --- a/hc/front/management/commands/pygmentize.py +++ b/hc/front/management/commands/pygmentize.py @@ -22,7 +22,7 @@ class Command(BaseCommand): try: from pygments import lexers except ImportError: - self.stdout.write("This command requires Pygments package.") + self.stdout.write("This command requires the Pygments package.") self.stdout.write("Please install it with:\n\n") self.stdout.write(" pip install Pygments\n\n") return diff --git a/hc/front/management/commands/render_docs.py b/hc/front/management/commands/render_docs.py index 3415da87..fe65de49 100644 --- a/hc/front/management/commands/render_docs.py +++ b/hc/front/management/commands/render_docs.py @@ -2,13 +2,23 @@ import os from django.conf import settings from django.core.management.base import BaseCommand -import markdown class Command(BaseCommand): help = "Renders Markdown to HTML" def handle(self, *args, **options): + try: + import markdown + + # We use pygments for highlighting code samples + import pygments + except ImportError as e: + self.stdout.write(f"This command requires the {e.name} package.") + self.stdout.write("Please install it with:\n\n") + self.stdout.write(f" pip install {e.name}\n\n") + return + extensions = ["fenced_code", "codehilite", "tables"] ec = {"codehilite": {"css_class": "highlight"}}