git-svn-id: http://code.djangoproject.com/svn/django/trunk@1967 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e260037e16
commit
0eaee6f5d4
|
@ -249,6 +249,14 @@ class NowNode(Node):
|
||||||
df = DateFormat(datetime.now())
|
df = DateFormat(datetime.now())
|
||||||
return df.format(self.format_string)
|
return df.format(self.format_string)
|
||||||
|
|
||||||
|
class SpacelessNode(Node):
|
||||||
|
def __init__(self, nodelist):
|
||||||
|
self.nodelist = nodelist
|
||||||
|
|
||||||
|
def render(self, context):
|
||||||
|
from django.utils.html import strip_spaces_between_tags
|
||||||
|
return strip_spaces_between_tags(self.nodelist.render(context).strip())
|
||||||
|
|
||||||
class TemplateTagNode(Node):
|
class TemplateTagNode(Node):
|
||||||
mapping = {'openblock': BLOCK_TAG_START,
|
mapping = {'openblock': BLOCK_TAG_START,
|
||||||
'closeblock': BLOCK_TAG_END,
|
'closeblock': BLOCK_TAG_END,
|
||||||
|
@ -726,6 +734,12 @@ def regroup(parser, token):
|
||||||
return RegroupNode(target, expression, var_name)
|
return RegroupNode(target, expression, var_name)
|
||||||
regroup = register.tag(regroup)
|
regroup = register.tag(regroup)
|
||||||
|
|
||||||
|
def spaceless(parser, token):
|
||||||
|
nodelist = parser.parse(('endspaceless',))
|
||||||
|
parser.delete_first_token()
|
||||||
|
return SpacelessNode(nodelist)
|
||||||
|
spaceless = register.tag(spaceless)
|
||||||
|
|
||||||
#@register.tag
|
#@register.tag
|
||||||
def templatetag(parser, token):
|
def templatetag(parser, token):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -37,6 +37,10 @@ def strip_tags(value):
|
||||||
"Returns the given HTML with all tags stripped"
|
"Returns the given HTML with all tags stripped"
|
||||||
return re.sub(r'<[^>]*?>', '', value)
|
return re.sub(r'<[^>]*?>', '', value)
|
||||||
|
|
||||||
|
def strip_spaces_between_tags(value):
|
||||||
|
"Returns the given HTML with spaces between tags stripped"
|
||||||
|
return re.sub(r'>\s+<', '><', value)
|
||||||
|
|
||||||
def strip_entities(value):
|
def strip_entities(value):
|
||||||
"Returns the given HTML with all entities (&something;) stripped"
|
"Returns the given HTML with all entities (&something;) stripped"
|
||||||
return re.sub(r'&(?:\w+|#\d);', '', value)
|
return re.sub(r'&(?:\w+|#\d);', '', value)
|
||||||
|
|
|
@ -663,6 +663,34 @@ i.e.::
|
||||||
|
|
||||||
{% regroup people|dictsort:"gender" by gender as grouped %}
|
{% regroup people|dictsort:"gender" by gender as grouped %}
|
||||||
|
|
||||||
|
spaceless
|
||||||
|
~~~~~~~~~
|
||||||
|
|
||||||
|
**New in Django development version.**
|
||||||
|
|
||||||
|
Strips whitespace between HTML tags. 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 stripped -- not space between tags and text. In
|
||||||
|
this example, the space around ``Hello`` won't be stripped::
|
||||||
|
|
||||||
|
{% spaceless %}
|
||||||
|
<strong>
|
||||||
|
Hello
|
||||||
|
</strong>
|
||||||
|
{% spaceless %}
|
||||||
|
|
||||||
ssi
|
ssi
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
|
|
|
@ -298,6 +298,11 @@ TEMPLATE_TESTS = {
|
||||||
gentlemen.
|
gentlemen.
|
||||||
"""),
|
"""),
|
||||||
|
|
||||||
|
# {% spaceless %} tag
|
||||||
|
'spaceless01': ("{% spaceless %} <b> <i> text </i> </b> {% endspaceless %}", {}, "<b><i> text </i></b>"),
|
||||||
|
'spaceless02': ("{% spaceless %} <b> \n <i> text </i> \n </b> {% endspaceless %}", {}, "<b><i> text </i></b>"),
|
||||||
|
'spaceless03': ("{% spaceless %}<b><i>text</i></b>{% endspaceless %}", {}, "<b><i>text</i></b>"),
|
||||||
|
|
||||||
# simple translation of a string delimited by '
|
# simple translation of a string delimited by '
|
||||||
'i18n01': ("{% load i18n %}{% trans 'xxxyyyxxx' %}", {}, "xxxyyyxxx"),
|
'i18n01': ("{% load i18n %}{% trans 'xxxyyyxxx' %}", {}, "xxxyyyxxx"),
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue