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.

25 lines
1.0 KiB

  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("powershell.txt", "powershell.html",
  19. lexers.shell.PowerShellLexer())
  20. _process("node.txt", "node.html", lexers.JavascriptLexer())