]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
add break_on_hyphens parameter to wordwrap filter 829/head
authorAlessandro -oggei- Ogier <alessandro.ogier@gmail.com>
Fri, 23 Mar 2018 16:58:15 +0000 (17:58 +0100)
committerDavid Lord <davidism@gmail.com>
Fri, 1 Nov 2019 15:35:01 +0000 (08:35 -0700)
CHANGES.rst
jinja2/filters.py

index 22c1567248657612d887e7c2f2daf3c1bb31f4ab..f05603f58de89364a6de992cafe00b26cc7d56bf 100644 (file)
@@ -65,6 +65,8 @@ Unreleased
 -   ``|wordwrap`` filter treats existing newlines as separate paragraphs
     to be wrapped individually, rather than creating short intermediate
     lines. :issue:`175`
+-   Add ``break_on_hyphens`` parameter to ``|wordwrap`` filter.
+    :issue:`550`
 
 
 Version 2.10.3
index 7c546493bfdb1886f15a935fe08187fda1552131..666df408f8b76902ee3055eec94a069dae8b04bd 100644 (file)
@@ -684,7 +684,14 @@ def do_truncate(env, s, length=255, killwords=False, end='...', leeway=None):
 
 
 @environmentfilter
-def do_wordwrap(environment, s, width=79, break_long_words=True, wrapstring=None):
+def do_wordwrap(
+    environment,
+    s,
+    width=79,
+    break_long_words=True,
+    wrapstring=None,
+    break_on_hyphens=True,
+):
     """Wrap a string to the given width. Existing newlines are treated
     as paragraphs to be wrapped separately.
 
@@ -692,15 +699,21 @@ def do_wordwrap(environment, s, width=79, break_long_words=True, wrapstring=None
     :param width: Maximum length of wrapped lines.
     :param break_long_words: If a word is longer than ``width``, break
         it across lines.
+    :param break_on_hyphens: If a word contains hyphens, it may be split
+        across lines.
     :param wrapstring: String to join each wrapped line. Defaults to
         :attr:`Environment.newline_sequence`.
 
     .. versionchanged:: 2.11
         Existing newlines are treated as paragraphs wrapped separately.
 
+    .. versionchanged:: 2.11
+        Added the ``break_on_hyphens`` parameter.
+
     .. versionchanged:: 2.7
         Added the ``wrapstring`` parameter.
     """
+
     import textwrap
 
     if not wrapstring:
@@ -719,6 +732,7 @@ def do_wordwrap(environment, s, width=79, break_long_words=True, wrapstring=None
                     expand_tabs=False,
                     replace_whitespace=False,
                     break_long_words=break_long_words,
+                    break_on_hyphens=break_on_hyphens,
                 )
             )
             for line in s.splitlines()