comparison piecrust/templating/jinjaengine.py @ 293:d013cc191922

jinja: Add a global function to render Pygments' CSS styles.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 08 Mar 2015 22:58:28 -0700
parents 078e64dba77d
children b7ab1b503510
comparison
equal deleted inserted replaced
292:c8a6c92b1867 293:d013cc191922
131 # All good! Create the Environment. 131 # All good! Create the Environment.
132 super(PieCrustEnvironment, self).__init__(*args, **kwargs) 132 super(PieCrustEnvironment, self).__init__(*args, **kwargs)
133 133
134 # Now add globals and filters. 134 # Now add globals and filters.
135 self.globals.update({ 135 self.globals.update({
136 'fail': raise_exception}) 136 'fail': raise_exception,
137 'highlight_css': get_highlight_css})
137 138
138 self.filters.update({ 139 self.filters.update({
139 'keys': get_dict_keys, 140 'keys': get_dict_keys,
140 'values': get_dict_values, 141 'values': get_dict_values,
141 'paginate': self._paginate, 142 'paginate': self._paginate,
328 else: 329 else:
329 formatter = HtmlFormatter(linenos=line_numbers) 330 formatter = HtmlFormatter(linenos=line_numbers)
330 331
331 code = highlight(Markup(body.rstrip()).unescape(), lexer, formatter) 332 code = highlight(Markup(body.rstrip()).unescape(), lexer, formatter)
332 return code 333 return code
334
335
336 def get_highlight_css(class_name='.highlight'):
337 return HtmlFormatter().get_style_defs(class_name)
333 338
334 339
335 class PieCrustCacheExtension(Extension): 340 class PieCrustCacheExtension(Extension):
336 tags = set(['pccache', 'cache']) 341 tags = set(['pccache', 'cache'])
337 342