Colourful syntax for your Pelican.
This is a Jinja2 extension to allow you to render a Pygments
fragment against an .html
-formatted Pelican article. Typically
only rST
files implement the Pygments Directive.
Requires the html_jinja2 Pelican plugin.
Add this module to your pelicanconf.py
settings:
JINJA_EXTENSIONS = ['plumage.plumage.CodeHighlight',]
Adds support for a new Jinja2 tag
With language arg (passed to Pygment's lexer lookup):
{% syntax 'python' %} import this {% endsyntax %}
Or without for plain, but preformatted text:
{% syntax %} >> $('body').find('a'); ... {% endsyntax %}
If you use Typogrify you'll need to disable it as it rewrites single quotes in the tag to HTML entities.
A workaround or fix is currently #TODO.
If you have a code snippet in an article that uses Jinja2 or Django
template syntax you'll need to encapsulate it with the {% raw %}
block tag, lest it also parse (or break on) your sample code:
{% syntax 'html' %} {% raw %}{% block content %} <h2>Test</h2> {% endblock content %}{% endraw %} {% endsyntax %}
As this work conveys modified source from Pelican itself, it is licensed under the same terms; The GNU Affero General Public License, v3.