You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
922 B

  1. import os
  2. from django.conf import settings
  3. from django.core.management.base import BaseCommand
  4. import markdown
  5. class Command(BaseCommand):
  6. help = "Renders Markdown to HTML"
  7. def handle(self, *args, **options):
  8. extensions = ["fenced_code", "codehilite", "tables"]
  9. ec = {"codehilite": {"css_class": "highlight"}}
  10. docs_path = os.path.join(settings.BASE_DIR, "templates/docs")
  11. for doc in os.listdir(docs_path):
  12. if not doc.endswith(".md"):
  13. continue
  14. print("Rendering %s" % doc)
  15. src_path = os.path.join(docs_path, doc)
  16. dst_path = os.path.join(docs_path, doc[:-3] + ".html")
  17. text = open(src_path, "r", encoding="utf-8").read()
  18. html = markdown.markdown(text, extensions=extensions, extension_configs=ec)
  19. with open(dst_path, "w", encoding="utf-8") as f:
  20. f.write(html)