Skip to main content

A django app that provides a template tag and 2 filters for doing syntax highlighting with Pygments

Project description

description

django-pygments is a Django app that provides a template tag and two filters for doing syntax highlighting with Pygments.

dependencies

installation

  • add django_pygments to your project directory and to INSTALLED_APPS in your settings.py
  • if you want to see the integrated demo page, add a urls.py entry and copy/link the media files in the proper dir

usage

  • enclose your code snippet in a pre tag with the non-standard "lang" attribute set to a supported language like this:
<pre lang="python">....</pre>
  • see the view and demo template for examples on how to use the "pygmentify" and "pygmentify_inline" filters (the later is rather useful for RSS feeds) or the "pygment" tag
  • While using the "pygment" template tag, you can pass keyword arguments that you would pass to Pygments HtmlFormatter class constructor by passing them as with keyword arguments along with the pygment tag. Look at demo template for examples. There is one caveat with this feature still. You can only pass Python values as argument values (like Strings wrapped within quotes or True or False boolean values, etc.). It doesn't support Django template/context variables as arguments yet.

notes

  • the custom HTML formatter class displays each line as an ordered list element, thus implementing line numbering without interfering with copy/pasting
  • to see a list of supported languages, look at the "lexer_names" variable in utils.py

license

3-clause BSD

credits

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-pygments-0.4.tar.gz (7.6 kB view details)

Uploaded Source

File details

Details for the file django-pygments-0.4.tar.gz.

File metadata

  • Download URL: django-pygments-0.4.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.5.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.6.9

File hashes

Hashes for django-pygments-0.4.tar.gz
Algorithm Hash digest
SHA256 0210b517e19f3fd12856610fc3f6cf87dac359b211fa3009ff3ef78f2e2e61b8
MD5 b77cf5359767525b6e66f1d925897fda
BLAKE2b-256 4ee843ee5494234f6cc37cc5bb88b7245afa41d42e6aeb69a63c1967998b2d38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page