Skip to main content
jinja2-highlight
################

About
=====

A simple Jinja2 extension that uses Pygments to highlight code blocks.


.. image:: https://travis-ci.org/tlatsas/jinja2-highlight.svg?branch=master
:target: https://travis-ci.org/tlatsas/jinja2-highlight


Source
======

Github: https://github.com/tlatsas/jinja2-highlight

Pypi: http://pypi.python.org/pypi/jinja2-highlight


Requirements
============

* Jinja2 >= 2.4
* Pygments >= 1.5


Highlight examples
=================
::

{% highlight 'language' %}
your-awesome-code-here
{% endhighlight %}

Replace `language` with the appropriate Pygments lexer short name: http://pygments.org/docs/lexers/

Line numbering can be turned on using `lineno='inline'` or `lineno='table'` depending on the style of line numbering you want (as per Pygment's documentation: http://pygments.org/docs/formatters/#HtmlFormatter)

::

{% highlight 'language', lineno='inline' %}
your-awesome-code-here
{% endhighlight %}

This can also be used without a language setting

::

{% highlight lineno='table' %}
your-awesome-code-here
{% endhighlight %}

Optional settings
================

By default Pygments renders the code block inside a div with the class 'highlight', if you want to change the name you can set the environment variable `jinja2_highlight_cssclass` to the class name you would like.

In jinja this can be done after you've created your environment;
::

env = Environment(extensions=['jinja2_highlight.HighlightExtension'])
# Set the css class name to 'codehilite'
env.extend(jinja2_highlight_cssclass = 'codehilite')

In Flask this can be done with the following (after creating your app):
::

app.jinja_env.extend(jinja2_highlight_cssclass = 'codehilite')



Using with Flask
================

See the example at: https://github.com/tlatsas/jinja2-highlight/tree/master/examples/flask

Metadata

Release files for jinja2-highlight 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jinja2-highlight 0.6.1
File Size Uploaded
jinja2-highlight-0.6.1.tar.gz 3.4 kB Details

Release files / jinja2-highlight-0.6.1.tar.gz

Download URL jinja2-highlight-0.6.1.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
fad47890c12f1a270a45cd0783cad84cb8f9770071395df87be473ec6d611b09
BLAKE2b-256 checksum
How to use checksums
c42e98a1fc3c72fe8ed1be581797cf5d0178ec30b2617721d94eda367d964f58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.6.1 This release

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page