- Resolved an issue where top-level output silencing after known extend
blocks could generate invalid code when blocks where contained in if
statements. (#651)
+- Made the `truncate.leeway` default configurable to improve compatibility
+ with older templates.
Version 2.9.3
-------------
If this is set to False then all strings are stored as unicode
internally.
+``truncate.leeway``:
+ Configures the leeway default for the `truncate` filter. Leeway as
+ introduced in 2.9 but to restore compatibility with older templates
+ it can be configured to `0` to get the old behavior back. The default
+ is `5`.
+
``urlize.rel``:
A string that defines the items for the `rel` attribute of generated
links with the `urlize` filter. These items are always added. The
'compiler.ascii_str': True,
'urlize.rel': 'noopener',
'urlize.target': None,
+ 'truncate.leeway': 5,
'json.dumps_function': None,
'json.dumps_kwargs': {'sort_keys': True},
}
return rv
-def do_truncate(s, length=255, killwords=False, end='...', leeway=5):
+@environmentfilter
+def do_truncate(env, s, length=255, killwords=False, end='...', leeway=None):
"""Return a truncated copy of the string. The length is specified
with the first parameter which defaults to ``255``. If the second
parameter is ``true`` the filter will cut the text at length. Otherwise
{{ "foo bar baz qux"|truncate(11, False, '...', 0) }}
-> "foo bar..."
+ The default leeway on newer Jinja2 versions is 5 and was 0 before but
+ can be reconfigured globally.
"""
+ if leeway is None:
+ leeway = env.policies['truncate.leeway']
assert length >= len(end), 'expected length >= %s, got %s' % (len(end), length)
assert leeway >= 0, 'expected leeway >= 0, got %s' % leeway
if len(s) <= length + leeway: