Socket
Socket
Sign inDemoInstall

jinja2-highlight

Package Overview
Dependencies
0
Maintainers
1
Alerts
File Explorer

Install Socket

Protect your apps from supply chain attacks

Install

jinja2-highlight

Jinja2 extension to highlight source code using Pygments

    0.6.1

Maintainers
1

Readme

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

Keywords

FAQs


Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc