generate.py 770 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python
  2. import os
  3. from pygments.styles import get_all_styles
  4. from pygments.formatters.html import HtmlFormatter
  5. PYGMENTS_PATH = './../static/pygments'
  6. def export():
  7. if not os.path.exists(PYGMENTS_PATH):
  8. os.makedirs(PYGMENTS_PATH)
  9. styles = list(get_all_styles())
  10. for style in styles:
  11. print('Generating CSS for %s' % style)
  12. opts = {
  13. 'style': style,
  14. 'noclasses': False,
  15. 'nobackground': False,
  16. }
  17. path = os.path.join(PYGMENTS_PATH, '%s.css' % style)
  18. formatter = HtmlFormatter(**opts)
  19. css_content = formatter.get_style_defs('.highlight')
  20. with open(path, 'w') as f:
  21. f.write(css_content)
  22. if __name__ == '__main__':
  23. export()