Newlines
| From: | Ferdinand Beyer | Date: | Tue, 18 Jun 2002 14:46:57 +0000 |
| Subject: | Newlines | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-4926@lists.php.net to get a copy of this message | ||
While playing with the newline-after-smarty-tags issue, I encountered
some problems.
{literal} tags also produce white space:
--------------------------------------------------
<pre>
{literal}
some code here
{/literal}
</pre>
--------------------------------------------------
produces
--------------------------------------------------
<pre>
some code here
</pre>
--------------------------------------------------
instead of
--------------------------------------------------
<pre>
some code here
</pre>
--------------------------------------------------
This should be fixed by removing new-line-characters after smarty
tags. But when removing newlines we have to make sure to count
them so that $_current_line_no saves the right number. In my patch
code, I simply replaced {...}\n with {...}{*\n*} so that the comment will be
removed but the newline still counted.
This causes problems with {literal} tags:
--------------------------------------------------
{literal}
{/literal}
--------------------------------------------------
would be replaced with
--------------------------------------------------
{literal}{*
*}{/literal}
--------------------------------------------------
Furthermore, smarty comments inside {literal} tags are not passed
through as they should be:
--------------------------------------------------
{literal}
A smarty comment starts with {* and ends with *}.
{/literal}
--------------------------------------------------
is compiled to:
--------------------------------------------------
A smarty comment starts with {**}
--------------------------------------------------
A solution would be to handle {literal}s before handling comments. New
line characters after {literal} have to be removed seperately from new
lines after other smarty tags:
- pull out literal's and preg_replace("/^\n/", "") in the content of
literal
blocks (if removing, add 1 to $_current_line_no)
- remove new lines after smarty tags by replacing {...}\n with {...}{*\n*}
- remove comments including the ones created in step 2 and count
new lines to $_current_line_no.
--
Ferdinand Beyer
<fbeyer@clickhand.de>