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 for "django_pygments.views.demo".

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 latter is rather useful for RSS feeds, because it inlines CSS styles by passing noclasses=True to pygments.formatters.HtmlFormatter) 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.

    E.g: to disable line numbering, use:

{% pygment linenos=False %}
    <pre lang="python">...</pre>
{% endpygment %}

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

Uploaded Source

Built Distribution

django_pygments-0.7-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for django_pygments-0.7.tar.gz
Algorithm Hash digest
SHA256 6c9a9866447b06b2e73352bc4bc85ccd7692e1b5f0fc1f0c289ecd3dc1b99c9e
MD5 49c397112f94ec9dacea8833c57e8b81
BLAKE2b-256 a7b33eef2faf91bd92fcfb344ce541c5350de9db41ba0cb566e53e4dd798bde8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_pygments-0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c9d22b621d0fa042bd351c47ab4c06e9417f384dc873e2f1f68a63ac9e7458f7
MD5 b4c5166bafecfb711c749b9f8b410a28
BLAKE2b-256 e0078be78fa78fc71fea00f42c30109bc93f00518c11975a259d292f91458d6f

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