Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Is this what {strip} is supposed to do?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
ldrut
Smarty Rookie


Joined: 22 Dec 2009
Posts: 11

PostPosted: Tue Dec 22, 2009 1:52 am    Post subject: Is this what {strip} is supposed to do? Reply with quote

My reading of the {strip} tag is that it is intended to remove extra whitespace, but it will in fact completely remove whitespace:

Code:
{strip}
  Sentence.
  Another sentence which is so long
  it wraps across lines.
{/strip}


Becomes:

Code:
Sentence.Another sentence which is so longit wraps across lines.


Similarly newlines between tags are replaced with nothing which slightly changes the layout (for instance adjacent images become closer together).

The offending line is #55 in smarty_internal_compile_strip.php (3.0b5) which is

$_output = "<?php echo preg_replace('![\t ]*[\r\n]+[\t ]*!', '', ob_get_clean()); ?>\n";

and IMHO should be (though could probably be made better):

$_output = "<?php echo preg_replace('![\t ]*[\r\n]+[\t ]*!', ' ', ob_get_clean()); ?>\n";

Or do I misunderstand the intent of the tag?
Back to top
View user's profile Send private message
sadness203
Smarty Rookie


Joined: 12 Nov 2009
Posts: 11

PostPosted: Tue Dec 22, 2009 3:32 am    Post subject: Reply with quote

Newline and tabulation are whitespace, extra whitespace actually, since they are not needed by the html interpreter to render a page. What you propose will defeat the purpose of the strip function, by changing these whitespace to normal space. (So not really removing content (a couple byte in the case of a \r\n but still))

Unless you want to use the 'pre' tag a lot, I don't see any reason to change the behavior of this. (Yet you can still change it yourself or write a pluging)
Back to top
View user's profile Send private message
ldrut
Smarty Rookie


Joined: 22 Dec 2009
Posts: 11

PostPosted: Tue Dec 22, 2009 7:37 am    Post subject: Reply with quote

Ahh, I missed part of the documentation saying that the tag was ONLY for use where whitespace was intentionally not wanted regardless of context. Ready, Post, Aim, RTFM...


I was looking for more symmetry between the {strip} tag and the strip variable modifier - odd that both are really quite different, both in the whitespace they will remove and in the replacement they effect. Having the same name they really should be more similar in function or be given different names. Its just asking for confusion.


In any case, newline and tabulation are not always 'extra whitespace' and frequently they are needed by the HTML interpreter to render a page (or more correctly it renders slightly differently without them). In those cases {strip} is not usable. Allowing something like {strip replace=' '} would make the strip tag usable where the whitespace is significant.

A quick check of some HTML code on some random websites shows 10-20% of the bytecount is often in extra leading blanks used to indent for readability and trailing blanks from editor artifacts. That is really what I am looking use it for. The modified tag would allow indentation to be used to clarify complicated <div> structures while keeping those bytes out of the compiled files and the HTTP transfer.
Back to top
View user's profile Send private message
sadness203
Smarty Rookie


Joined: 12 Nov 2009
Posts: 11

PostPosted: Tue Dec 22, 2009 2:12 pm    Post subject: Reply with quote

If you want to see the rendered html, use something like firebug (a Firefox addon) or webdevelopper (Another Firefox addon).

Even Chrome as the tool to render properly indented code, even if the page is one long line of html tags.

As I said, unless you want to use the 'pre' tags, I fail to see any use for this modification. Change a '\t' to ' ' will reduce the size a little, but '\t' to '' is even better.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3 All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP