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.

23 lines
962 B

  1. from django.core.management.base import BaseCommand
  2. from pygments import highlight, lexers
  3. from pygments.formatters import HtmlFormatter
  4. def _process(fin, fout, lexer):
  5. source = open("templates/front/snippets/" + fin).read()
  6. processed = highlight(source, lexer, HtmlFormatter())
  7. processed = processed.replace("PING_URL", "{{ ping_url }}")
  8. with open("templates/front/snippets/" + fout, "w") as out:
  9. out.write(processed)
  10. class Command(BaseCommand):
  11. help = 'Compiles snippets with pygmentize'
  12. def handle(self, *args, **options):
  13. _process("bash.txt", "bash.html", lexers.BashLexer())
  14. _process("browser.txt", "browser.html", lexers.JavascriptLexer())
  15. _process("crontab.txt", "crontab.html", lexers.BashLexer())
  16. _process("python.txt", "python.html", lexers.PythonLexer())
  17. _process("php.txt", "php.html", lexers.PhpLexer())
  18. _process("node.txt", "node.html", lexers.JavascriptLexer())