Skip to main content

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.

The project is also available on PyPI:

pip install django-pygments

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.6.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

django_pygments-0.6-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file django_pygments-0.6.tar.gz.

File metadata

  • Download URL: django_pygments-0.6.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for django_pygments-0.6.tar.gz
Algorithm Hash digest
SHA256 5f75b05828ee4a9df7ad9e8b05e5ada631e134451d1a74b66da3b30f53635402
MD5 cc2e567f71756ae91abcf8899b2131a8
BLAKE2b-256 e5f5f640c0c7956a76cd76472b42a3be00538921195609b1996e9bed1d6b7f02

See more details on using hashes here.

File details

Details for the file django_pygments-0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_pygments-0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0865c8c82d2f31137704b14fac3861d81d3878d908bf69d35b6a36229137f8c0
MD5 072caacb32977a0fd11d03be29cbeeb0
BLAKE2b-256 2410ad831e7208df3c1af12ac6328bfce5eed52ff494e1227a5e828b4469a9c1

See more details on using hashes here.

Supported by

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