Pygments syntax highlighting via Jinja2 on Pelican HTML articles
Python
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
LICENSE
README.rst
__init__.py
plumage.py
setup.py

README.rst

Plumage

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.

Installation

Requires the html_jinja2 Pelican plugin.

Add this module to your pelicanconf.py settings:

JINJA_EXTENSIONS = ['plumage.plumage.CodeHighlight',]

Usage

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.

Gotchas

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

License

As this work conveys modified source from Pelican itself, it is licensed under the same terms; The GNU Affero General Public License, v3.