diff --git a/hyde/ext/templates/jinja.py b/hyde/ext/templates/jinja.py
index df1da83..22e5076 100644
--- a/hyde/ext/templates/jinja.py
+++ b/hyde/ext/templates/jinja.py
@@ -50,6 +50,7 @@ def markdown(env, value):
try:
import markdown
except ImportError:
+ logger.error(u"Cannot load the markdown library.")
raise TemplateError("Cannot load the markdown library")
output = value
d = {}
@@ -59,6 +60,34 @@ def markdown(env, value):
md = markdown.Markdown(**d)
return md.convert(output)
+
+@environmentfilter
+def syntax(env, value, lexer=None):
+ """
+ Processes the contained block using `pygments`
+ """
+
+ try:
+ import pygments
+ from pygments import lexers
+ self.lexers = lexers
+ from pygments import formatters
+ except ImportError:
+ logger.error(u"pygments library is required to use syntax highlighting tags.")
+ raise TemplateError("Cannot load pygments")
+
+ pyg = (self.lexers.get_lexer_by_name(lexer)
+ if lexer else
+ self.lexers.guess_lexer(value))
+ settings = {}
+ if hasattr(env.config, 'syntax'):
+ settings = getattr(env.config.syntax, 'options', {})
+
+ formatter = formatters.HtmlFormatter(**settings)
+ code = pygments.highlight(value, lexer, formatter)
+ code = code.replace('\n\n', '\n \n').replace('\n', '
')
+ return safestring.mark_safe('\n\n