Skip to content
/ plumage Public

Pygments syntax highlighting via Jinja2 on Pelican HTML articles

License

Notifications You must be signed in to change notification settings

mattoc/plumage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Pygments syntax highlighting via Jinja2 on Pelican HTML articles

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages