Re: comments trump newline?

"Jonathan Revusky" <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
On Wed, Jun 25, 2008 at 4:17 PM, Zemian Deng <[email protected]> wrote:
> Okay, I did more experiments, and I got even more confused. :(
>
> Example1 template:
> ONE
> <#-- c1 -->
> <#nt>
> <#-- c2 -->
> THREE
>
> Example1 output:
> ONE
> THREE

Hmm, that's probably a bug, even though it kind of makes sense if you
get into a very complex mental model of what the whitespace stripping
does. I mean, it has to do with the fact that the whitespace trimming
algorithm is actually stripping the whitespace at two levels. It
ignores the whitespace between comments, or between macros, or, for
example, between a command and a macro, that's WS trimming at the
block or element level, let's say, and there is WS trimming at the
line by line level. The <#nt> doesn't work as expected above, because
even if you say not to strip the whitespace at the line by line level,
it is still stripping it at the block level. Of course, that's a
description of why it is that way, I'm not saying it's the right
thing.

>
> Example2 template:
> ONE
> <#-- c1 -->
> X<#-- c2  -->
> <#-- c3 -->
> THREE
>
> Example2 output:
> ONE
> XTHREE

Well, that is working as it is described as working, which is that it
is getting rid of the whitespace between the comments c2 and c3, which
includes the newline. So, in principle, if you wanted the newline to
appear, you would have to write:

<#--c2 -->X
<#-- c3 -->

and then what is between the two comments is not whitespace.

As Daniel, said, it is probably true that stripping the whitespace
between two comments is not the best behavior. I guess I was thinking
of the whitespace between two macros and between a comment and a
macro, which should almost always be stripped, and I generalized that
to the whitespace between any two non-outputting elements, and that
included between two comments.

Maybe we'll change this for 2.4. As a practical matter, I don't think
this is causing people a lot of problems out there. Of course, most
people are outputting HTML anyway, so it doesn't affect them in most
cases. Of course another way of looking at it is that there is little
reason to write consecutive comments anyway, since you could just
write:

<# -- c2
        c3 -->

so you could conceptualize it that the consecutive comments are
getting fused into one comment and the intervening whtiespace is part
of that fused comment...

>
> So <#nt> has no effect? and what happens in Example2?

Well, I guess the rule about ignoring whitespace between two
non-outputting elements, in particular between two comments, has some
anti-intuitive results in these cases.

JR

>
> Thanks,
> -Z
>
> On Wed, Jun 25, 2008 at 8:41 AM, Zemian Deng <[email protected]> wrote:
>> +1 with Daniel.
>>
>> Hello Jonathan,
>> Yes I can use <#ftl strip_whitespace=false>, but that affect the
>> entire template, and I only have problem for that single new line
>> space.
>>
>> I have to say this expected behavior is a bit confusing. If you say
>> "Whitespace between non-outputting elements (comments among them) is
>> stripped. ", then to me, it's white-space that are enclosed will be
>> striped, but  a  well defined separated two non-outputting elements.
>>
>> For example if I have these
>> <#if cond>
>>
>> </#if>
>>
>> or even this
>> <#-- c1
>>
>> -->
>>
>> Then the whitespace is stripped is WHAT I expected, but this
>> <#-- c1 -->
>>
>> <#-- c2 -->
>>
>> Shouldn't strip my whitespace in between.
>>
>> This is just my feedback as user.
>>
>> -Z
>>
>> On Wed, Jun 25, 2008 at 5:16 AM, Daniel Dekany <[email protected]> wrote:
>>> Wednesday, June 25, 2008, 10:14:24 AM, Jonathan Revusky wrote:
>>>
>>>> This is the expected behavior, unless your template begins with something like
>>>> <#ftl strip_whitespace=false>
>>>>
>>>> Whitespace between non-outputting elements (comments among them) is
>>>> stripped.
>>>
>>> I hope you don't keep this behavior with comments in 2.4. A comment
>>> should not influence the output in any way, except that the whitespace
>>> in its own line should be removed if the comment is the only thing in
>>> that line (beside whitespace).
>>>
>>>> Also, the whitespace on a line that contains only non-outputting
>>>> elements is ignored.
>>>
>>> Except that for user-defined FTL tags you don't know which is
>>> outputting, so it's not entirely true.
>>>
>>>> JR
>>>>
>>>> On Wed, Jun 25, 2008 at 6:39 AM, Zemian Deng <[email protected]> wrote:
>>>>> Hi list,
>>>>>
>>>>> I have this template:
>>>>>
>>>>> ONE
>>>>> <#-- comment here -->
>>>>> TWO
>>>>> <#-- -->
>>>>> THREE
>>>>> =====
>>>>> ONE
>>>>> <#-- comment here -->
>>>>>
>>>>> <#-- -->
>>>>> THREE
>>>>>
>>>>> And I get this output:
>>>>> ONE
>>>>> TWO
>>>>> THREE
>>>>> =====
>>>>> ONE
>>>>> THREE
>>>>>
>>>>> Should I be getting a empty line above the second THREE? I tried with
>>>>> multiple empty lines between comments, and they all get stripped out.
>>>>> Is this expected?
>>>>>
>>>>> Thanks,
>>>>> -Z
>>>>>
>>>>> -------------------------------------------------------------------------
>>>>> Check out the new SourceForge.net Marketplace.
>>>>> It's the best place to buy or sell services for
>>>>> just about anything Open Source.
>>>>> http://sourceforge.net/services/buy/index.php
>>>>> _______________________________________________
>>>>> FreeMarker-user mailing list
>>>>> [email protected]
>>>>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>>>>
>>>>
>>>> -------------------------------------------------------------------------
>>>> Check out the new SourceForge.net Marketplace.
>>>> It's the best place to buy or sell services for
>>>> just about anything Open Source.
>>>> http://sourceforge.net/services/buy/index.php
>>>> _______________________________________________
>>>> FreeMarker-user mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>>
>>> --
>>> Best regards,
>>>  Daniel Dekany
>>>
>>>
>>> -------------------------------------------------------------------------
>>> Check out the new SourceForge.net Marketplace.
>>> It's the best place to buy or sell services for
>>> just about anything Open Source.
>>> http://sourceforge.net/services/buy/index.php
>>> _______________________________________________
>>> FreeMarker-user mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>>
>>
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.