Pygments syntax highlighting via Jinja2 on Pelican HTML articles
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Colourful syntax for your Pelican.

Uhh, what?

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 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 %}

Known Issues

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 %}
{% 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.