Mercurial > piecrust2
comparison piecrust/processing/pygments_style.py @ 507:ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
| author | Ludovic Chabant <ludovic@chabant.com> |
|---|---|
| date | Sat, 25 Jul 2015 22:00:27 -0700 |
| parents | |
| children | 727110ea112a |
comparison
equal
deleted
inserted
replaced
| 506:6ca1b6fb9964 | 507:ee3fe63cc51d |
|---|---|
| 1 import yaml | |
| 2 from pygments.formatters import HtmlFormatter | |
| 3 from piecrust.processing.base import SimpleFileProcessor | |
| 4 | |
| 5 | |
| 6 class PygmentsStyleProcessor(SimpleFileProcessor): | |
| 7 PROCESSOR_NAME = 'pygments_style' | |
| 8 | |
| 9 def __init__(self): | |
| 10 super(PygmentsStyleProcessor, self).__init__({'pygstyle': 'css'}) | |
| 11 | |
| 12 def _doProcess(self, in_path, out_path): | |
| 13 with open(in_path, 'r') as fp: | |
| 14 config = yaml.load(fp) | |
| 15 | |
| 16 style_name = config.get('style', 'default') | |
| 17 class_name = config.get('class', '.highlight') | |
| 18 fmt = HtmlFormatter(style=style_name).get_style_defs(class_name) | |
| 19 | |
| 20 with open(out_path, 'w') as fp: | |
| 21 fp.write(fmt) | |
| 22 | |
| 23 return True | |
| 24 |
