This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 18613 - [Templates]: Section 7 Parsing HTML Templates needs to be re-written
Summary: [Templates]: Section 7 Parsing HTML Templates needs to be re-written
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Tony Ross [MSFT]
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 15476
  Show dependency treegraph
 
Reported: 2012-08-17 22:55 UTC by Rafael Weinstein
Modified: 2012-09-07 04:41 UTC (History)
3 users (show)

See Also:


Attachments

Description Rafael Weinstein 2012-08-17 22:55:41 UTC
To be reflect the prior consensus (on public-webapps) about implied context parsing.

The basic idea is this:

While parsing children of the template element, act as if IN_HEAD, but append any produced nodes to the template element's content. When the first "determining" start tag is encountered, set the context element based on the indentity of that tag, reset the insertion mode appropriately and continue.

Non-determining start tags must include: template, style, script, link.
Comment 1 Tony Ross [MSFT] 2012-08-17 23:54:40 UTC
We'll also need an explicit clause for non-whitespace text (else we'll end up implying a closing HEAD tag). Basically this clause will add non-whitespace text to the DOM without exiting implied context parsing (so we'll keep searching for a "determining" start tag afterward).
Comment 2 Tony Ross [MSFT] 2012-08-24 18:12:46 UTC
http://dvcs.w3.org/hg/webcomponents/rev/557c7e693458
Comment 3 Rafael Weinstein 2012-08-28 23:45:46 UTC
I implemented the current spec text (including "clear the stack back to XXX", and I have some questions:

Here are html5lib test cases that illustrate the issues:

// Does naked template go into <head> or <body> -- as is, it goes into <head>
#data
<template>Hello</template>
#errors
#document
| <html>
|   <head>
|   <body>
|     <template>
|       "Hello"

// Can template exist as a child of <html> -- as is, it gets put into <head>
#data
<html><template><div>
#errors
#document
| <html>
|   <template>
|     <div>

// Can template exist as a child of <colgroup> -- as is, no
#data
<table><colgroup><template>Hello
#errors
#document
| <html>
|   <head>
|   <body>
|     <table>
|       <colgroup>
|         <template>
|           "Hello"

// Can template exist as a child of <frameset> -- as is, no
#data
<frameset><template><frame>
#errors
#document
| <html>
|   <head>
|   <body>
|     <frameset>
|       <template>
|         <frame>

// Reset insertion mode picks InBody for </head>, which is wrong for this case. -- as is, this actually hits a series of assertions, and I'm pretty sure it's wrong.
#data
<head><template><div></div></template></head>
#errors
#document
| <html>
|   <head>
|     <template>
|       <div>

// Should "in cell" be modified to "close the cell" on </template> (e.g. with </table>, </tbody>, </tfoot>, </thead>, </tr>) -- as is, </tr> wil lbe ignored and <div> appended to <td>
#data
<body><template><td></tr><div></template>
#errors
#document
| <html>
|   <head>
|   <body>
|     <template>
|       <td>
|       <div>
Comment 4 Rafael Weinstein 2012-08-29 22:29:25 UTC
Also, just to make sure this is what we want:

#data
<body><template><tr><div></div></tr></template>
#errors
#document
| <html>
|   <head>
|   <body>
|     <template>
|       <tr>
|       <div>

Note that the div is foster parented *after* the <tr>, not before.
Comment 5 Rafael Weinstein 2012-08-29 22:31:48 UTC
Likewise this one:

#data
<body><template><div><tr></tr></div></template>
#errors
#document
| <html>
|   <head>
|   <body>
|     <template>
|       <div>

(throws away the <tr> -- which I think makes sense).
Comment 6 Rafael Weinstein 2012-08-30 17:59:29 UTC
Decisions:

On Thu, Aug 30, 2012 at 10:52 AM, Rafael Weinstein <rafaelw@google.com> wrote:
> // Does naked template go into <head> or <body> -- as is, it goes into <head>
> #data
> <template>Hello</template>
> #errors
> #document
> | <html>
> |   <head>
> |   <body>
> |     <template>
> |       "Hello"

This is correct (analog is <script>)

>
> // Can template exist as a child of <html> -- as is, it gets put into <head>
> #data
> <html><template><div>
> #errors
> #document
> | <html>
> |   <template>
> |     <div>
>

This is correct (analog is <script>)

> // Can template exist as a child of <colgroup> -- as is, no
> #data
> <table><colgroup><template>Hello
> #errors
> #document
> | <html>
> |   <head>
> |   <body>
> |     <table>
> |       <colgroup>
> |         <template>
> |           "Hello"

We need parser edits for this. Relevant test which should pass is

// Can template exist as a child of <colgroup> -- as is, no
#data
<table><colgroup><template><col>
#errors
#document
| <html>
|   <head>
|   <body>
|     <table>
|       <colgroup>
|         <template>
|           <col>

>
> // Can template exist as a child of <frameset> -- as is, no
> #data
> <frameset><template><frame>
> #errors
> #document
> | <html>
> |   <head>
> |   <body>
> |     <frameset>
> |       <template>
> |         <frame>

We need parser edits for this. Relevant test which should pass is

#data
<frameset><template><frame>
#errors
#document
| <html>
|   <head>
|   <frameset>
|     <template>
|       <frame>

>
> // Reset insertion mode picks InBody for </head>, which is wrong for this case.
> -- as is, this actually hits a series of assertions, and I'm pretty sure it's
> wrong.
> #data
> <head><template><div></div></template></head>
> #errors
> #document
> | <html>
> |   <head>
> |     <template>
> |       <div>

Step 11 of reset insertion mode appropriately should be:

If node is a head element and node is the context element, then switch the insertion mode to "in body" ("in body"! not "in head"!) and abort these steps. (fragment case)
otherwise, switch the insertion mode to "in head" and abort these steps.

>
> // Should "in cell" be modified to "close the cell" on </template> (e.g. with
> </table>, </tbody>, </tfoot>, </thead>, </tr>) -- as is, </tr> wil lbe ignored
> and <div> appended to <td>
> #data
> <body><template><td></tr><div></template>
> #errors
> #document
> | <html>
> |   <head>
> |   <body>
> |     <template>
> |       <td>
> |       <div>

This is correct, but we need spec text that http://dev.w3.org/html5/spec/parsing.html#has-an-element-in-table-scope includes <template>

>
> Also, just to make sure this is what we want:
>
> #data
> <body><template><tr><div></div></tr></template>
> #errors
> #document
> | <html>
> |   <head>
> |   <body>
> |     <template>
> |       <tr>
> |       <div>
>
> Note that the div is foster parented *after* the <tr>, not before.

Correct behavior.

>
> Likewise this one:
>
> #data
> <body><template><div><tr></tr></div></template>
> #errors
> #document
> | <html>
> |   <head>
> |   <body>
> |     <template>
> |       <div>
>
> (throws away the <tr> -- which I think makes sense).

Correct behavior.
Comment 7 Tony Ross [MSFT] 2012-09-04 21:42:01 UTC
http://dvcs.w3.org/hg/webcomponents/rev/6b0813f30f10
Comment 8 Rafael Weinstein 2012-09-06 21:42:42 UTC
For the colgroup case to work (e.g.:

#data
<table><colgroup><template><col>
#errors
#document
| <html>
|   <head>
|   <body>
|     <table>
|       <colgroup>
|         <template>
|           <col>

), template contents mode needs to set the insertion mode to in column group when a col tag is encountered.
Comment 9 Rafael Weinstein 2012-09-06 22:26:23 UTC
For the frameset case to work, template contents mode needs to set the insertion mode to in frameset
when a frame tag is encountered.
Comment 10 Rafael Weinstein 2012-09-06 22:50:52 UTC
The in head edit to reset insertion mode should read:

Modify the step which begins "If node is a head element..." to be:

If node is a head element and node is the context element, then switch the insertion mode to "in body" ("in body"! not "in head") and abort these steps (fragment case). Otherwise, switch the insertion mode to "in head", and abort these steps.
Comment 11 Rafael Weinstein 2012-09-06 23:08:25 UTC
To clarify

> // Should "in cell" be modified to "close the cell" on </template> (e.g. with
> </table>, </tbody>, </tfoot>, </thead>, </tr>) -- as is, </tr> wil lbe ignored
> and <div> appended to <td>
> #data
> <body><template><td></tr><div></template>
> #errors
> #document
> | <html>
> |   <head>
> |   <body>
> |     <template>
> |       <td>
> |       <div>

This is correct, but we need spec text that
http://dev.w3.org/html5/spec/parsing.html#has-an-element-in-table-scope
includes <template>

Should actually be:

#data
<body><template><td></tr><div></template>
#errors
#document
| <html>
|   <head>
|   <body>
|     <template>
|       <td>
|         <div>
Comment 12 Rafael Weinstein 2012-09-07 00:29:36 UTC
also, it's probably worth clarifying for in cell mode:

An end tag whose tag name is one of: "table", "tbody", "tfoot", "thead", "tr"
If the stack of open elements does not have an element in table scope with the same tag name as that of the token (which can only happen for "tbody", "tfoot" and "thead", or in the fragment case), then this is a parse error and the token must be ignored.

Otherwise, close the cell (see below) and reprocess the current token.

---

That this can now happen if a template contents is currently being parsed (webkit was hitting an assertion which I had to relax by checking if templateTag is in tableScope.
Comment 13 Rafael Weinstein 2012-09-07 00:43:42 UTC
note that i have patch for these edits which I'll submit as soon as I gain write access.
Comment 14 Rafael Weinstein 2012-09-07 04:41:07 UTC
http://dvcs.w3.org/hg/webcomponents/rev/923f79e27d75