diff --git a/django/core/template/defaulttags.py b/django/core/template/defaulttags.py index daad1c2dfa9ab..f9197dec92c0c 100644 --- a/django/core/template/defaulttags.py +++ b/django/core/template/defaulttags.py @@ -735,6 +735,31 @@ def regroup(parser, token): regroup = register.tag(regroup) def spaceless(parser, token): + """ + Normalize whitespace between HTML tags to a single space. This includes tab + characters and newlines. + + Example usage:: + + {% spaceless %} +

+ Foo +

+ {% spaceless %} + + This example would return this HTML:: + +

Foo

+ + Only space between *tags* is normalized -- not space between tags and text. In + this example, the space around ``Hello`` won't be stripped:: + + {% spaceless %} + + Hello + + {% spaceless %} + """ nodelist = parser.parse(('endspaceless',)) parser.delete_first_token() return SpacelessNode(nodelist)