plainblack.com
Username Password
search
Bookmark and Share
View All Tickets
Use packed template removes wanted whitespace  (#11458)
Issue

The "Use packed template" option is overzealous. It cleans up all whitespace around HTML::Template syntax. For example, if you put this in a template:

<tmpl_if displayTitle>
Foo
</tmpl_if>
Bar

You would expect the result to be "Foo Bar", since that is what you would get from the not-packed template. But when the template is packed, the result is "FooBar", without any whitespace.

This means that packing a template may cause changes for the user. I assume that that's a bug.

If I understand correctly, in this case the \n</tmpl_if>\n is simply removed. But it should be replaced by a single space. This should be fixed for all statements: tmpl_if, tmpl_unless, tmpl_loop, both start and end tags. And for the tmpl_var too.

Found in 7.7.32, confirmed in 7.8.13.

Thanks,

Rogier

Solution Summary
Comments
perlDreamer
0
3/8/2010 10:53 am
This is definitely a bug.  HTML::Packer will pack HTML and do exactly what you want, it translates most newlines into spaces around HTML tags.

However, HTML::Template code is not real HTML, and HTML::Packer is smart enough to see the difference, so it treats newlines around template syntax differently; it deletes them.

Fortunately, newline removal is an option we can pass to HTML::Packer.
preaction
0
3/8/2010 1:28 pm
HTML::Packer isn't smart enough, it's treating the tag as a block element.

The rules for HTML whitespace: Whitespace between block-level elements is completely ignored. Whitespace inside tags (like <li      class="somethign"          >) is truncated to a single space. Whitespace between inline-level elements is truncated to a single space.

So, if <tmpl_if> is a block element, whitespace gets completely ignored.

If there's a way to get HTML::Packer to treat tmpl_* as inline, that would be ideal.
perlDreamer
0
3/8/2010 1:31 pm
Fixed in 7.9.0 (d0884af)
Fixed in 7.8.15 (1e4fb86)
perlDreamer
0
3/8/2010 1:42 pm
when remove_newlines is set to be true, there are a list of tags that it walks through to handle newlines in the space preserving way.  We would need to alter that list for HTML::Template, HTML::Template::Expr, and maybe some other engines.

For now, I've turned off the removal of newlines.  HTML::Packer will still helpfully condense multiple ones down into just 1 newline so the compression is altered all that much.
rogier
0
3/15/2010 11:13 am
If HTML::Packer works like Doug says, that's very odd. It can't be certain that a block element is actually displayed as a block. With CSS you can make any element an inline element. So I guess it should *never* remove all whitespace. I think this is a bug in HTML::Packer?

All of this FYI if you ever try to find a solution that is not just "for now".
perlDreamer
0
3/15/2010 1:07 pm
In HTML::Packer, when remove_newlines is false, it  only compresses multiple newlines in a row down to one, which is exactly what you suggest (never remove all whitespace).

HTML::Packer is fairly blunt, and only checks the HTML that it is sent.  It would have to fetch, merge and parse CSS in order to do truly accurate whitespace handling.  I don't see it doing that.
perlDreamer
0
4/5/2010 8:40 pm
The best solution is to leave in the newlines, compressed or not.
rogier
0
4/7/2010 3:13 am
OK, thanks for fixing
Details
Ticket Status Closed  
Rating0.0 
Submitted Byrogier 
Date Submitted2010-03-08 
Assigned To unassigned  
Date Assigned2012-02-11 
Assigned By 
Severity Minor (annoying, but not harmful)  
What's the bug in? WebGUI Stable  
WebGUI / WRE Version 7.7.32  
URLuse/bugs/tracker/11458
Keywords
Ticket History
4/7/2010
3:13 AM
Closed rogier
4/5/2010
8:40 PM
Resolved perlDreamer
3/15/2010
11:13 AM
Pending rogier
3/8/2010
1:42 PM
Resolved perlDreamer
3/8/2010
1:42 PM
Pending perlDreamer
3/8/2010
1:32 PM
Resolved perlDreamer
3/8/2010
8:51 AM
Ticket created rogier
© 2012 Plain Black Corporation | All Rights Reserved