forked from mitsuhiko/jinja2-htmlcompress
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
32 lines (19 loc) · 1.19 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- jinja2-htmlcompress
a Jinja2 extension that removes whitespace between HTML tags.
Example usage:
env = Environment(extensions=['jinja2htmlcompress.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. 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 selectively strip stuff?
You can use ``{% strip false %} ... {% endstrip %}`` blocks to temporarily disable
stripping for a block; and/or use ``{% strip true %} ... {% enstrip %}`` blocks to enable it
(the last can be shortened to ``{% strip %}...{% endstrip %}``).
By default, stripping is turned on globally. To disable it,
you can either use:
env = Environment(extensions=['jinja2htmlcompress.SelectiveHTMLCompress'])
or for jinja 2.9, you can keep using ``HTMLCompress``, and set the policy flag:
env.policies['htmlcompress.default_active'] = False