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
33
|
# from jinja2.utils import Markup, escape, pformat, urlize, soft_unicode, \
# unicode_urlencode
from jinja2.runtime import Undefined
#from jinja2.exceptions import FilterArgumentError
#from jinja2._compat import imap, string_types, text_type, iteritems
def environmentfilter(f):
"""Decorator for marking environment dependent filters. The current
:class:`Environment` is passed to the filter as first argument.
"""
f.environmentfilter = True
return f
@environmentfilter
def do_customwordwrap(environment, s, width=79, break_long_words=True,
wrapstring=None, break_on_hyphens=False):
"""
Return a copy of the string passed to the filter wrapped after
``79`` characters. You can override this default using the first
parameter. If you set the second parameter to `false` Jinja will not
split words apart if they are longer than `width`. By default, the newlines
will be the default newlines for the environment, but this can be changed
using the wrapstring keyword argument.
"""
if not wrapstring:
wrapstring = environment.newline_sequence
import textwrap
return wrapstring.join(textwrap.wrap(s, width=width, expand_tabs=False,
replace_whitespace=False,
break_long_words=break_long_words,
break_on_hyphens=break_on_hyphens))
|