Skip to main content

Jinja2 extension that removes whitespace between HTML tags

Project description

Jinja2 extension that removes whitespace between HTML tags.

Example usage:

env = Environment(extensions=['j2hc.compressors.HTMLCompress'])

or for the coffin users:

JINJA2_EXTENSIONS = [
    'j2hc.compressors.HTMLCompress'
]

How does it work? It throws away all whitespace between HTML tags it can find at runtime. It will however preserve pre, textarea, style and script tags because this kinda makes sense. There is one exception for script tags, that contain an angularjs template:

<script type="test/ng-template" ....

In order to force whitespace you can use {{ " " }}.

Unlike filters that work at template runtime, this remotes whitespace at compile time and does not add an overhead in template execution.

What if you only want to selective strip stuff?:

env = Environment(extensions=['j2hc.compressors.SelectiveHTMLCompress'])

And then mark blocks with:

{% strip %} ... {% endstrip %}

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

j2hc-0.1.tar.gz (3.1 kB view details)

Uploaded Source

File details

Details for the file j2hc-0.1.tar.gz.

File metadata

  • Download URL: j2hc-0.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for j2hc-0.1.tar.gz
Algorithm Hash digest
SHA256 3ffb5e6c6163b3f29956e31e71afd6046335b5c0102f087d58c5bd59dec79ee2
MD5 91587732e28b81d62822d5abe3e0ebce
BLAKE2b-256 996c95f53cad5401d6d04578960778b0ddc02b24bb4a02334e884085b3e77a72

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