Mercurial > piecrust2
annotate piecrust/processing/pygments_style.py @ 989:8adc27285d93
bake: Big pass on bake performance.
- Reduce the amount of data passed between processes.
- Make inter-process data simple objects to make it easier to test with
alternatives to pickle.
- Make sources have the basic requirement to be able to find a content item
from an item spec (path).
- Make Hoedown the default Markdown formatter.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 19 Nov 2017 14:29:17 -0800 |
parents | ee3fe63cc51d |
children | 727110ea112a |
rev | line source |
---|---|
507
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import yaml |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 from pygments.formatters import HtmlFormatter |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 from piecrust.processing.base import SimpleFileProcessor |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 class PygmentsStyleProcessor(SimpleFileProcessor): |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 PROCESSOR_NAME = 'pygments_style' |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 def __init__(self): |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 super(PygmentsStyleProcessor, self).__init__({'pygstyle': 'css'}) |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 def _doProcess(self, in_path, out_path): |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 with open(in_path, 'r') as fp: |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 config = yaml.load(fp) |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 style_name = config.get('style', 'default') |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 class_name = config.get('class', '.highlight') |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 fmt = HtmlFormatter(style=style_name).get_style_defs(class_name) |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 with open(out_path, 'w') as fp: |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 fp.write(fmt) |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 return True |
ee3fe63cc51d
bake: Add a processor to generate a Pygments style CSS file.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 |