[ZPT] Why does this cause a page template to be invalid?(longish)

Casey Duncan casey@zope.com
Wed, 27 Mar 2002 09:32:46 -0700


R. David Murray wrote:
> On Tue, 19 Mar 2002, Geir Bholt wrote:
> 
>>- where it explicitly states that :
>>
>><q> The P element represents a paragraph. It cannot contain
>>block-level elements (including P itself). </q>
>>
>>thus , the parser is right , although is was not as obvious as i
>>first thought..
>>
> 
> Well, as far as I am concerned, this means that the browsers are
> correct and the spec is wrong.

It comes down to the fact that there are really three levels of tags:

block
paragraph
inline

block tags can contain anything. paragraph and inline tags can only 
contain other inlines.

This is to support this lazy idiom:

<p>This is an implicitly close paragraph
<h1>Being closed by a level 1 heading</h1>

So, the <h1> (which is paragraph level) is not inside the paragraph 
above, it is a new paragraph making this equiviliant to:

<p>This is an implicitly close paragraph</p>
<h1>Being closed by a level 1 heading</h1>

The ZPT parser understands this, so the "bad" example of:

<p><div></div></p>

gets internally transformed (correctly) to:

<p></p><div></div></p>

Which is of course invalid HTML. Now this also means that the following 
rather odd looking code:

<p><div></div><p></p>

Actually works.

Now the other example:

<span><div></div><span>

Does not get transformed at all since there are no implicit closing 
rules for <span>. Therefore the ZPT parser goes along merrily with your 
ill-advised nesting.

The point is that the ZPT parser does not enforce the nesting rules of 
HTML when it comes to block vs. inline. But paragraph tags get 
transformed, so they're nesting is significant by side affect.

If we want ZPT to enforce the standard for nesting then this needs to be 
added. I personally think that's a bit out of scope for ZPT, but I could 
envision a "strict mode" which enforced these things. If we enforce them 
all the time, then I think we may find that certain "broken" authoring 
tools do not work with ZPT anymore. Plus it would break any existing 
templates with bad nesting.

So, I would suggest that if someone feels strongly enough about this 
"strict behavior", then a fishbowl proposal needs to be drafted to add 
this into ZPT. The current "enforcement" is only a side-affect of 
closing lazy <p> tags.

-Casey