magic-removal: Merged to [2012]

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2013 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-01-16 19:00:24 +00:00
parent d6bf53760b
commit b02bb933fd
1 changed files with 25 additions and 0 deletions

View File

@ -734,6 +734,31 @@ def regroup(parser, token):
regroup = register.tag(regroup) regroup = register.tag(regroup)
def spaceless(parser, token): def spaceless(parser, token):
"""
Normalize whitespace between HTML tags to a single space. This includes tab
characters and newlines.
Example usage::
{% spaceless %}
<p>
<a href="foo/">Foo</a>
</p>
{% spaceless %}
This example would return this HTML::
<p> <a href="foo/">Foo</a> </p>
Only space between *tags* is normalized -- not space between tags and text. In
this example, the space around ``Hello`` won't be stripped::
{% spaceless %}
<strong>
Hello
</strong>
{% spaceless %}
"""
nodelist = parser.parse(('endspaceless',)) nodelist = parser.parse(('endspaceless',))
parser.delete_first_token() parser.delete_first_token()
return SpacelessNode(nodelist) return SpacelessNode(nodelist)