]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Allow choice of wrap string in wordwrap filter. 206/head
authorJohn McDonnell <john.v.mcdonnell@gmail.com>
Sun, 2 Oct 2011 07:17:57 +0000 (03:17 -0400)
committerJohn McDonnell <john.v.mcdonnell@gmail.com>
Wed, 8 May 2013 02:08:42 +0000 (22:08 -0400)
jinja2/filters.py

index 47f07684cdb7baa53cbcb7ad22a9cd73c36f799f..393912961779d29b015b01269f5c1a4770a50113 100644 (file)
@@ -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))