diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 52bbe8fea2..6a37c163e9 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -852,7 +852,7 @@ regroup = register.tag(regroup) def spaceless(parser, token): """ - Normalize whitespace between HTML tags to a single space. This includes tab + Removes whitespace between HTML tags. This includes tab characters and newlines. Example usage:: @@ -865,7 +865,7 @@ def spaceless(parser, token): This example would return this HTML:: -
+ Only space between *tags* is normalized -- not space between tags and text. In this example, the space around ``Hello`` won't be stripped:: diff --git a/django/utils/html.py b/django/utils/html.py index a0d1e82dcf..baa2fb06fc 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -39,8 +39,8 @@ def strip_tags(value): return re.sub(r'<[^>]*?>', '', value) def strip_spaces_between_tags(value): - "Returns the given HTML with spaces between tags normalized to a single space" - return re.sub(r'>\s+<', '> <', value) + "Returns the given HTML with spaces between tags removed" + return re.sub(r'>\s+<', '><', value) def strip_entities(value): "Returns the given HTML with all entities (&something;) stripped" diff --git a/docs/templates.txt b/docs/templates.txt index 8ab383c461..d93ee49ac1 100644 --- a/docs/templates.txt +++ b/docs/templates.txt @@ -757,7 +757,7 @@ i.e.:: spaceless ~~~~~~~~~ -Normalizes whitespace between HTML tags to a single space. This includes tab +Removes whitespace between HTML tags. This includes tab characters and newlines. Example usage:: @@ -770,9 +770,9 @@ Example usage:: This example would return this HTML:: - + -Only space between *tags* is normalized -- not space between tags and text. In +Only space between *tags* is removed -- not space between tags and text. In this example, the space around ``Hello`` won't be stripped:: {% spaceless %} diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index a77b1dcb7a..e60e778d0b 100644 --- a/tests/regressiontests/templates/tests.py +++ b/tests/regressiontests/templates/tests.py @@ -522,8 +522,8 @@ class Templates(unittest.TestCase): ### I18N ################################################################## # {% spaceless %} tag - 'spaceless01': ("{% spaceless %} text {% endspaceless %}", {}, " text "), - 'spaceless02': ("{% spaceless %} \n text \n {% endspaceless %}", {}, " text "), + 'spaceless01': ("{% spaceless %} text {% endspaceless %}", {}, " text "), + 'spaceless02': ("{% spaceless %} \n text \n {% endspaceless %}", {}, " text "), 'spaceless03': ("{% spaceless %}text{% endspaceless %}", {}, "text"), # simple translation of a string delimited by '