From: John McDonnell Date: Sun, 2 Oct 2011 07:17:57 +0000 (-0400) Subject: Allow choice of wrap string in wordwrap filter. X-Git-Tag: 2.7~67^2~1^2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=012d0170c4481f8441a6a330d9c9625c4f886190;p=thirdparty%2Fjinja.git Allow choice of wrap string in wordwrap filter. --- diff --git a/jinja2/filters.py b/jinja2/filters.py index 47f07684..39391296 100644 --- a/jinja2/filters.py +++ b/jinja2/filters.py @@ -470,15 +470,20 @@ def do_truncate(s, length=255, killwords=False, end='...'): return u' '.join(result) @environmentfilter -def do_wordwrap(environment, s, width=79, break_long_words=True): +def do_wordwrap(environment, s, width=79, break_long_words=True, + wrapstring=None): """ 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`. + 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 environment.newline_sequence.join(textwrap.wrap(s, width=width, expand_tabs=False, + return wrapstring.join(textwrap.wrap(s, width=width, expand_tabs=False, replace_whitespace=False, break_long_words=break_long_words))