#1067 closed enhancement (fixed)
"Spaceless" tag, removes spaces between html nodes
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Template system | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This is a cool tag that I think should be added to the defaults, it removes spaces between HTML tags. This is a problem many designers has banged their heads against many walls over, where spaces between tags show up even though they are clearly not inteded to be there.
So this:
{% spaceless %} <a href='#'> <img src='something.jpg' border='0'/> </a> <a href='#'> <img src='something-else.jpg' border='0'/> </a> {% endspaceless %}
Renders as:
<a href='#'><img src='something.jpg' border='0'/></a><a href='#'><img src='something-else.jpg' border='0'/></a>
import re re_spaceless = re.compile(">\s+<") def do_spaceless(parser, token): nodelist = parser.parse(('endspaceless',)) parser.delete_first_token() return SpacelessNode(nodelist) class SpacelessNode(template.Node): def __init__(self, nodelist): self.nodelist = nodelist def render(self, context): rendered = self.nodelist.render(context).strip() return re_spaceless.sub("><", rendered)
Change History (2)
comment:1 by , 19 years ago
comment:2 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
hehehe http://code.djangoproject.com/ticket/276
:)))