diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 2d8cdd6d26..363147289a 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -734,6 +734,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)