Annotation of html5/spec/syntax.html, revision 1.327
1.2 mike 1: <!DOCTYPE HTML>
1.258 mike 2: <!-- when publishing, change bits marked ZZZ --><html lang="en-US-x-Hixie"><head><title>9 The HTML syntax — HTML 5</title><style type="text/css">
1.1 mike 3: pre { margin-left: 2em; white-space: pre-wrap; }
4: h2 { margin: 3em 0 1em 0; }
5: h3 { margin: 2.5em 0 1em 0; }
6: h4 { margin: 2.5em 0 0.75em 0; }
7: h5, h6 { margin: 2.5em 0 1em; }
8: h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
9: h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
10: p { margin: 1em 0; }
11: hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
12: dl, dd { margin-top: 0; margin-bottom: 0; }
13: dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
14: dt + dt { margin-top: 0; }
15: dd dt { margin-top: 0.25em; margin-bottom: 0; }
16: dd p { margin-top: 0; }
17: dd dl + p { margin-top: 1em; }
18: dd table + p { margin-top: 1em; }
19: p + * > li, dd li { margin: 1em 0; }
20: dt, dfn { font-weight: bold; font-style: normal; }
21: dt dfn { font-style: italic; }
22: pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
23: pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
24: pre em { font-weight: bolder; font-style: normal; }
25: @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
26: var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
27: table { border-collapse: collapse; border-style: hidden hidden none hidden; }
28: table thead { border-bottom: solid; }
29: table tbody th:first-child { border-left: solid; }
30: table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
31: blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
32:
33: .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
34: .matrix, .matrix td { border: none; text-align: right; }
35: .matrix { margin-left: 2em; }
36: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
37: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
38: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
39:
40: .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
41: img.extra { float: right; }
42: pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
43: pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
44: pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
45: pre.css:first-line { color: #AAAA50; }
46: dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #EEFFEE; }
47: hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
48: dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
49: dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
50: dl.domintro dd p { margin: 0.5em 0; }
51: dl.switch { padding-left: 2em; }
52: dl.switch > dt { text-indent: -1.5em; }
53: dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
54: dl.triple { padding: 0 0 0 1em; }
55: dl.triple dt, dl.triple dd { margin: 0; display: inline }
56: dl.triple dt:after { content: ':'; }
57: dl.triple dd:after { content: '\A'; white-space: pre; }
58: .diff-old { text-decoration: line-through; color: silver; background: transparent; }
59: .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
60: a .diff-new { border-bottom: 1px blue solid; }
61:
62: h2 { page-break-before: always; }
63: h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
64: h1 + h2, hr + h2.no-toc { page-break-before: auto; }
65:
66: p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
67:
68: div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
69: div.head p { margin: 0; }
70: div.head h1 { margin: 0; }
71: div.head .logo { float: right; margin: 0 1em; }
72: div.head .logo img { border: none } /* remove border from top image */
73: div.head dl { margin: 1em 0; }
74: p.copyright { font-size: x-small; font-style: oblique; margin: 0; }
75:
76: body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
77: body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
78: body > .toc > li > * { margin-bottom: 0.5em; }
79: body > .toc > li > * > li > * { margin-bottom: 0.25em; }
80: .toc, .toc li { list-style: none; }
81:
82: .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
83: .brief li { margin: 0; padding: 0; }
84: .brief li p { margin: 0; padding: 0; }
85:
86: .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
87: .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
88: .category-list li { display: inline; }
89: .category-list li:not(:last-child)::after { content: ', '; }
90: .category-list li > span, .category-list li > a { text-transform: lowercase; }
91: .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
92:
93: .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
94: .XXX > :first-child { margin-top: 0; }
95: p .XXX { line-height: 3em; }
1.159 mike 96: .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
97: .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
98: .annotation :link, .annotation :visited { color: inherit; }
99: .annotation :link:hover, .annotation :visited:hover { background: transparent; }
100: .annotation span { border: none ! important; }
1.1 mike 101: .note { color: green; background: transparent; font-family: sans-serif; }
102: .warning { color: red; background: transparent; }
103: .note, .warning { font-weight: bolder; font-style: italic; }
104: p.note, div.note { padding: 0.5em 2em; }
105: span.note { padding: 0 2em; }
106: .note p:first-child, .warning p:first-child { margin-top: 0; }
107: .note p:last-child, .warning p:last-child { margin-bottom: 0; }
108: .warning:before { font-style: normal; }
109: p.note:before { content: 'Note: '; }
110: p.warning:before { content: '\26A0 Warning! '; }
111:
112: .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
113: .bookkeeping { font-size: 0.8em; margin: 2em 0; }
114: .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
115:
116: h4 { position: relative; z-index: 3; }
117: h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
118: .element {
119: background: #EEEEFF;
120: color: black;
121: margin: 0 0 1em 0.15em;
122: padding: 0 1em 0.25em 0.75em;
123: border-left: solid #9999FF 0.25em;
124: position: relative;
125: z-index: 1;
126: }
127: .element:before {
128: position: absolute;
129: z-index: 2;
130: top: 0;
131: left: -1.15em;
132: height: 2em;
133: width: 0.9em;
134: background: #EEEEFF;
135: content: ' ';
136: border-style: none none solid solid;
137: border-color: #9999FF;
138: border-width: 0.25em;
139: }
140:
1.149 mike 141: .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
142: td > .example:only-child { margin: 0 0 0 0.1em; }
1.1 mike 143:
144: .tall-and-narrow {
145: font-size: 0.6em;
146: column-width: 25em;
147: column-gap: 1em;
148: -moz-column-width: 25em;
149: -moz-column-gap: 1em;
150: -webkit-column-width: 25em;
151: -webkit-column-gap: 1em;
152: }
153:
154: ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
155: ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
156: ul.domTree li li { list-style: none; }
157: ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
158: ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
159: ul.domTree span { font-style: italic; font-family: serif; }
160: ul.domTree .t1 code { color: purple; font-weight: bold; }
161: ul.domTree .t2 { font-style: normal; font-family: monospace; }
162: ul.domTree .t2 .name { color: black; font-weight: bold; }
163: ul.domTree .t2 .value { color: blue; font-weight: normal; }
164: ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
165: ul.domTree .t7 code, .domTree .t8 code { color: green; }
166: ul.domTree .t10 code { color: teal; }
167:
1.267 mike 168: </style><style type="text/css">
169:
1.292 mike 170: .applies thead th > * { display: block; }
171: .applies thead code { display: block; }
172: .applies tbody th { whitespace: nowrap; }
173: .applies td { text-align: center; }
174: .applies .yes { background: yellow; }
175:
1.267 mike 176: .matrix, .matrix td { border: none; text-align: right; }
177: .matrix { margin-left: 2em; }
178:
179: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
180: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
181: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
182:
183: #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
184: #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
185: #table-example-1 caption { padding-bottom: 0.5em; }
186: #table-example-1 thead, #table-example-1 tbody { border: none; }
187: #table-example-1 th, #table-example-1 td { border: solid thin; }
188: #table-example-1 th { font-weight: normal; }
189: #table-example-1 td { border-style: none solid; vertical-align: top; }
190: #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
191: #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
192: #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
193: #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
194: #table-example-1 tbody td:first-child::after { content: leader(". "); }
195: #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
196: #table-example-1 tbody td:first-child + td { width: 10em; }
197: #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
198: #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
199:
200: .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
201: .apple-table-examples * { font-family: "Times", serif; }
202: .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
203: .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
204: .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
205: .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
206: .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
207: .apple-table-examples td { text-align: right; vertical-align: top; }
208: .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
209: .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
210: .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
211: .apple-table-examples sup { line-height: 0; }
212:
1.235 mike 213: </style><link href="data:text/css," rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D" rel="alternate stylesheet" title="Highlight implementation requirements"><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css"><!-- ZZZ ED vs WD -->
1.2 mike 214: <script src="link-fixup.js"></script>
215: <link href="comms.html" title="8 Communication" rel="prev">
216: <link href="spec.html#contents" title="Table of contents" rel="index">
1.1 mike 217: <link href="named-character-references.html" title="9.6 Named character references" rel="next">
1.16 mike 218: </head><body onload="fixBrokenLink(); fixBrokenLink()"><div class="head">
1.1 mike 219: <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
1.183 mike 220: <h1>HTML5</h1>
1.1 mike 221: <h2 class="no-num no-toc" id="a-vocabulary-and-associated-apis-for-html-and-xhtml">A vocabulary and associated APIs for HTML and XHTML</h2>
1.123 mike 222: </div><nav>
1.1 mike 223: <a href="comms.html">← 8 Communication</a> –
1.2 mike 224: <a href="spec.html#contents">Table of contents</a> –
1.1 mike 225: <a href="named-character-references.html">9.6 Named character references →</a>
1.327 ! mike 226: </nav><p>This is revision 1.3050.</p>
1.11 mike 227:
1.1 mike 228:
1.123 mike 229: <h2 id="syntax"><span class="secno">9 </span><dfn>The HTML syntax</dfn></h2><p class="note">This section only describes the rules for
1.83 mike 230: <code><a href="iana-considerations.html#text-html">text/html</a></code> resources. Rules for XML resources are
1.1 mike 231: discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.159 mike 232: syntax</a>".</p><h3 id="writing"><span class="secno">9.1 </span>Writing HTML documents</h3><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p><div class="impl">
1.1 mike 233:
234: <p><i>This section only applies to documents, authoring tools, and
235: markup generators. In particular, it does not apply to conformance
236: checkers; conformance checkers must use the requirements given in
237: the next section ("parsing HTML documents").</i></p>
238:
1.123 mike 239: </div><p>Documents must consist of the following parts, in the given
240: order:</p><ol><li>Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.</li>
1.1 mike 241:
242: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
243: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
244:
245: <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
246:
247: </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
248: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
249:
1.159 mike 250: <li>The root element, in the form of an <code><a href="semantics.html#the-html-element-0">html</a></code> <a href="#syntax-elements" title="syntax-elements">element</a>.</li>
1.1 mike 251:
252: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
253: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
254:
255: </ol><p>The various types of content mentioned above are described in the
1.123 mike 256: next few sections.</p><p>In addition, there are some restrictions on how <a href="semantics.html#character-encoding-declaration" title="character encoding declaration">character encoding
1.1 mike 257: declarations</a> are to be serialized, as discussed in the
1.123 mike 258: section on that topic.</p><div class="note">
1.1 mike 259:
1.159 mike 260: <p>Space characters before the root <code><a href="semantics.html#the-html-element-0">html</a></code> element, and
261: space characters at the start of the <code><a href="semantics.html#the-html-element-0">html</a></code> element and
262: before the <code><a href="semantics.html#the-head-element-0">head</a></code> element, will be dropped when the
1.1 mike 263: document is parsed; space characters <em>after</em> the root
1.159 mike 264: <code><a href="semantics.html#the-html-element-0">html</a></code> element will be parsed as if they were at the end
265: of the <code><a href="semantics.html#the-body-element-0">body</a></code> element. Thus, space characters around the
1.1 mike 266: root element do not round-trip.</p>
267:
268: <p>It is suggested that newlines be inserted after the DOCTYPE,
269: after any comments that are before the root element, after the
1.159 mike 270: <code><a href="semantics.html#the-html-element-0">html</a></code> element's start tag (if it is not <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>), and after any comments
271: that are inside the <code><a href="semantics.html#the-html-element-0">html</a></code> element but before the
272: <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 273:
1.123 mike 274: </div><p>Many strings in the HTML syntax (e.g. the names of elements and
1.1 mike 275: their attributes) are case-insensitive, but only for characters in
276: the ranges U+0041 .. U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
277: LETTER Z) and U+0061 .. U+007A (LATIN SMALL LETTER A to LATIN SMALL
278: LETTER Z). For convenience, in this section this is just referred to
1.168 mike 279: as "case-insensitive".</p><h4 id="the-doctype"><span class="secno">9.1.1 </span>The DOCTYPE</h4><p class="XXX annotation"><span><a href="http://www.w3.org/html/wg/tracker/issues/4">ISSUE-4</a> (html-versioning) blocks progress to Last Call</span></p><p>A <dfn id="syntax-doctype" title="syntax-doctype">DOCTYPE</dfn> is a mostly useless,
1.123 mike 280: but required, header.</p><p class="note">DOCTYPEs are required for legacy reasons. When
1.1 mike 281: omitted, browsers tend to use a different rendering mode that is
282: incompatible with some specifications. Including the DOCTYPE in a
283: document ensures that the browser makes a best-effort attempt at
1.123 mike 284: following the relevant specifications.</p><p>A DOCTYPE must consist of the following characters, in this
285: order:</p><ol class="brief"><li>A U+003C LESS-THAN SIGN (<code><</code>) character.</li>
1.1 mike 286: <li>A U+0021 EXCLAMATION MARK (<code>!</code>) character.</li>
287: <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">DOCTYPE</code>".</li>
288: <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
289: <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">HTML</code>".</li>
290: <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> (defined below).</li>
291: <li>Zero or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
292: <li>A U+003E GREATER-THAN SIGN (<code>></code>) character.</li>
293: </ol><p class="note">In other words, <code><!DOCTYPE HTML></code>,
1.123 mike 294: case-insensitively.</p><p>For the purposes of HTML generators that cannot output HTML
1.1 mike 295: markup with the short DOCTYPE "<code title=""><!DOCTYPE
296: HTML></code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
297: into the DOCTYPE (in the position defined above). This string must
1.123 mike 298: consist of:</p><ol class="brief"><li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.1 mike 299: <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">SYSTEM</code>".</li>
300: <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
301: <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
302: <li>The literal string "<code title="">about:legacy-compat</code>".</li>
303: <li>A matching U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (i.e. the same character as in the earlier step marked <i>quote mark</i>).</li>
304: </ol><p class="note">In other words, <code><!DOCTYPE HTML SYSTEM
305: "about:legacy-compat"></code> or <code><!DOCTYPE HTML SYSTEM
306: 'about:legacy-compat'></code>, case-insensitively except for the bit
1.123 mike 307: in quotes.</p><p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1 mike 308: the document is generated from a system that cannot output the
1.123 mike 309: shorter string.</p><h4 id="elements-0"><span class="secno">9.1.2 </span>Elements</h4><p>There are five different kinds of <dfn id="syntax-elements" title="syntax-elements">elements</dfn>: void elements, raw text
1.1 mike 310: elements, RCDATA elements, foreign elements, and normal
1.123 mike 311: elements.</p><dl><dt><dfn id="void-elements">Void elements</dfn></dt>
1.1 mike 312:
313: <dd><code><a href="the-canvas-element.html#the-area-element">area</a></code>, <code><a href="semantics.html#the-base-element">base</a></code>, <code><a href="semantics.html#the-br-element">br</a></code>,
1.159 mike 314: <code><a href="tabular-data.html#the-col-element">col</a></code>, <code><a href="interactive-elements.html#the-command">command</a></code>, <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>,
315: <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="text-level-semantics.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>,
1.1 mike 316: <code><a href="forms.html#the-keygen-element">keygen</a></code>, <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#meta">meta</a></code>,
1.159 mike 317: <code><a href="text-level-semantics.html#the-param-element">param</a></code>, <code><a href="video.html#the-source-element">source</a></code></dd>
1.1 mike 318:
1.91 mike 319: <dt>Raw text elements</dt>
1.1 mike 320:
321: <dd><code><a href="semantics.html#script">script</a></code>, <code><a href="semantics.html#the-style-element">style</a></code></dd> <!-- iframe and
1.91 mike 322: noscript don't count as raw text for syntax purposes -->
1.1 mike 323:
324: <dt>RCDATA elements</dt>
325:
1.159 mike 326: <dd><code><a href="forms.html#the-textarea-element">textarea</a></code>, <code><a href="semantics.html#the-title-element-0">title</a></code></dd>
1.1 mike 327:
328: <dt>Foreign elements</dt>
329:
330: <dd>Elements from the <a href="#mathml-namespace">MathML namespace</a>
331: and the <a href="#svg-namespace">SVG namespace</a>.</dd>
332:
333: <dt>Normal elements</dt>
334:
335: <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
336: elements.</dd>
337:
338: </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.91 mike 339: and end of elements in the markup. Raw text, RCDATA, and normal
1.1 mike 340: elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to
341: indicate where they begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end
342: tag</a> to indicate where they end. The start and end tags of
343: certain normal elements can be <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>, as described
344: later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
345: elements</a> only have a start tag; end tags must not be
346: specified for void elements. Foreign elements must either have a
347: start tag and an end tag, or a start tag that is marked as
1.123 mike 348: self-closing, in which case they must not have an end tag.</p><p>The contents of the element must be placed between just after the
1.1 mike 349: start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
350: in certain cases</a>) and just before the end tag (which again,
351: <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
352: cases</a>). The exact allowed contents of each individual element
353: depends on the content model of that element, as described earlier
354: in this specification. Elements must not contain content that their
355: content model disallows. In addition to the restrictions placed on
356: the contents by those content models, however, the five types of
1.123 mike 357: elements have additional <em>syntactic</em> requirements.</p><p><a href="#void-elements">Void elements</a> can't have any contents (since there's
1.1 mike 358: no end tag, no content can be put between the start tag and the end
1.123 mike 359: tag).</p><p>Raw text elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1 mike 360: though it has <a href="#cdata-rcdata-restrictions">restrictions</a>
1.123 mike 361: described below.</p><p>RCDATA elements can have <a href="#syntax-text" title="syntax-text">text</a>
1.1 mike 362: and <a href="#syntax-charref" title="syntax-charref">character references</a>, but
363: the text must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
364: There are also <a href="#cdata-rcdata-restrictions">further
1.123 mike 365: restrictions</a> described below.</p><p>Foreign elements whose start tag is marked as self-closing can't
1.1 mike 366: have any contents (since, again, as there's no end tag, no content
367: can be put between the start tag and the end tag). Foreign elements
368: whose start tag is <em>not</em> marked as self-closing can have
369: <a href="#syntax-text" title="syntax-text">text</a>, <a href="#syntax-charref" title="syntax-charref">character references</a>, <a href="#syntax-cdata" title="syntax-cdata">CDATA sections</a>, other <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
370: contain the character U+003C LESS-THAN SIGN (<code><</code>) or
371: an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.123 mike 372: ampersand</a>.</p><p>Normal elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1 mike 373: <a href="#syntax-charref" title="syntax-charref">character references</a>, other
374: <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
375: contain the character U+003C LESS-THAN SIGN (<code><</code>) or
376: an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
377: ampersand</a>. Some normal elements also have <a href="#element-restrictions">yet more restrictions</a> on what
378: content they are allowed to hold, beyond the restrictions imposed by
379: the content model and those described in this paragraph. Those
1.123 mike 380: restrictions are described below.</p><p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1 mike 381: giving the element's name. HTML elements all have names that only
382: use characters in the range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE,
1.202 mike 383: U+0061 LATIN SMALL LETTER A .. U+007A LATIN SMALL LETTER Z, and
384: U+0041 LATIN CAPITAL LETTER A .. U+005A LATIN CAPITAL LETTER Z. In
385: the HTML syntax, tag names may be written with any mix of lower- and
386: uppercase letters that, when converted to all-lowercase, matches the
387: element's tag name; tag names are case-insensitive.</p><h5 id="start-tags"><span class="secno">9.1.2.1 </span>Start tags</h5><p><dfn id="syntax-start-tag" title="syntax-start-tag">Start tags</dfn> must have the
1.123 mike 388: following format:</p><ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.1 mike 389: SIGN (<code><</code>).</li>
390:
391: <li>The next few characters of a start tag must be the element's
392: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
393:
394: <li>If there are to be any attributes in the next step, there must
395: first be one or more <a href="infrastructure.html#space-character" title="space character">space
396: characters</a>.</li>
397:
398: <li>Then, the start tag may have a number of attributes, the <a href="#syntax-attributes" title="syntax-attributes">syntax for which</a> is described
399: below. Attributes may be separated from each other by one or more
400: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
401:
402: <li>After the attributes, there may be one or more <a href="infrastructure.html#space-character" title="space character">space characters</a>. (Some attributes
403: are required to be followed by a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes section</a> below.)</li>
404:
405: <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
406: or if the element is a foreign element, then there may be a single
407: U+002F SOLIDUS (<code>/</code>) character. This character has no
408: effect on void elements, but on foreign elements it marks the start
409: tag as self-closing.</li>
410:
411: <li>Finally, start tags must be closed by a U+003E GREATER-THAN
412: SIGN (<code>></code>) character.</li>
413:
1.123 mike 414: </ol><h5 id="end-tags"><span class="secno">9.1.2.2 </span>End tags</h5><p><dfn id="syntax-end-tag" title="syntax-end-tag">End tags</dfn> must have the
415: following format:</p><ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.1 mike 416: SIGN (<code><</code>).</li>
417:
418: <li>The second character of an end tag must be a U+002F SOLIDUS
419: (<code>/</code>).</li>
420:
421: <li>The next few characters of an end tag must be the element's
422: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
423:
424: <li>After the tag name, there may be one or more <a href="infrastructure.html#space-character" title="space
425: character">space characters</a>.</li>
426:
427: <li>Finally, end tags must be closed by a U+003E GREATER-THAN
428: SIGN (<code>></code>) character.</li>
429:
1.123 mike 430: </ol><h5 id="attributes"><span class="secno">9.1.2.3 </span>Attributes</h5><p><dfn id="syntax-attributes" title="syntax-attributes">Attributes</dfn> for an element
431: are expressed inside the element's start tag.</p><p>Attributes have a name and a value. <dfn id="syntax-attribute-name" title="syntax-attribute-name">Attribute names</dfn> must consist of
1.1 mike 432: one or more characters other than the <a href="infrastructure.html#space-character" title="space
433: character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
434: MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
435: (>), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters,
436: the control characters, and any characters that are not defined by
437: Unicode. In the HTML syntax, attribute names may be written with any
438: mix of lower- and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.123 mike 439: case-insensitive</a> match for the attribute's name.</p><p><dfn id="syntax-attribute-value" title="syntax-attribute-value">Attribute values</dfn> are a
1.1 mike 440: mixture of <a href="#syntax-text" title="syntax-text">text</a> and <a href="#syntax-charref" title="syntax-charref">character references</a>, except with the
1.123 mike 441: additional restriction that the text cannot contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.</p><p>Attributes can be specified in four different ways:</p><dl><dt>Empty attribute syntax</dt>
1.1 mike 442:
443: <dd>
444:
445: <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
446: name</a>.</p>
447:
448: <div class="example">
449:
450: <p>In the following example, the <code title="attr-fe-disabled"><a href="forms.html#attr-fe-disabled">disabled</a></code> attribute is given with
451: the empty attribute syntax:</p>
452:
453: <pre><input <em>disabled</em>></pre>
454:
455: </div>
456:
457: <p>If an attribute using the empty attribute syntax is to be
458: followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
459: character</a> separating the two.</p>
460:
461: </dd>
462:
1.2 mike 463: <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1 mike 464:
465: <dd>
466:
467: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
468: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
469: characters</a>, followed by a single U+003D EQUALS SIGN
470: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
471: character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
472: addition to the requirements given above for attribute values,
473: must not contain any literal <a href="infrastructure.html#space-character" title="space character">space
474: characters</a>, any U+0022 QUOTATION MARK (<code>"</code>)
475: characters, U+0027 APOSTROPHE (<code>'</code>) characters,
476: U+003D EQUALS SIGN (<code>=</code>) characters, U+003C LESS-THAN
477: SIGN (<code><</code>) characters, or U+003E GREATER-THAN SIGN
478: (<code>></code>) characters, and must not be the empty
479: string.</p>
480:
481: <div class="example">
482:
483: <p>In the following example, the <code title="attr-input-value"><a href="forms.html#attr-input-value">value</a></code> attribute is given
484: with the unquoted attribute value syntax:</p>
485:
486: <pre><input <em>value=yes</em>></pre>
487:
488: </div>
489:
490: <p>If an attribute using the unquoted attribute syntax is to be
1.101 mike 491: followed by another attribute or by the optional U+002F SOLIDUS
492: (<code>/</code>) character allowed in step 6 of the <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> syntax above, then there
1.1 mike 493: must be a <a href="infrastructure.html#space-character">space character</a> separating the two.</p>
494:
495: </dd>
496:
497: <dt>Single-quoted attribute value syntax</dt>
498:
499: <dd>
500:
501: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
502: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
503: characters</a>, followed by a single U+003D EQUALS SIGN
504: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
505: character">space characters</a>, followed by a single U+0027
506: APOSTROPHE (<code>'</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
507: addition to the requirements given above for attribute values,
508: must not contain any literal U+0027 APOSTROPHE (<code>'</code>)
509: characters, and finally followed by a second single U+0027
510: APOSTROPHE (<code>'</code>) character.</p>
511:
512: <div class="example">
513:
514: <p>In the following example, the <code title="attr-input-type"><a href="forms.html#attr-input-type">type</a></code> attribute is given with the
515: single-quoted attribute value syntax:</p>
516:
517: <pre><input <em>type='checkbox'</em>></pre>
518:
519: </div>
520:
521: <p>If an attribute using the single-quoted attribute syntax is to
522: be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
523: character</a> separating the two.</p>
524:
525: </dd>
526:
527: <dt>Double-quoted attribute value syntax</dt>
528:
529: <dd>
530:
531: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
532: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
533: characters</a>, followed by a single U+003D EQUALS SIGN
534: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
535: character">space characters</a>, followed by a single U+0022
536: QUOTATION MARK (<code>"</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
537: addition to the requirements given above for attribute values,
538: must not contain any literal U+0022 QUOTATION MARK
539: (<code>"</code>) characters, and finally followed by a second
540: single U+0022 QUOTATION MARK (<code>"</code>) character.</p>
541:
542: <div class="example">
543:
544: <p>In the following example, the <code title="attr-fe-name"><a href="forms.html#attr-fe-name">name</a></code> attribute is given with the
545: double-quoted attribute value syntax:</p>
546:
547: <pre><input <em>name="be evil"</em>></pre>
548:
549: </div>
550:
551: <p>If an attribute using the double-quoted attribute syntax is to
552: be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
553: character</a> separating the two.</p>
554:
555: </dd>
556:
557: </dl><p>There must never be two or more attributes on the same start tag
558: whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.123 mike 559: each other.</p><h5 id="optional-tags"><span class="secno">9.1.2.4 </span>Optional tags</h5><p>Certain tags can be <dfn id="syntax-tag-omission" title="syntax-tag-omission">omitted</dfn>.</p><p class="note">Omitting an element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> does not mean the element
1.1 mike 560: is not present; it is implied, but it is still there. An HTML
1.159 mike 561: document always has a root <code><a href="semantics.html#the-html-element-0">html</a></code> element, even if the
1.1 mike 562: string <code title=""><html></code> doesn't appear anywhere in
1.159 mike 563: the markup.</p><!-- <html> --><p>An <code><a href="semantics.html#the-html-element-0">html</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
564: first thing inside the <code><a href="semantics.html#the-html-element-0">html</a></code> element is not a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- </html> --><p>An <code><a href="semantics.html#the-html-element-0">html</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
565: tag</a> may be omitted if the <code><a href="semantics.html#the-html-element-0">html</a></code> element is not
566: immediately followed by a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- <head> --><p>A <code><a href="semantics.html#the-head-element-0">head</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted <!--if the
1.1 mike 567: element is empty, or--> if the first thing inside the
1.159 mike 568: <code><a href="semantics.html#the-head-element-0">head</a></code> element is an element.</p><!-- </head> --><p>A <code><a href="semantics.html#the-head-element-0">head</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
569: tag</a> may be omitted if the <code><a href="semantics.html#the-head-element-0">head</a></code> element is not
570: immediately followed by a <a href="infrastructure.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- <body> --><p>A <code><a href="semantics.html#the-body-element-0">body</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
571: element is empty, or if the first thing inside the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 572: element is not a <a href="infrastructure.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>, except if the first thing
1.159 mike 573: inside the <code><a href="semantics.html#the-body-element-0">body</a></code> element is a <code><a href="semantics.html#script">script</a></code> or
1.1 mike 574: <code><a href="semantics.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
575: tag is present, the parser makes <style> and <script> elements
576: between </head> and <body> end up in the <head> instead of implying
1.159 mike 577: the <body> --></p><!-- </body> --><p>A <code><a href="semantics.html#the-body-element-0">body</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
578: tag</a> may be omitted if the <code><a href="semantics.html#the-body-element-0">body</a></code> element is not
1.123 mike 579: immediately followed by a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- </li> --><p>A <code><a href="semantics.html#the-li-element">li</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 580: tag</a> may be omitted if the <code><a href="semantics.html#the-li-element">li</a></code> element is
581: immediately followed by another <code><a href="semantics.html#the-li-element">li</a></code> element or if there
1.305 mike 582: is no more content in the parent element.</p><!-- </dc> and </ds> can be added here one they are invented --><!-- </dt> --><p>A <code><a href="semantics.html#the-dt-element">dt</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 583: tag</a> may be omitted if the <code><a href="semantics.html#the-dt-element">dt</a></code> element is
584: immediately followed by another <code><a href="semantics.html#the-dt-element">dt</a></code> element or a
1.123 mike 585: <code><a href="semantics.html#the-dd-element">dd</a></code> element.</p><!-- </dd> --><p>A <code><a href="semantics.html#the-dd-element">dd</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 586: tag</a> may be omitted if the <code><a href="semantics.html#the-dd-element">dd</a></code> element is
587: immediately followed by another <code><a href="semantics.html#the-dd-element">dd</a></code> element or a
588: <code><a href="semantics.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.123 mike 589: parent element.</p><!-- </p> --><p>A <code><a href="semantics.html#the-p-element">p</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 590: tag</a> may be omitted if the <code><a href="semantics.html#the-p-element">p</a></code> element is
591: immediately followed by an <code><a href="semantics.html#the-address-element">address</a></code>,
592: <code><a href="semantics.html#the-article-element">article</a></code>, <code><a href="semantics.html#the-aside-element">aside</a></code>, <code><a href="semantics.html#the-blockquote-element">blockquote</a></code>,
1.305 mike 593: <!--v2DATAGRID <code>datagrid</code>,--> <code><a href="obsolete.html#dir">dir</a></code>,
1.306 mike 594: <code><a href="semantics.html#the-div-element">div</a></code>, <code><a href="semantics.html#the-dl-element">dl</a></code>, <code><a href="forms.html#the-fieldset-element">fieldset</a></code>,
1.305 mike 595: <code><a href="semantics.html#the-footer-element">footer</a></code>, <code><a href="forms.html#the-form-element">form</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h1</a></code>,
596: <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h2</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h3</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h4</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h5</a></code>,
597: <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h6</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>, <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>,
598: <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="interactive-elements.html#menus">menu</a></code>, <code><a href="semantics.html#the-nav-element">nav</a></code>,
599: <code><a href="semantics.html#the-ol-element">ol</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>, <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.1 mike 600: <code><a href="semantics.html#the-section-element">section</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>, or <code><a href="semantics.html#the-ul-element">ul</a></code>,
601: element, or if there is no more content in the parent element and
1.123 mike 602: the parent element is not an <code><a href="text-level-semantics.html#the-a-element">a</a></code> element.</p><!-- </rt> --><p>An <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 603: tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element is
604: immediately followed by an <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> or <code><a href="text-level-semantics.html#the-rp-element">rp</a></code>
1.123 mike 605: element, or if there is no more content in the parent element.</p><!-- </rp> --><p>An <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 606: tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element is
607: immediately followed by an <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> or <code><a href="text-level-semantics.html#the-rp-element">rp</a></code>
1.123 mike 608: element, or if there is no more content in the parent element.</p><!-- </optgroup> (the text assumes <optgroup> can only be inside a
1.1 mike 609: <select>; commented out text below can handle the non-<select> case
1.123 mike 610: if we ever allow it) --><p>An <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> may be omitted if the
1.1 mike 611: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
612: <code>select</code> element and--> is immediately followed by
613: another <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
614: that are ancestors of the <code>optgroup</code> element, up to and
615: including the first ancestor element that is not an
616: <code>optgroup</code> element, have no more content--> there is no
1.123 mike 617: more content in the parent element.</p><!-- so e.g. the max number of </optgroup>s are omitted here:
1.1 mike 618: <select><optgroup></select>
619: <p id=x><optgroup></optgroup>x</p>
620: <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
621: <p><optgroup id=x><optgroup></optgroup>x</p>
622: <p><optgroup><optgroup id=x>x</p>
1.123 mike 623: --><!-- </option> --><p>An <code><a href="forms.html#the-option-element">option</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 624: tag</a> may be omitted if the <code><a href="forms.html#the-option-element">option</a></code> element is
625: immediately followed by another <code><a href="forms.html#the-option-element">option</a></code> element, or if
626: it is immediately followed by an <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or
1.123 mike 627: if there is no more content in the parent element.</p><!-- <colgroup> --><p>A <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.1 mike 628: first thing inside the <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is a
629: <code><a href="tabular-data.html#the-col-element">col</a></code> element, and if the element is not immediately
630: preceded by another <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> has been omitted. (It can't be
1.123 mike 631: omitted if the element is empty.)</p><!-- </colgroup> --><p>A <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> may be omitted if the
1.1 mike 632: <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.123 mike 633: <a href="infrastructure.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- </thead> --><p>A <code><a href="tabular-data.html#the-thead-element">thead</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 634: tag</a> may be omitted if the <code><a href="tabular-data.html#the-thead-element">thead</a></code> element is
635: immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> or <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>
1.123 mike 636: element.</p><!-- <tbody> --><p>A <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.1 mike 637: first thing inside the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is a
638: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, and if the element is not immediately
639: preceded by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or
640: <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
641: tag</a> has been omitted. (It can't be omitted if the element is
1.123 mike 642: empty.)</p><!-- </tbody> --><p>A <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 643: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is
644: immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> or <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>
1.123 mike 645: element, or if there is no more content in the parent element.</p><!-- </tfoot> --><p>A <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 646: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element is
647: immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, or if there is
1.123 mike 648: no more content in the parent element.</p><!-- </tr> --><p>A <code><a href="tabular-data.html#the-tr-element">tr</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 649: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
650: immediately followed by another <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, or if there
1.123 mike 651: is no more content in the parent element.</p><!-- </td> --><p>A <code><a href="tabular-data.html#the-td-element">td</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 652: tag</a> may be omitted if the <code><a href="tabular-data.html#the-td-element">td</a></code> element is
653: immediately followed by a <code><a href="tabular-data.html#the-td-element">td</a></code> or <code><a href="tabular-data.html#the-th-element">th</a></code>
1.123 mike 654: element, or if there is no more content in the parent element.</p><!-- </th> --><p>A <code><a href="tabular-data.html#the-th-element">th</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 655: tag</a> may be omitted if the <code><a href="tabular-data.html#the-th-element">th</a></code> element is
656: immediately followed by a <code><a href="tabular-data.html#the-td-element">td</a></code> or <code><a href="tabular-data.html#the-th-element">th</a></code>
1.123 mike 657: element, or if there is no more content in the parent element.</p><p><strong>However</strong>, a <a href="#syntax-start-tag" title="syntax-start-tag">start
658: tag</a> must never be omitted if it has any attributes.</p><h5 id="element-restrictions"><span class="secno">9.1.2.5 </span>Restrictions on content models</h5><p>For historical reasons, certain elements have extra restrictions
659: beyond even the restrictions given by their content model.</p><p>A <code><a href="tabular-data.html#the-table-element">table</a></code> element must not contain <code><a href="tabular-data.html#the-tr-element">tr</a></code>
1.1 mike 660: elements, even though these elements are technically allowed inside
661: <code><a href="tabular-data.html#the-table-element">table</a></code> elements according to the content models
662: described in this specification. (If a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
663: put inside a <code><a href="tabular-data.html#the-table-element">table</a></code> in the markup, it will in fact imply
1.304 mike 664: a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag before it.)</p><p>A single <a href="#syntax-newlines" title="syntax-newlines">newline</a> may be
665: placed immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
1.1 mike 666: tag</a> of <code><a href="semantics.html#the-pre-element">pre</a></code> and <code><a href="forms.html#the-textarea-element">textarea</a></code>
667: elements. This does not affect the processing of the element. The
1.304 mike 668: otherwise optional <a href="#syntax-newlines" title="syntax-newlines">newline</a>
669: <em>must</em> be included if the element's contents start with that
670: character (because otherwise the leading newline in the contents
671: would be treated like the optional newline, and ignored).</p><div class="example">
1.1 mike 672: <p>The following two <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
673: <pre><pre>Hello</pre></pre>
674: <pre><pre><br>Hello</pre></pre>
1.123 mike 675: </div><h5 id="cdata-rcdata-restrictions"><span class="secno">9.1.2.6 </span>Restrictions on the contents of raw text and RCDATA elements</h5><p>The text in raw text and RCDATA elements must not contain any
1.1 mike 676: occurrences of the string "<code title=""></</code>" (U+003C
677: LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that
678: case-insensitively match the tag name of the element followed by one
679: of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM
1.304 mike 680: FEED (FF), U+000D CARRIAGE RETURN (CR), U+0020 SPACE, U+003E
681: GREATER-THAN SIGN (>), or U+002F SOLIDUS (/), unless that string is
682: part of an <a href="#syntax-escape" title="syntax-escape">escaping text
683: span</a>.</p><p>An <dfn id="syntax-escape" title="syntax-escape">escaping text span</dfn> is a span
1.1 mike 684: of <a href="#syntax-text" title="syntax-text">text</a> that starts with an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a> that is
685: not itself in an <a href="#syntax-escape" title="syntax-escape">escaping text
686: span</a>, and ends at the next <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span end</a>. There
687: cannot be any <a href="#syntax-charref" title="syntax-charref">character
688: references</a> inside an <a href="#syntax-escape" title="syntax-escape">escaping
689: text span</a> — sequences of characters that would look
690: like <a href="#syntax-charref" title="syntax-charref">character references</a> do not
1.123 mike 691: have special meaning.</p><p>An <dfn id="syntax-escape-start" title="syntax-escape-start">escaping text span
1.1 mike 692: start</dfn> is a part of <a href="#syntax-text" title="syntax-text">text</a> that
693: consists of the four character sequence "<code title=""><!--</code>" (U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
1.123 mike 694: MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS).</p><p>An <dfn id="syntax-escape-end" title="syntax-escape-end">escaping text span end</dfn> is
1.1 mike 695: a part of <a href="#syntax-text" title="syntax-text">text</a> that consists of the
696: three character sequence "<code title="">--></code>" (U+002D
1.134 mike 697: HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN).</p><p>An <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span
1.1 mike 698: start</a> may share its U+002D HYPHEN-MINUS characters with its
699: corresponding <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span
1.123 mike 700: end</a>.</p><p>The text in raw text elements and RCDATA elements must not have
1.91 mike 701: an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a>
702: that is not followed by an <a href="#syntax-escape-end" title="syntax-escape-end">escaping
1.123 mike 703: text span end</a>.</p><h4 id="text-0"><span class="secno">9.1.3 </span>Text</h4><p><dfn id="syntax-text" title="syntax-text">Text</dfn> is allowed inside elements,
1.1 mike 704: attributes, and comments. Text must consist of Unicode characters.
705: Text must not contain U+0000 characters. Text must not contain
1.316 mike 706: permanently undefined Unicode characters (noncharacters). Text must
707: not contain control characters other than <a href="infrastructure.html#space-character" title="space
708: character">space characters</a>. Extra constraints are placed on
709: what is and what is not allowed in text based on where the text is
710: to be put, as described in the other sections.</p><h5 id="newlines"><span class="secno">9.1.3.1 </span>Newlines</h5><p><dfn id="syntax-newlines" title="syntax-newlines">Newlines</dfn> in HTML may be
1.1 mike 711: represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A
712: LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR),
1.123 mike 713: U+000A LINE FEED (LF) characters in that order.</p><h4 id="character-references"><span class="secno">9.1.4 </span>Character references</h4><p>In certain cases described in other sections, <a href="#syntax-text" title="syntax-text">text</a> may be mixed with <dfn id="syntax-charref" title="syntax-charref">character references</dfn>. These can be used
1.1 mike 714: to escape characters that couldn't otherwise legally be included in
1.123 mike 715: <a href="#syntax-text" title="syntax-text">text</a>.</p><p>Character references must start with a U+0026 AMPERSAND
1.1 mike 716: (<code>&</code>). Following this, there are three possible kinds
1.123 mike 717: of character references:</p><dl><dt>Named character references</dt>
1.1 mike 718:
719: <dd>The ampersand must be followed by one of the names given in the
720: <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
721: case. The name must be one that is terminated by a U+003B SEMICOLON
722: (<code title="">;</code>) character.</dd>
723:
724:
725: <dt>Decimal numeric character reference</dt>
726:
727: <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
728: (<code>#</code>) character, followed by one or more digits in the
729: range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, representing a
730: base-ten integer that itself is a Unicode code point that is
731: not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
732: 0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
733: a U+003B SEMICOLON character (<code title="">;</code>).</dd>
734:
735:
736: <dt>Hexadecimal numeric character reference</dt>
737:
738: <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
739: (<code>#</code>) character, which must be followed by either a
740: U+0078 LATIN SMALL LETTER X or a U+0058 LATIN CAPITAL LETTER X
741: character, which must then be followed by one or more digits in the
742: range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, U+0061 LATIN SMALL
743: LETTER A .. U+0066 LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL
744: LETTER A .. U+0046 LATIN CAPITAL LETTER F, representing a
745: base-sixteen integer that itself is a Unicode code point that is
746: not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
747: 0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
748: a U+003B SEMICOLON character (<code title="">;</code>).</dd>
749:
750: </dl><p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
751: ampersand</dfn> is a U+0026 AMPERSAND (<code>&</code>) character
752: that is followed by some <a href="#syntax-text" title="syntax-text">text</a> other
753: than a <a href="infrastructure.html#space-character">space character</a>, a U+003C LESS-THAN SIGN
754: character ('<'), or another U+0026 AMPERSAND (<code>&</code>)
1.123 mike 755: character.</p><h4 id="cdata-sections"><span class="secno">9.1.5 </span>CDATA sections</h4><p><dfn id="syntax-cdata" title="syntax-cdata">CDATA sections</dfn> must start with
1.1 mike 756: the character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
757: MARK, U+005B LEFT SQUARE BRACKET, U+0043 LATIN CAPITAL LETTER C,
758: U+0044 LATIN CAPITAL LETTER D, U+0041 LATIN CAPITAL LETTER A, U+0054
759: LATIN CAPITAL LETTER T, U+0041 LATIN CAPITAL LETTER A, U+005B LEFT
760: SQUARE BRACKET (<code title=""><![CDATA[</code>). Following this
761: sequence, the CDATA section may have <a href="#syntax-text" title="syntax-text">text</a>, with the additional restriction
762: that the text must not contain the three character sequence U+005D
763: RIGHT SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E
764: GREATER-THAN SIGN (<code title="">]]></code>). Finally, the CDATA
765: section must be ended by the three character sequence U+005D RIGHT
766: SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E GREATER-THAN
1.159 mike 767: SIGN (<code title="">]]></code>).</p><h4 id="comments"><span class="secno">9.1.6 </span>Comments</h4><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p><p><dfn id="syntax-comments" title="syntax-comments">Comments</dfn> must start with the
1.1 mike 768: four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
769: MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title=""><!--</code>). Following this sequence, the comment may
770: have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
771: restriction that the text must not start with a single U+003E
772: GREATER-THAN SIGN ('>') character, nor start with a U+002D
773: HYPHEN-MINUS (<code title="">-</code>) character followed by a
774: U+003E GREATER-THAN SIGN ('>') character, nor contain two
775: consecutive U+002D HYPHEN-MINUS (<code title="">-</code>)
776: characters, nor end with a U+002D HYPHEN-MINUS (<code title="">-</code>) character. Finally, the comment must be ended by
777: the three character sequence U+002D HYPHEN-MINUS, U+002D
1.123 mike 778: HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--></code>).</p><div class="impl">
1.1 mike 779:
1.159 mike 780: <h3 id="parsing"><span class="secno">9.2 </span>Parsing HTML documents</h3><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 781:
782: <p><i>This section only applies to user agents, data mining tools,
783: and conformance checkers.</i></p>
784:
785: <p class="note">The rules for parsing XML documents into DOM trees
786: are covered by the next section, entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
787: syntax</a>".</p>
788:
789: <p>For <a href="dom.html#html-documents">HTML documents</a>, user agents must use the parsing
790: rules described in this section to generate the DOM trees. Together,
791: these rules define what is referred to as the <dfn id="html-parser">HTML
792: parser</dfn>.</p>
793:
794: <div class="note">
795:
796: <p>While the HTML syntax described in this specification bears a
797: close resemblance to SGML and XML, it is a separate language with
798: its own parsing rules.</p>
799:
1.183 mike 800: <p>Some earlier versions of HTML (in particular from HTML2 to
801: HTML4) were based on SGML and used SGML parsing rules. However, few
1.1 mike 802: (if any) web browsers ever implemented true SGML parsing for HTML
803: documents; the only user agents to strictly handle HTML as an SGML
804: application have historically been validators. The resulting
805: confusion — with validators claiming documents to have one
806: representation while widely deployed Web browsers interoperably
807: implemented a different representation — has wasted decades
808: of productivity. This version of HTML thus returns to a non-SGML
809: basis.</p>
810:
811: <p>Authors interested in using SGML tools in their authoring
812: pipeline are encouraged to use XML tools and the XML serialization
813: of HTML.</p>
814:
815: </div>
816:
817: <p>This specification defines the parsing rules for HTML documents,
818: whether they are syntactically correct or not. Certain points in the
819: parsing algorithm are said to be <dfn id="parse-error" title="parse error">parse
820: errors</dfn>. The error handling for parse errors is well-defined:
821: user agents must either act as described below when encountering
822: such problems, or must abort processing at the first error that they
823: encounter for which they do not wish to apply the rules described
824: below.</p>
825:
826: <p>Conformance checkers must report at least one parse error
827: condition to the user if one or more parse error conditions exist in
828: the document and must not report parse error conditions if none
829: exist in the document. Conformance checkers may report more than one
1.174 mike 830: parse error condition if more than one parse error condition exists
1.1 mike 831: in the document. Conformance checkers are not required to recover
832: from parse errors.</p>
833:
834: <p class="note">Parse errors are only errors with the
835: <em>syntax</em> of HTML. In addition to checking for parse errors,
836: conformance checkers will also verify that the document obeys all
837: the other conformance requirements described in this
838: specification.</p>
839:
840: <p>For the purposes of conformance checkers, if a resource is
841: determined to be in <a href="#syntax">the HTML syntax</a>, then it is an
842: <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
843:
1.266 mike 844: </div><div class="impl">
1.1 mike 845:
846: <h4 id="overview-of-the-parsing-model"><span class="secno">9.2.1 </span>Overview of the parsing model</h4>
847:
848: <p>The input to the HTML parsing process consists of a stream of
849: Unicode characters, which is passed through a
850: <a href="#tokenization">tokenization</a> stage followed by a <a href="#tree-construction">tree
851: construction</a> stage. The output is a <code>Document</code>
852: object.</p>
853:
854: <p class="note">Implementations that <a href="infrastructure.html#non-scripted">do not
855: support scripting</a> do not have to actually create a DOM
856: <code>Document</code> object, but the DOM tree in such cases is
857: still used as the model for the rest of the specification.</p>
858:
859: <p>In the common case, the data handled by the tokenization stage
1.159 mike 860: comes from the network, but <a href="embedded-content-0.html#dynamic-markup-insertion" title="dynamic markup
861: insertion">it can also come from script</a>, e.g. using the <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code> API.</p>
1.1 mike 862:
863: <p><img alt="" src="images/parsing-model-overview.png"></p>
864:
865: <p id="nestedParsing">There is only one set of states for the
866: tokenizer stage and the tree construction stage, but the tree
867: construction stage is reentrant, meaning that while the tree
868: construction stage is handling one token, the tokenizer might be
869: resumed, causing further tokens to be emitted and processed before
870: the first token's processing is complete.</p>
871:
872: <div class="example">
873:
874: <p>In the following example, the tree construction stage will be
875: called upon to handle a "p" start tag token while handling the
876: "script" start tag token:</p>
877:
878: <pre>...
879: <script>
880: document.write('<p>');
881: </script>
882: ...</pre>
883:
884: </div>
885:
886: <p>To handle these cases, parsers have a <dfn id="script-nesting-level">script nesting
887: level</dfn>, which must be initially set to zero, and a <dfn id="parser-pause-flag">parser
888: pause flag</dfn>, which must be initially set to false.</p>
889:
1.266 mike 890: </div><div class="impl">
1.1 mike 891:
892: <h4 id="the-input-stream"><span class="secno">9.2.2 </span>The <dfn>input stream</dfn></h4>
893:
894: <p>The stream of Unicode characters that comprises the input to the
895: tokenization stage will be initially seen by the user agent as a
896: stream of bytes (typically coming over the network or from the local
897: file system). The bytes encode the actual characters according to a
898: particular <em>character encoding</em>, which the user agent must
899: use to decode the bytes into characters.</p>
900:
901: <p class="note">For XML documents, the algorithm user agents must
902: use to determine the character encoding is given by the XML
1.104 mike 903: specification. This section does not apply to XML documents. <a href="references.html#refsXML">[XML]</a></p>
1.1 mike 904:
905:
1.168 mike 906: <h5 id="determining-the-character-encoding"><span class="secno">9.2.2.1 </span>Determining the character encoding</h5><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p>
1.1 mike 907:
908: <p>In some cases, it might be impractical to unambiguously determine
909: the encoding before parsing the document. Because of this, this
910: specification provides for a two-pass mechanism with an optional
911: pre-scan. Implementations are allowed, as described below, to apply
912: a simplified parsing algorithm to whatever bytes they have available
913: before beginning to parse the document. Then, the real parser is
914: started, using a tentative encoding derived from this pre-parse and
915: other out-of-band metadata. If, while the document is being loaded,
916: the user agent discovers an encoding declaration that conflicts with
917: this information, then the parser can get reinvoked to perform a
918: parse of the document with the real encoding.</p>
919:
920: <p id="documentEncoding">User agents must use the following
921: algorithm (the <dfn id="encoding-sniffing-algorithm">encoding sniffing algorithm</dfn>) to determine
922: the character encoding to use when decoding a document in the first
923: pass. This algorithm takes as input any out-of-band metadata
924: available to the user agent (e.g. the <a href="infrastructure.html#content-type" title="Content-Type">Content-Type metadata</a> of the document)
925: and all the bytes available so far, and returns an encoding and a
926: <dfn id="concept-encoding-confidence" title="concept-encoding-confidence">confidence</dfn>. The
927: confidence is either <i>tentative</i>, <i>certain</i>, or
928: <i>irrelevant</i>. The encoding used, and whether the confidence in
929: that encoding is <i>tentative</i> or <i>certain</i>, is <a href="#meta-charset-during-parse">used during the parsing</a> to
930: determine whether to <a href="#change-the-encoding">change the encoding</a>. If no
931: encoding is necessary, e.g. because the parser is operating on a
932: stream of Unicode characters and doesn't have to use an encoding at
933: all, then the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
934: <i>irrelevant</i>.</p>
935:
936: <ol><li><p>If the transport layer specifies an encoding, and it is
937: supported, return that encoding with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
938: <i>certain</i>, and abort these steps.</p></li>
939:
940: <li><p>The user agent may wait for more bytes of the resource to be
941: available, either in this step or at any later step in this
942: algorithm. For instance, a user agent might wait 500ms or 512
943: bytes, whichever came first. In general preparsing the source to
944: find the encoding improves performance, as it reduces the need to
945: throw away the data structures used when parsing upon finding the
946: encoding information. However, if the user agent delays too long to
947: obtain data to determine the encoding, then the cost of the delay
948: could outweigh any performance improvements from the
949: preparse.</p></li>
950:
951: <li><p>For each of the rows in the following table, starting with
952: the first one and going down, if there are as many or more bytes
953: available than the number of bytes in the first column, and the
954: first bytes of the file match the bytes given in the first column,
955: then return the encoding given in the cell in the second column of
956: that row, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
957: <i>certain</i>, and abort these steps:</p>
958:
959: <!-- this table is present in several forms in this file; keep them in sync -->
960: <table><thead><tr><th>Bytes in Hexadecimal
961: </th><th>Encoding
962: </th></tr></thead><tbody><!-- nobody uses this
963: <tr>
964: <td>00 00 FE FF
965: <td>UTF-32BE
966: <tr>
967: <td>FF FE 00 00
968: <td>UTF-32LE
969: --><tr><td>FE FF
970: </td><td>UTF-16BE
971: </td></tr><tr><td>FF FE
972: </td><td>UTF-16LE
973: </td></tr><tr><td>EF BB BF
974: </td><td>UTF-8
975: <!-- nobody uses this
976: <tr>
977: <td>DD 73 66 73
978: <td>UTF-EBCDIC
979: -->
980: </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
981: (BOMs).</p></li>
982:
983: <li><p>Otherwise, the user agent will have to search for explicit
984: character encoding information in the file itself. This should
985: proceed as follows:
986:
987: </p><p>Let <var title="">position</var> be a pointer to a byte in the
988: input stream, initially pointing at the first byte. If at any
989: point during these substeps the user agent either runs out of
990: bytes or decides that scanning further bytes would not be
991: efficient, then skip to the next step of the overall character
992: encoding detection algorithm. User agents may decide that scanning
993: <em>any</em> bytes is not efficient, in which case these substeps
994: are entirely skipped.</p>
995:
996: <p>Now, repeat the following "two" steps until the algorithm
997: aborts (either because user agent aborts, as described above, or
998: because a character encoding is found):</p>
999:
1000: <ol><li><p>If <var title="">position</var> points to:</p>
1001:
1002: <dl class="switch"><dt>A sequence of bytes starting with: 0x3C 0x21 0x2D 0x2D (ASCII '<!--')</dt>
1003: <dd>
1004:
1005: <p>Advance the <var title="">position</var> pointer so that it
1006: points at the first 0x3E byte which is preceded by two 0x2D
1007: bytes (i.e. at the end of an ASCII '-->' sequence) and comes
1008: after the 0x3C byte that was found. (The two 0x2D bytes can be
1009: the same as the those in the '<!--' sequence.)</p>
1010:
1011: </dd>
1012:
1013: <dt>A sequence of bytes starting with: 0x3C, 0x4D or 0x6D, 0x45 or 0x65, 0x54 or 0x74, 0x41 or 0x61, and finally one of 0x09, 0x0A, 0x0C, 0x0D, 0x20, 0x2F (case-insensitive ASCII '<meta' followed by a space or slash)</dt>
1014: <dd>
1015:
1016: <ol><li><p>Advance the <var title="">position</var> pointer so
1017: that it points at the next 0x09, 0x0A, 0x0C, 0x0D, 0x20, or
1018: 0x2F byte (the one in sequence of characters matched
1019: above).</p></li>
1020:
1021: <li><p><a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">Get
1022: an attribute</a> and its value. If no attribute was
1023: sniffed, then skip this inner set of steps, and jump to the
1024: second step in the overall "two step" algorithm.</p></li>
1025:
1026: <li><p>If the attribute's name is neither "<code title="">charset</code>" nor "<code title="">content</code>",
1027: then return to step 2 in these inner steps.</p></li>
1028:
1029: <li><p>If the attribute's name is "<code title="">charset</code>", let <var title="">charset</var> be
1030: the attribute's value, interpreted as a character
1031: encoding.</p></li>
1032:
1033: <li><p>Otherwise, the attribute's name is "<code title="">content</code>": apply the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for
1034: extracting an encoding from a Content-Type</a>, giving the
1035: attribute's value as the string to parse. If an encoding is
1036: returned, let <var title="">charset</var> be that
1037: encoding. Otherwise, return to step 2 in these inner
1038: steps.</p></li>
1039:
1040: <li><p>If <var title="">charset</var> is a UTF-16 encoding,
1041: change the value of <var title="">charset</var> to
1042: UTF-8.</p></li>
1043:
1044: <li><p>If <var title="">charset</var> is a supported
1045: character encoding, then return the given encoding, with
1046: <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1047: <i>tentative</i>, and abort all these steps.</p></li>
1048:
1049: <li><p>Otherwise, return to step 2 in these inner
1050: steps.</p></li>
1051:
1052: </ol></dd>
1053:
1054: <dt>A sequence of bytes starting with a 0x3C byte (ASCII '<'), optionally a 0x2F byte (ASCII '/'), and finally a byte in the range 0x41-0x5A or 0x61-0x7A (an ASCII letter)</dt>
1055: <dd>
1056:
1057: <ol><li><p>Advance the <var title="">position</var> pointer so
1058: that it points at the next 0x09 (ASCII TAB), 0x0A (ASCII LF),
1059: 0x0C (ASCII FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E
1060: (ASCII '>') byte.</p></li>
1061:
1062: <li><p>Repeatedly <a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
1063: attribute</a> until no further attributes can be found,
1064: then jump to the second step in the overall "two step"
1065: algorithm.</p></li>
1066:
1067: </ol></dd>
1068:
1069: <dt>A sequence of bytes starting with: 0x3C 0x21 (ASCII '<!')</dt>
1070: <dt>A sequence of bytes starting with: 0x3C 0x2F (ASCII '</')</dt>
1071: <dt>A sequence of bytes starting with: 0x3C 0x3F (ASCII '<?')</dt>
1072: <dd>
1073:
1074: <p>Advance the <var title="">position</var> pointer so that it
1075: points at the first 0x3E byte (ASCII '>') that comes after the
1076: 0x3C byte that was found.</p>
1077:
1078: </dd>
1079:
1080: <dt>Any other byte</dt>
1081: <dd>
1082:
1083: <p>Do nothing with that byte.</p>
1084:
1085: </dd>
1086:
1087: </dl></li>
1088:
1089: <li>Move <var title="">position</var> so it points at the next
1090: byte in the input stream, and return to the first step of this
1091: "two step" algorithm.</li>
1092:
1093: </ol><p>When the above "two step" algorithm says to <dfn id="concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
1094: attribute</dfn>, it means doing this:</p>
1095:
1096: <ol><li><p>If the byte at <var title="">position</var> is one of 0x09
1097: (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII FF), 0x0D (ASCII CR),
1098: 0x20 (ASCII space), or 0x2F (ASCII '/') then advance <var title="">position</var> to the next byte and redo this
1099: substep.</p></li>
1100:
1101: <li><p>If the byte at <var title="">position</var> is 0x3E (ASCII
1102: '>'), then abort the "get an attribute" algorithm. There isn't
1103: one.</p></li>
1104:
1105: <li><p>Otherwise, the byte at <var title="">position</var> is the
1106: start of the attribute name. Let <var title="">attribute
1107: name</var> and <var title="">attribute value</var> be the empty
1108: string.</p></li>
1109:
1110: <li><p><i>Attribute name</i>: Process the byte at <var title="">position</var> as follows:</p>
1111:
1112: <dl class="switch"><dt>If it is 0x3D (ASCII '='), and the <var title="">attribute
1113: name</var> is longer than the empty string</dt>
1114:
1115: <dd>Advance <var title="">position</var> to the next byte and
1116: jump to the step below labeled <i>value</i>.</dd>
1117:
1118: <dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
1119: FF), 0x0D (ASCII CR), or 0x20 (ASCII space)</dt>
1120:
1121: <dd>Jump to the step below labeled <i>spaces</i>.</dd>
1122:
1123: <dt>If it is 0x2F (ASCII '/') or 0x3E (ASCII '>')</dt>
1124:
1125: <dd>Abort the "get an attribute" algorithm. The attribute's
1126: name is the value of <var title="">attribute name</var>, its
1127: value is the empty string.</dd>
1128:
1129: <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
1130: 'Z')</dt>
1131:
1132: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1133: name</var> (where <var title="">b</var> is the value of the
1134: byte at <var title="">position</var>).</dd>
1135:
1136: <dt>Anything else</dt>
1137:
1138: <dd>Append the Unicode character with the same code point as the
1139: value of the byte at <var title="">position</var>) to <var title="">attribute name</var>. (It doesn't actually matter how
1140: bytes outside the ASCII range are handled here, since only
1141: ASCII characters can contribute to the detection of a character
1142: encoding.)</dd>
1143:
1144: </dl></li>
1145:
1146: <li><p>Advance <var title="">position</var> to the next byte and
1147: return to the previous step.</p></li>
1148:
1149: <li><p><i>Spaces</i>: If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
1150: LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
1151: advance <var title="">position</var> to the next byte, then,
1152: repeat this step.</p></li>
1153:
1154: <li><p>If the byte at <var title="">position</var> is
1155: <em>not</em> 0x3D (ASCII '='), abort the "get an attribute"
1156: algorithm. The attribute's name is the value of <var title="">attribute name</var>, its value is the empty
1157: string.</p></li>
1158:
1159: <li><p>Advance <var title="">position</var> past the 0x3D (ASCII
1160: '=') byte.</p></li>
1161:
1162: <li><p><i>Value:</i> If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
1163: LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
1164: advance <var title="">position</var> to the next byte, then,
1165: repeat this step.</p></li>
1166:
1167: <li><p>Process the byte at <var title="">position</var> as
1168: follows:</p>
1169:
1170: <dl class="switch"><dt>If it is 0x22 (ASCII '"') or 0x27 ("'")</dt>
1171:
1172: <dd>
1173:
1174: <ol><li>Let <var title="">b</var> be the value of the byte at
1175: <var title="">position</var>.</li>
1176:
1177: <li>Advance <var title="">position</var> to the next
1178: byte.</li>
1179:
1180: <li>If the value of the byte at <var title="">position</var>
1181: is the value of <var title="">b</var>, then advance <var title="">position</var> to the next byte and abort the "get
1182: an attribute" algorithm. The attribute's name is the value of
1183: <var title="">attribute name</var>, and its value is the
1184: value of <var title="">attribute value</var>.</li>
1185:
1186: <li>Otherwise, if the value of the byte at <var title="">position</var> is in the range 0x41 (ASCII 'A') to
1187: 0x5A (ASCII 'Z'), then append a Unicode character to <var title="">attribute value</var> whose code point is 0x20 more
1188: than the value of the byte at <var title="">position</var>.</li>
1189:
1190: <li>Otherwise, append a Unicode character to <var title="">attribute value</var> whose code point is the same as
1191: the value of the byte at <var title="">position</var>.</li>
1192:
1193: <li>Return to the second step in these substeps.</li>
1194:
1195: </ol></dd>
1196:
1197: <dt>If it is 0x3E (ASCII '>')</dt>
1198:
1199: <dd>Abort the "get an attribute" algorithm. The attribute's
1200: name is the value of <var title="">attribute name</var>, its
1201: value is the empty string.</dd>
1202:
1203:
1204: <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
1205: 'Z')</dt>
1206:
1207: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1208: value</var> (where <var title="">b</var> is the value of the
1209: byte at <var title="">position</var>). Advance <var title="">position</var> to the next byte.</dd>
1210:
1211: <dt>Anything else</dt>
1212:
1213: <dd>Append the Unicode character with the same code point as the
1214: value of the byte at <var title="">position</var>) to <var title="">attribute value</var>. Advance <var title="">position</var> to the next byte.</dd>
1215:
1216: </dl></li>
1217:
1218: <li><p>Process the byte at <var title="">position</var> as
1219: follows:</p>
1220:
1221: <dl class="switch"><dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
1222: FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E (ASCII
1223: '>')</dt>
1224:
1225: <dd>Abort the "get an attribute" algorithm. The attribute's
1226: name is the value of <var title="">attribute name</var> and its
1227: value is the value of <var title="">attribute value</var>.</dd>
1228:
1229: <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
1230: 'Z')</dt>
1231:
1232: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1233: value</var> (where <var title="">b</var> is the value of the
1234: byte at <var title="">position</var>).</dd>
1235:
1236: <dt>Anything else</dt>
1237:
1238: <dd>Append the Unicode character with the same code point as the
1239: value of the byte at <var title="">position</var>) to <var title="">attribute value</var>.</dd>
1240:
1241: </dl></li>
1242:
1243: <li><p>Advance <var title="">position</var> to the next byte and
1244: return to the previous step.</p></li>
1245:
1246: </ol><p>For the sake of interoperability, user agents should not use a
1247: pre-scan algorithm that returns different results than the one
1248: described above. (But, if you do, please at least let us know, so
1249: that we can improve this algorithm and benefit everyone...)</p>
1250:
1251: </li>
1252:
1253: <li><p>If the user agent has information on the likely encoding for
1254: this page, e.g. based on the encoding of the page when it was last
1255: visited, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1256: <i>tentative</i>, and abort these steps.</p></li>
1257:
1.322 mike 1258: <li>
1259:
1260: <p>The user agent may attempt to autodetect the character encoding
1261: from applying frequency analysis or other algorithms to the data
1262: stream. If autodetection succeeds in determining a character
1263: encoding, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1264: <i>tentative</i>, and abort these steps. <a href="references.html#refsUNIVCHARDET">[UNIVCHARDET]</a></p>
1265:
1266: <p class="note">The UTF-8 encoding has a highly detectable bit
1267: pattern. Documents that contain bytes with values greater than
1268: 0x7F which match the UTF-8 pattern are very likely to be UTF-8,
1269: while documents with byte sequences that do not match it are very
1270: likely not. User-agents are therefore encouraged to search for
1271: this common encoding.</p>
1272:
1273: </li>
1.1 mike 1274:
1275: <li><p>Otherwise, return an implementation-defined or
1276: user-specified default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1277: <i>tentative</i>. In non-legacy environments, the more
1278: comprehensive <code title="">UTF-8</code> encoding is
1279: recommended. Due to its use in legacy content, <code title="">windows-1252</code> is recommended as a default in
1.187 mike 1280: predominantly Western demographics instead.</p></li>
1.1 mike 1281:
1282: </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
1283: be set to the value returned from this algorithm, at the same time
1284: as the user agent uses the returned value to select the decoder to
1285: use for the input stream.</p>
1286:
1287:
1.237 mike 1288: <h5 id="character-encodings-0"><span class="secno">9.2.2.2 </span>Character encodings</h5><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p>
1.1 mike 1289:
1.237 mike 1290: <p>User agents must at a minimum support the UTF-8 and Windows-1252
1291: encodings, but may support more.</p>
1292:
1293: <p class="note">It is not unusual for Web browsers to support dozens
1294: if not upwards of a hundred distinct character encodings.</p>
1295:
1296: <p>User agents must support the preferred MIME name of every
1297: character encoding they support that has a preferred MIME name, and
1298: should support all the IANA-registered aliases of every character
1299: encoding they support. <a href="references.html#refsIANACHARSET">[IANACHARSET]</a></p>
1300:
1301: <p>When comparing a string specifying a character encoding with the
1302: name or alias of a character encoding to determine if they are
1303: equal, user agents must remove any leading or trailing <a href="infrastructure.html#space-character" title="space character">space characters</a> in both names, and
1304: then perform the comparison in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1305: case-insensitive</a> manner.</p>
1306:
1307: <!-- this bit will be replaced by actual alias registrations in due course -->
1308:
1309: <p>In addition, user agents must support the aliases given in the
1310: following table for every character encoding they support, so that
1311: labels from the first column are treated as equivalent to the labels
1312: given in the corresponding cell from the second column on the same
1313: row.</p>
1314:
1315: <table><caption>Additional character encoding aliases</caption>
1316: <thead><tr><th> Alias </th><th> Corresponding encoding </th><th> References
1317: </th></tr></thead><tbody><tr><td> x-sjis </td><td> windows-31J </td><td>
1318: <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
1319: <a href="references.html#refsWIN31J">[WIN31J]</a>
1320: </td></tr><tr><td> windows-932 </td><td> windows-31J </td><td>
1321: <a href="references.html#refsWIN31J">[WIN31J]</a>
1322: </td></tr><tr><td> x-x-big5 </td><td> Big5 </td><td>
1323: <a href="references.html#refsBIG5">[BIG5]</a>
1324: </td></tr></tbody></table><!-- end of bit that will be replaced by actual alias registrations in due course --><hr><p>When a user agent would otherwise use an encoding given in the
1325: first column of the following table to either convert content to
1326: Unicode characters or convert Unicode characters to bytes, it must
1327: instead use the encoding given in the cell in the second column of
1328: the same row. When a byte or sequence of bytes is treated
1329: differently due to this encoding aliasing, it is said to have been
1330: <dfn id="misinterpreted-for-compatibility">misinterpreted for compatibility</dfn>.</p>
1331:
1332: <table><caption>Character encoding overrides</caption>
1333: <thead><tr><th> Input encoding </th><th> Replacement encoding </th><th> References
1334: </th></tr></thead><tbody><!-- how about EUC-JP? --><tr><td> EUC-KR </td><td> windows-949 </td><td>
1335: <a href="references.html#refsEUCKR">[EUCKR]</a>
1336: <a href="references.html#refsWIN949">[WIN949]</a>
1337: </td></tr><tr><td> GB2312 </td><td> GBK </td><td>
1338: <a href="references.html#refsRFC1345">[RFC1345]</a>
1339: <a href="references.html#refsGBK">[GBK]</a>
1340: </td></tr><tr><td> GB_2312-80 </td><td> GBK </td><td>
1341: <a href="references.html#refsRFC1345">[RFC1345]</a>
1342: <a href="references.html#refsGBK">[GBK]</a>
1343: </td></tr><tr><td> ISO-8859-1 </td><td> windows-1252 </td><td>
1344: <a href="references.html#refsRFC1345">[RFC1345]</a>
1345: <a href="references.html#refsWIN1252">[WIN1252]</a>
1346: </td></tr><tr><td> ISO-8859-9 </td><td> windows-1254 </td><td>
1347: <a href="references.html#refsRFC1345">[RFC1345]</a>
1348: <a href="references.html#refsWIN1254">[WIN1254]</a>
1349: </td></tr><tr><td> ISO-8859-11 </td><td> windows-874 </td><td>
1350: <a href="references.html#refsISO885911">[ISO885911]</a>
1351: <a href="references.html#refsWIN874">[WIN874]</a>
1352: </td></tr><tr><td> KS_C_5601-1987 </td><td> windows-949 </td><td>
1353: <a href="references.html#refsRFC1345">[RFC1345]</a>
1354: <a href="references.html#refsWIN949">[WIN949]</a>
1355: </td></tr><tr><td> Shift_JIS </td><td> windows-31J </td><td>
1356: <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
1357: <a href="references.html#refsWIN31J">[WIN31J]</a>
1358: </td></tr><tr><td> TIS-620 </td><td> windows-874 </td><td>
1359: <a href="references.html#refsTIS620">[TIS620]</a>
1360: <a href="references.html#refsWIN874">[WIN874]</a>
1361: </td></tr><tr><td> US-ASCII </td><td> windows-1252 </td><td>
1362: <a href="references.html#refsRFC1345">[RFC1345]</a>
1363: <a href="references.html#refsWIN1252">[WIN1252]</a>
1364: </td></tr></tbody></table><p class="note">The requirement to treat certain encodings as other
1365: encodings according to the table above is a <a href="introduction.html#willful-violation">willful
1366: violation</a> of the W3C Character Model specification, motivated
1367: by a desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
1368:
1369: <p>When a user agent is to use the UTF-16 encoding but no BOM has
1370: been found, user agents must default to UTF-16LE.</p>
1371:
1372: <p class="note">The requirement to default UTF-16 to LE rather than
1373: BE is a <a href="introduction.html#willful-violation">willful violation</a> of RFC 2781, motivated by a
1374: desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
1375:
1376: <hr><p>User agents must not support the CESU-8, UTF-7, BOCU-1 and SCSU
1377: encodings. <a href="references.html#refsCESU8">[CESU8]</a> <a href="references.html#refsUTF7">[UTF7]</a> <a href="references.html#refsBOCU1">[BOCU1]</a> <a href="references.html#refsSCSU">[SCSU]</a></p>
1378:
1379: <p>Support for encodings based on EBCDIC is not recommended. This
1380: encoding is rarely used for publicly-facing Web content.</p>
1381:
1382: <p>Support for UTF-32 is not recommended. This encoding is rarely
1383: used, and frequently implemented incorrectly.</p>
1384:
1385: <p class="note">This specification does not make any attempt to
1386: support EBCDIC-based encodings and UTF-32 in its algorithms; support
1387: and use of these encodings can thus lead to unexpected behavior in
1388: implementations of this specification.</p>
1389:
1390:
1391:
1392: <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.3 </span>Preprocessing the input stream</h5>
1.1 mike 1393:
1394: <p>Given an encoding, the bytes in the input stream must be
1395: converted to Unicode characters for the tokenizer, as described by
1396: the rules for that encoding, except that the leading U+FEFF BYTE
1397: ORDER MARK character, if any, must not be stripped by the encoding
1398: layer (it is stripped by the rule below).</p> <!-- this is to
1399: prevent two leading BOMs from being both stripped, once by the
1400: decoder, and once by the parser -->
1401:
1402: <p>Bytes or sequences of bytes in the original byte stream that
1403: could not be converted to Unicode characters must be converted to
1404: U+FFFD REPLACEMENT CHARACTER code points.</p>
1405:
1406: <p class="note">Bytes or sequences of bytes in the original byte
1407: stream that did not conform to the encoding specification
1408: (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
1409: errors that conformance checkers are expected to report.</p>
1410:
1411: <p>Any byte or sequences of bytes in the original byte stream that
1.237 mike 1412: is <a href="#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
1.1 mike 1413: error</a>.</p>
1414:
1415: <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
1416: any are present.</p>
1417:
1.300 mike 1418: <p class="note">The requirement to strip a U+FEFF BYTE ORDER MARK
1419: character regardless of whether that character was used to determine
1420: the byte order is a <a href="introduction.html#willful-violation">willful violation</a> of Unicode,
1421: motivated by a desire to increase the resilience of user agents in
1422: the face of naïve transcoders.</p>
1423:
1.316 mike 1424: <p>All U+0000 NULL characters and code points in the range U+D800 to
1.315 mike 1425: U+DFFF<!-- surrogates not allowed e.g. in UTF-8, and we don't want
1426: them to suddenly turn into codepoints when they go through a UTF-16
1427: pipe --> in the input must be replaced by U+FFFD REPLACEMENT
1.316 mike 1428: CHARACTERs. Any occurrences of such characters and code points are
1429: <a href="#parse-error" title="parse error">parse errors</a>.</p>
1.1 mike 1430:
1431: <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
1432: <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
1433: CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
1.315 mike 1434: <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+FDD0
1435: to U+FDEF, and characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF,
1436: U+2FFFE, U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE,
1437: U+5FFFF, U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF,
1438: U+9FFFE, U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE,
1439: U+CFFFF, U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF,
1440: U+10FFFE, and U+10FFFF are <a href="#parse-error" title="parse error">parse
1.316 mike 1441: errors</a>. These are all control characters or permanently
1442: undefined Unicode characters (noncharacters).</p>
1.1 mike 1443:
1444: <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
1445: characters are treated specially. Any CR characters that are
1446: followed by LF characters must be removed, and any CR characters not
1447: followed by LF characters must be converted to LF characters. Thus,
1448: newlines in HTML DOMs are represented by LF characters, and there
1449: are never any CR characters in the input to the
1450: <a href="#tokenization">tokenization</a> stage.</p>
1451:
1452: <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
1453: input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
1454: the <i><a href="#next-input-character">next input character</a></i> is the first character in the
1455: input. The <dfn id="current-input-character">current input character</dfn> is the last character
1456: to have been <i><a href="#consumed">consumed</a></i>.</p>
1457:
1458: <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
1459: character or just before the end of the input stream) where content
1.159 mike 1460: inserted using <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code> is actually
1.1 mike 1461: inserted. The insertion point is relative to the position of the
1462: character immediately after it, it is not an absolute offset into
1463: the input stream. Initially, the insertion point is
1.10 mike 1464: undefined.</p>
1.1 mike 1465:
1466: <p>The "EOF" character in the tables below is a conceptual character
1467: representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
1.159 mike 1468: is a <a href="embedded-content-0.html#script-created-parser">script-created parser</a>, then the end of the
1.1 mike 1469: <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
1.159 mike 1470: character</dfn> (inserted by the <code title="dom-document-close"><a href="embedded-content-0.html#dom-document-close">document.close()</a></code> method) is
1.1 mike 1471: consumed. Otherwise, the "EOF" character is not a real character in
1472: the stream, but rather the lack of any further characters.</p>
1473:
1474:
1.237 mike 1475: <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.4 </span>Changing the encoding while parsing</h5>
1.1 mike 1476:
1477: <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
1478: encoding</dfn>, it must run the following steps. This might happen
1479: if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
1480: failed to find an encoding, or if it found an encoding that was not
1481: the actual encoding of the file.</p>
1482:
1483: <ol><li>If the new encoding is identical or equivalent to the encoding
1484: that is already being used to interpret the input stream, then set
1485: the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1486: <i>certain</i> and abort these steps. This happens when the
1487: encoding information found in the file matches what the
1488: <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
1489: encoding, and in the second pass through the parser if the first
1490: pass found that the encoding sniffing algorithm described in the
1491: earlier section failed to find the right encoding.</li>
1492:
1493: <li>If the encoding that is already being used to interpret the
1494: input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1495: <i>certain</i> and abort these steps. The new encoding is ignored;
1496: if it was anything but the same encoding, then it would be clearly
1497: incorrect.</li>
1498:
1499: <li>If the new encoding is a UTF-16 encoding, change it to
1500: UTF-8.</li>
1501:
1502: <li>If all the bytes up to the last byte converted by the current
1503: decoder have the same Unicode interpretations in both the current
1504: encoding and the new encoding, and if the user agent supports
1505: changing the converter on the fly, then the user agent may change
1506: to the new converter for the encoding on the fly. Set the
1507: <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
1508: convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1509: <i>certain</i>, and abort these steps.</li>
1510:
1511: <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
1512: <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
1513: browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
1514: sniffing algorithm</a> and instead just set the encoding to the
1515: new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1516: <i>certain</i>. Whenever possible, this should be done without
1517: actually contacting the network layer (the bytes should be
1518: re-parsed from memory), even if, e.g., the document is marked as
1519: not being cacheable. If this is not possible and contacting the
1520: network layer would involve repeating a request that uses a method
1521: other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
1522: equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1523: <i>certain</i> and ignore the new encoding. The resource will be
1524: misinterpreted. User agents may notify the user of the situation,
1525: to aid in application development.</li>
1526:
1.266 mike 1527: </ol></div><div class="impl">
1528:
1529: <h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4>
1.1 mike 1530:
1531: <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5>
1532:
1533: <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
1534: the primary operation of the tree construction stage.</p>
1535:
1536: <p>Initially, the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion mode: initial">initial</a>". It can change to
1537: "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
1538: "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
1539: "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>", "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head noscript</a>",
1.91 mike 1540: "<a href="#the-after-head-insertion-mode" title="insertion mode: after head">after head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>", "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>",
1.1 mike 1541: "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>", "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table text</a>", "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>", "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column group</a>",
1542: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
1543: "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>", "<a href="#parsing-main-intd" title="insertion mode: in cell">in cell</a>", "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>", "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
1544: table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
1545: foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
1546: body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
1547: frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
1548: frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
1549: after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
1550: frameset</a>" during the course of the parsing, as described in
1551: the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
1552: how tokens are processed and whether CDATA sections are
1553: supported.</p>
1554:
1555: <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
1556: head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
1557: body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
1558: table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
1559: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
1560: "<a href="#parsing-main-intd" title="insertion mode: in cell">in cell</a>", and "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>", are special, in
1561: that the other modes defer to them at various times. When the
1562: algorithm below says that the user agent is to do something
1563: "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
1564: mode", where <var title="">m</var> is one of these modes, the user
1565: agent must use the rules described under the <var title="">m</var>
1566: <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
1567: <a href="#insertion-mode">insertion mode</a> unchanged unless the rules in <var title="">m</var> themselves switch the <a href="#insertion-mode">insertion mode</a>
1568: to a new value.</p>
1569:
1570: <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.91 mike 1571: mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>" or "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table text</a>", the
1.1 mike 1572: <dfn id="original-insertion-mode">original insertion mode</dfn> is also set. This is the
1573: insertion mode to which the tree construction stage will return.</p>
1574:
1575: <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
1576: mode: in foreign content">in foreign content</a>", the
1577: <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
1578: is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
1579: foreign content">in foreign content</a>" mode to handle HTML
1580: (i.e. not foreign) content.</p>
1581:
1582: <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
1583: mode appropriately</dfn>, it means the UA must follow these
1584: steps:</p>
1585:
1586: <ol><li>Let <var title="">last</var> be false.</li>
1587:
1588: <li>Let <var title="">node</var> be the last node in the
1589: <a href="#stack-of-open-elements">stack of open elements</a>.</li>
1590:
1591: <li>If <var title="">node</var> is the first node in the stack of
1592: open elements, then set <var title="">last</var> to true and set
1593: <var title="">node</var> to the <var title="">context</var>
1594: element. (<a href="#fragment-case">fragment case</a>)</li>
1595:
1596: <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
1597: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>" and abort these
1598: steps. (<a href="#fragment-case">fragment case</a>)</li>
1599:
1600: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
1601: <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
1602: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
1603: mode: in cell">in cell</a>" and abort these steps.</li>
1604:
1605: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
1606: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
1607: mode: in row">in row</a>" and abort these steps.</li>
1608:
1609: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
1610: <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element, then switch the
1611: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
1612: table body">in table body</a>" and abort these steps.</li>
1613:
1614: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
1615: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>" and abort
1616: these steps.</li>
1617:
1618: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
1619: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column group</a>" and
1620: abort these steps. (<a href="#fragment-case">fragment case</a>)</li>
1621:
1622: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
1623: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" and abort these
1624: steps.</li>
1625:
1626: <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
1627: namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then switch the
1628: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
1629: foreign content">in foreign content</a>", let the
1630: <a href="#secondary-insertion-mode">secondary insertion mode</a> be "<a href="#parsing-main-inbody" title="insertion
1631: mode: in body">in body</a>", and abort these steps.</li>
1632:
1.159 mike 1633: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element-0">head</a></code> element,
1.1 mike 1634: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" ("<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>"! <em> not "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>"</em>!) and abort
1635: these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- This is only
1636: here for now in case people think that the spec accidentally
1637: omitted it and try to "fix" it. Note that noscript-in-head is also
1638: handled this way. This is all intentional. The only thing it
1639: doesn't handle is the scripting-disabled fragment parsing case for
1640: a <head> element containing a <noscript> which itself contains
1641: something other than a <link> or a <style> element; you'd expect
1642: that to break out of the <noscript> but it doesn't. This is an edge
1643: case that doesn't affect the spec, since the algorithm for fragment
1644: parsing is only used for innerHTML/outerHTML/insertAdjacentHTML(),
1645: where we know scripting is enabled. (XXX except maybe if innerHTML
1646: is set from another browsing context on a document with designMode
1647: set?) -->
1648:
1.159 mike 1649: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element-0">body</a></code> element,
1.1 mike 1650: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and abort these
1651: steps.</li>
1652:
1.5 mike 1653: <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.1 mike 1654: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>" and abort
1655: these steps. (<a href="#fragment-case">fragment case</a>)</li>
1656:
1.159 mike 1657: <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element-0">html</a></code> element,
1.1 mike 1658: then: if the <a href="#head-element-pointer"><code title="">head</code> element
1659: pointer</a> is null, switch the <a href="#insertion-mode">insertion mode</a> to
1660: "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
1661: otherwise, switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-after-head-insertion-mode" title="insertion mode: after head">after head</a>". In either
1662: case, abort these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- XXX
1663: can the head element pointer ever be non-null when we're going
1664: through these steps? -->
1665:
1666: <li>If <var title="">last</var> is true, then switch the
1667: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
1668: body">in body</a>" and abort these steps. (<a href="#fragment-case">fragment
1669: case</a>)</li>
1670:
1671: <li>Let <var title="">node</var> now be the node before <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
1672: elements</a>.</li>
1673:
1674: <li>Return to step 3.</li>
1675:
1676: </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5>
1677:
1678: <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
1679: stack grows downwards; the topmost node on the stack is the first
1680: one added to the stack, and the bottommost node of the stack is the
1681: most recently added node in the stack (notwithstanding when the
1682: stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
1683:
1684: <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
1685: html</a>" <a href="#insertion-mode">insertion mode</a> creates the
1.159 mike 1686: <code><a href="semantics.html#the-html-element-0">html</a></code> root element node, which is then added to the
1.1 mike 1687: stack.</p>
1688:
1689: <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
1.159 mike 1690: elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1 mike 1691: element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
1692: parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
1693: case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
1694: html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
1695:
1.159 mike 1696: <p>The <code><a href="semantics.html#the-html-element-0">html</a></code> node, however it is created, is the topmost
1.1 mike 1697: node of the stack. It never gets popped off the stack.</p>
1698:
1699: <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
1700: stack.</p>
1701:
1702: <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
1703: element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
1704: one. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of
1705: open elements</a> (<a href="#fragment-case">fragment case</a>), then the
1706: <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
1.159 mike 1707: of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code> element).</p>
1.1 mike 1708:
1709: <p>Elements in the stack fall into the following categories:</p>
1710:
1711: <dl><dt><dfn id="special">Special</dfn></dt>
1712:
1713: <dd><p>The following HTML elements have varying levels of special
1714: parsing rules: <code><a href="semantics.html#the-address-element">address</a></code>, <code><a href="the-canvas-element.html#the-area-element">area</a></code>,
1715: <code><a href="semantics.html#the-article-element">article</a></code>, <code><a href="semantics.html#the-aside-element">aside</a></code>, <code><a href="semantics.html#the-base-element">base</a></code>,
1.5 mike 1716: <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.159 mike 1717: <code><a href="semantics.html#the-blockquote-element">blockquote</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="semantics.html#the-br-element">br</a></code>,
1.5 mike 1718: <code><a href="obsolete.html#center">center</a></code>, <code><a href="tabular-data.html#the-col-element">col</a></code>, <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code>,
1.86 mike 1719: <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
1.305 mike 1720: <code>dc</code><!-- speculative -->, <code><a href="semantics.html#the-dd-element">dd</a></code>,
1.306 mike 1721: <code><a href="interactive-elements.html#the-details-element">details</a></code>, <code><a href="obsolete.html#dir">dir</a></code>, <code><a href="semantics.html#the-div-element">div</a></code>,
1.305 mike 1722: <code><a href="semantics.html#the-dl-element">dl</a></code>, <code>ds</code><!-- speculative -->,
1.159 mike 1723: <code><a href="semantics.html#the-dt-element">dt</a></code>, <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>, <code><a href="forms.html#the-fieldset-element">fieldset</a></code>,
1724: <code><a href="text-level-semantics.html#the-figure-element">figure</a></code>, <code><a href="semantics.html#the-footer-element">footer</a></code>, <code><a href="forms.html#the-form-element">form</a></code>,
1.86 mike 1725: <code><a href="obsolete.html#frame">frame</a></code>, <code><a href="obsolete.html#frameset">frameset</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h1</a></code>,
1726: <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h2</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h3</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h4</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h5</a></code>,
1.159 mike 1727: <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h6</a></code>, <code><a href="semantics.html#the-head-element-0">head</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>,
1728: <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>, <!--
1.86 mike 1729: <code>image</code>, (commented out because this isn't an element
1730: that can end up on the stack, so it doesn't matter) -->
1.159 mike 1731: <code><a href="text-level-semantics.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="obsolete.html#isindex-0">isindex</a></code>,
1.86 mike 1732: <code><a href="semantics.html#the-li-element">li</a></code>, <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="obsolete.html#listing">listing</a></code>,
1733: <code><a href="interactive-elements.html#menus">menu</a></code>, <code><a href="semantics.html#meta">meta</a></code>, <code><a href="semantics.html#the-nav-element">nav</a></code>,
1734: <code><a href="obsolete.html#noembed">noembed</a></code>, <code><a href="obsolete.html#noframes">noframes</a></code>, <code><a href="semantics.html#the-noscript-element">noscript</a></code>,
1.159 mike 1735: <code><a href="semantics.html#the-ol-element">ol</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>, <code><a href="text-level-semantics.html#the-param-element">param</a></code>,
1.86 mike 1736: <code><a href="obsolete.html#plaintext">plaintext</a></code>, <code><a href="semantics.html#the-pre-element">pre</a></code>, <code><a href="semantics.html#script">script</a></code>,
1737: <code><a href="semantics.html#the-section-element">section</a></code>, <code><a href="forms.html#the-select-element">select</a></code>, <code><a href="obsolete.html#spacer">spacer</a></code>,
1738: <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="forms.html#the-textarea-element">textarea</a></code>,
1.159 mike 1739: <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, <code><a href="semantics.html#the-title-element-0">title</a></code>,
1.174 mike 1740: <code><a href="tabular-data.html#the-tr-element">tr</a></code>, <code><a href="semantics.html#the-ul-element">ul</a></code>, <code>wbr</code>, and
1741: <code><a href="obsolete.html#xmp">xmp</a></code>.</p></dd>
1.1 mike 1742:
1743: <dt><dfn id="scoping">Scoping</dfn></dt>
1744: <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
1745: an element in scope">scopes</a> for various parts of the
1.5 mike 1746: parsing: <code><a href="obsolete.html#the-applet-element">applet</a></code>, <code><a href="forms.html#the-button-element">button</a></code>,
1.159 mike 1747: <code><a href="tabular-data.html#the-caption-element">caption</a></code>, <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="obsolete.html#the-marquee-element">marquee</a></code>,
1748: <code><a href="text-level-semantics.html#the-object-element">object</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>, <code><a href="tabular-data.html#the-td-element">td</a></code>,
1.1 mike 1749: <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
1750:
1751: <dt><dfn id="formatting">Formatting</dfn></dt>
1752: <dd><p>The following HTML elements are those that end up in the
1753: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>: <code><a href="text-level-semantics.html#the-a-element">a</a></code>,
1.5 mike 1754: <code><a href="text-level-semantics.html#the-b-element">b</a></code>, <code><a href="obsolete.html#big">big</a></code>, <code><a href="text-level-semantics.html#the-code-element">code</a></code>,
1755: <code><a href="text-level-semantics.html#the-em-element">em</a></code>, <code><a href="obsolete.html#font">font</a></code>, <code><a href="text-level-semantics.html#the-i-element">i</a></code>,
1756: <code>nobr</code>, <code><a href="obsolete.html#s">s</a></code>, <code><a href="text-level-semantics.html#the-small-element">small</a></code>,
1757: <code><a href="obsolete.html#strike">strike</a></code>, <code><a href="text-level-semantics.html#the-strong-element">strong</a></code>, <code><a href="obsolete.html#tt">tt</a></code>, and
1758: <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1 mike 1759:
1760: <dt><dfn id="phrasing">Phrasing</dfn></dt>
1761: <dd><p>All other elements found while parsing an HTML
1762: document.</p></dd>
1763:
1.234 mike 1764: </dl><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-the-specific-scope" title="has an element in the specific scope">have an element in a
1765: specific scope</dfn> consisting of a list of element types <var title="">list</var> when the following algorithm terminates in a
1766: match state:</p>
1.1 mike 1767:
1768: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
1769: node</a> (the bottommost node of the stack).</p></li>
1770:
1771: <li><p>If <var title="">node</var> is the target node, terminate in
1772: a match state.</p></li>
1773:
1.234 mike 1774: <li><p>Otherwise, if <var title="">node</var> is one of the element
1775: types in <var title="">list</var>, terminate in a failure
1776: state.</p></li>
1.1 mike 1777:
1778: <li><p>Otherwise, set <var title="">node</var> to the previous
1779: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
1780: 2. (This will never fail, since the loop will always terminate in
1781: the previous step if the top of the stack — an
1.159 mike 1782: <code><a href="semantics.html#the-html-element-0">html</a></code> element — is reached.)</p></li>
1.1 mike 1783:
1.234 mike 1784: </ol><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-scope" title="has an element in scope">have an element in scope</dfn> when
1785: it <a href="#has-an-element-in-the-specific-scope">has an element in the specific scope</a> consisting
1786: of the following element types:</p>
1787:
1788: <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
1789: <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
1790: <li><code><a href="semantics.html#the-html-element-0">html</a></code> in the HTML namespace</li> <!-- (This can only happen if the <var title="">node</var> is the topmost node of the <span>stack of open elements</span>, and prevents the next step from being invoked if there are no more elements in the stack.) -->
1791: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
1792: <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
1793: <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
1794: <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
1795: <li><code><a href="obsolete.html#the-marquee-element">marquee</a></code> in the HTML namespace</li>
1796: <li><code><a href="text-level-semantics.html#the-object-element">object</a></code> in the HTML namespace</li>
1797: <li><code title="">foreignObject</code> in the SVG namespace</li>
1798: </ul><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-list-item-scope" title="has an element in list item scope">have an element in list
1799: item scope</dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
1800: scope</a> consisting of the following element types:</p>
1801:
1802: <ul class="brief"><li>All the element types listed above for the <i><a href="#has-an-element-in-scope">has an element
1803: in scope</a></i> algorithm.</li>
1804: <li><code><a href="semantics.html#the-ol-element">ol</a></code> in the HTML namespace</li>
1805: <li><code><a href="semantics.html#the-ul-element">ul</a></code> in the HTML namespace</li>
1806: </ul><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-table-scope" title="has an element in table scope">have an element in <em>table
1807: scope</em></dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
1808: scope</a> consisting of the following element types:</p>
1809:
1810: <ul class="brief"><li><code><a href="semantics.html#the-html-element-0">html</a></code> in the HTML namespace</li> <!-- (This can only happen if the <var title="">node</var> is the topmost node of the <span>stack of open elements</span>, and prevents the next step from being invoked if there are no more elements in the stack.) -->
1811: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
1812: </ul><p>Nothing happens if at any time any of the elements in the
1.1 mike 1813: <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
1814: or removed from, the <code>Document</code> tree. In particular, the
1815: stack is not changed in this situation. This can cause, amongst
1816: other strange effects, content to be appended to nodes that are no
1817: longer in the DOM.</p>
1818:
1819: <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
1820: the stack is manipulated in a random-access fashion.</p>
1821:
1822:
1823: <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5>
1824:
1825: <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
1826: empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
1827:
1828: <p>The list contains elements in the <a href="#formatting">formatting</a>
1829: category, and scope markers. The scope markers are inserted when
1.159 mike 1830: entering <code><a href="obsolete.html#the-applet-element">applet</a></code> elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code>
1.1 mike 1831: elements, marquees, table cells, and table captions, and are used to
1.5 mike 1832: prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.159 mike 1833: elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code> elements, marquees, and
1.1 mike 1834: tables.</p>
1835:
1836: <p class="note">The scope markers are unrelated to the concept of an
1837: element being <a href="#has-an-element-in-scope" title="has an element in scope">in
1838: scope</a>.</p>
1839:
1840: <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
1841: elements</a> is associated with the token for which it was
1842: created, so that further elements can be created for that token if
1843: necessary.</p>
1844:
1845: <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
1846: active formatting elements</dfn>, the UA must perform the following
1847: steps:</p>
1848:
1849: <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
1850: elements</a>, then there is nothing to reconstruct; stop this
1851: algorithm.</li>
1852:
1853: <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
1854: active formatting elements</a> is a marker, or if it is an
1855: element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
1856: there is nothing to reconstruct; stop this algorithm.</li>
1857:
1858: <li>Let <var title="">entry</var> be the last (most recently added)
1859: element in the <a href="#list-of-active-formatting-elements">list of active formatting
1860: elements</a>.</li>
1861:
1862: <li>If there are no entries before <var title="">entry</var> in the
1863: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
1864: 8.</li>
1865:
1866: <li>Let <var title="">entry</var> be the entry one earlier than
1867: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
1868: elements</a>.</li>
1869:
1870: <li>If <var title="">entry</var> is neither a marker nor an element
1871: that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
1872: 4.</li>
1873:
1874: <li>Let <var title="">entry</var> be the element one later than
1875: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
1876: elements</a>.</li>
1877:
1878: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
1879: element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
1880:
1881: <li>Append <var title="">new element</var> to the <a href="#current-node">current
1882: node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
1883: elements</a> so that it is the new <a href="#current-node">current
1884: node</a>.</li>
1885:
1886: <li>Replace the entry for <var title="">entry</var> in the list
1887: with an entry for <var title="">new element</var>.</li>
1888:
1889: <li>If the entry for <var title="">new element</var> in the
1890: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
1891: entry in the list, return to step 7.</li>
1892:
1893: </ol><p>This has the effect of reopening all the formatting elements that
1894: were opened in the current body, cell, or caption (whichever is
1895: youngest) that haven't been explicitly closed.</p>
1896:
1897: <p class="note">The way this specification is written, the
1898: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
1899: elements in chronological order with the least recently added
1900: element first and the most recently added element last (except for
1901: while steps 8 to 11 of the above algorithm are being executed, of
1902: course).</p>
1903:
1904: <p>When the steps below require the UA to <dfn id="clear-the-list-of-active-formatting-elements-up-to-the-last-marker">clear the list of
1905: active formatting elements up to the last marker</dfn>, the UA must
1906: perform the following steps:</p>
1907:
1908: <ol><li>Let <var title="">entry</var> be the last (most recently added)
1909: entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
1910:
1911: <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
1912: formatting elements</a>.</li>
1913:
1914: <li>If <var title="">entry</var> was a marker, then stop the
1915: algorithm at this point. The list has been cleared up to the last
1916: marker.</li>
1917:
1918: <li>Go to step 1.</li>
1919:
1920: </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5>
1921:
1922: <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
1923: pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
1924: pointer</dfn> are both null.</p>
1925:
1.159 mike 1926: <p>Once a <code><a href="semantics.html#the-head-element-0">head</a></code> element has been parsed (whether
1.1 mike 1927: implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
1928: element pointer</a> gets set to point to this node.</p>
1929:
1930: <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
1931: points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
1932: whose end tag has not yet been seen. It is used to make form
1933: controls associate with forms in the face of dramatically bad
1934: markup, for historical reasons.</p>
1935:
1936:
1937: <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5>
1938:
1939: <p>The <dfn id="scripting-flag">scripting flag</dfn> is set to "enabled" if <a href="browsers.html#concept-n-script" title="concept-n-script">scripting was enabled</a> for the
1940: <code>Document</code> with which the parser is associated when the
1941: parser was created, and "disabled" otherwise.</p>
1942:
1943: <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
1944: when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
1945: parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
1946: don't execute in that case.</p>
1947:
1948: <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
1949: created. It is set to "not ok" after certain tokens are seen.</p>
1950:
1.266 mike 1951: </div><div class="impl">
1.1 mike 1952:
1.159 mike 1953: <h4 id="tokenization"><span class="secno">9.2.4 </span><dfn>Tokenization</dfn></h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 1954:
1955: <p>Implementations must act as if they used the following state
1956: machine to tokenize HTML. The state machine must start in the
1957: <a href="#data-state">data state</a>. Most states consume a single character,
1958: which may have various side-effects, and either switches the state
1959: machine to a new state to <em>reconsume</em> the same character, or
1960: switches it to a new state (to consume the next character), or
1961: repeats the same state (to consume the next character). Some states
1962: have more complicated behavior and can consume several characters
1963: before switching to another state.</p>
1964:
1965: <p>The exact behavior of certain states depends on a <dfn id="content-model-flag">content
1966: model flag</dfn> that is set after certain tokens are emitted. The
1.91 mike 1967: flag has several states: <i title="">PCDATA</i>, <i title="">RCDATA</i>, <i title="">RAWTEXT</i>, and <i title="">PLAINTEXT</i>. Initially, it must be in the PCDATA
1968: state. In the RCDATA and RAWTEXT states, a further <dfn id="escape-flag">escape
1.1 mike 1969: flag</dfn> is used to control the behavior of the tokenizer. It is
1970: either true or false, and initially must be set to the false
1971: state. The <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
1972: elements</a> also affects tokenization.</p>
1973:
1974: <p>The output of the tokenization step is a series of zero or more
1975: of the following tokens: DOCTYPE, start tag, end tag, comment,
1976: character, end-of-file. DOCTYPE tokens have a name, a public
1977: identifier, a system identifier, and a <i>force-quirks
1978: flag</i>. When a DOCTYPE token is created, its name, public
1979: identifier, and system identifier must be marked as missing (which
1980: is a distinct state from the empty string), and the <i>force-quirks
1981: flag</i> must be set to <i>off</i> (its other state is
1982: <i>on</i>). Start and end tag tokens have a tag name, a
1983: <i>self-closing flag</i>, and a list of attributes, each of which
1984: has a name and a value. When a start or end tag token is created,
1985: its <i>self-closing flag</i> must be unset (its other state is that
1986: it be set), and its attributes list must be empty. Comment and
1987: character tokens have data.</p>
1988:
1989: <p>When a token is emitted, it must immediately be handled by the
1990: <a href="#tree-construction">tree construction</a> stage. The tree construction stage
1991: can affect the state of the <a href="#content-model-flag">content model flag</a>, and can
1992: insert additional characters into the stream. (For example, the
1993: <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
1.159 mike 1994: using the <a href="embedded-content-0.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
1.1 mike 1995: characters into the stream being tokenized.)</p>
1996:
1997: <p>When a start tag token is emitted with its <i>self-closing
1998: flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
1999: self-closing flag">acknowledged</dfn> when it is processed by the
2000: tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
2001:
2002: <p>When an end tag token is emitted, the <a href="#content-model-flag">content model
2003: flag</a> must be switched to the PCDATA state.</p>
2004:
2005: <p>When an end tag token is emitted with attributes, that is a
2006: <a href="#parse-error">parse error</a>.</p>
2007:
2008: <p>When an end tag token is emitted with its <i>self-closing
2009: flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
2010:
2011: <p>Before each step of the tokenizer, the user agent must first
2012: check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
2013: tokenizer must abort the processing of any nested invocations of the
2014: tokenizer, yielding control back to the caller. If it is false, then
2015: the user agent may then check to see if either one of the scripts in
2016: the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will execute as soon as
2017: possible</a> or the first script in the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts
2018: that will execute asynchronously</a>, has <a href="semantics.html#completed-loading">completed
2019: loading</a>. If one has, then it must be <a href="semantics.html#executing-a-script-block" title="executing a
2020: script block">executed</a> and removed from its list.</p>
2021:
2022: <p>The tokenizer state machine consists of the states defined in the
2023: following subsections.</p>
2024:
2025: <!-- XXX should go through these reordering the entries so that
2026: they're in some consistent order, like, by Unicode, errors last, or
2027: something -->
2028:
2029: <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5>
2030:
2031: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2032:
2033: <dl class="switch"><dt>U+0026 AMPERSAND (&)</dt>
2034: <dd>When the <a href="#content-model-flag">content model flag</a> is set to one of the
2035: PCDATA or RCDATA states and the <a href="#escape-flag">escape flag</a> is
1.299 mike 2036: false: switch to the <a href="#character-reference-in-data-state">character reference in data
1.56 mike 2037: state</a>.</dd>
2038: <dd>Otherwise: treat it as per the "anything else" entry
2039: below.</dd>
1.1 mike 2040:
2041: <dt>U+002D HYPHEN-MINUS (-)</dt>
2042: <dd>
2043:
2044: <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 2045: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1 mike 2046: is false, and there are at least three characters before this
2047: one in the input stream, and the last four characters in the
2048: input stream, including this one, are U+003C LESS-THAN SIGN,
2049: U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, and U+002D
2050: HYPHEN-MINUS ("<!--"), then set the <a href="#escape-flag">escape flag</a>
2051: to true.</p>
2052:
2053: <p>In any case, emit the input character as a character
2054: token. Stay in the <a href="#data-state">data state</a>.</p>
2055:
2056: </dd>
2057:
2058: <dt>U+003C LESS-THAN SIGN (<)</dt>
2059: <dd>When the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
2060: state: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
2061: <dd>When the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 2062: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1 mike 2063: is false: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
2064: <dd>Otherwise: treat it as per the "anything else" entry
2065: below.</dd>
2066:
2067: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2068: <dd>
2069:
2070: <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 2071: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape
1.1 mike 2072: flag</a> is true, and the last three characters in the input
2073: stream including this one are U+002D HYPHEN-MINUS, U+002D
2074: HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("-->"), set the
2075: <a href="#escape-flag">escape flag</a> to false.</p> <!-- no need to check
2076: that there are enough characters, since you can only run into
2077: this if the flag is true in the first place, which requires four
2078: characters. -->
2079:
2080: <p>In any case, emit the input character as a character
2081: token. Stay in the <a href="#data-state">data state</a>.</p>
2082:
2083: </dd>
2084:
2085: <dt>EOF</dt>
2086: <dd>Emit an end-of-file token.</dd>
2087:
2088: <dt>Anything else</dt>
2089: <dd>Emit the input character as a character token. Stay in the
2090: <a href="#data-state">data state</a>.</dd>
2091:
1.299 mike 2092: </dl><h5 id="character-reference-in-data-state"><span class="secno">9.2.4.2 </span><dfn>Character reference in data state</dfn></h5>
1.1 mike 2093:
2094: <p><i>(This cannot happen if the <a href="#content-model-flag">content model flag</a>
1.91 mike 2095: is set to the RAWTEXT state.)</i></p>
1.1 mike 2096:
2097: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
2098: <a href="#additional-allowed-character">additional allowed character</a>.</p>
2099:
2100: <p>If nothing is returned, emit a U+0026 AMPERSAND character
2101: token.</p>
2102:
2103: <p>Otherwise, emit the character token that was returned.</p>
2104:
2105: <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
2106:
2107:
2108: <h5 id="tag-open-state"><span class="secno">9.2.4.3 </span><dfn>Tag open state</dfn></h5>
2109:
2110: <p>The behavior of this state depends on the <a href="#content-model-flag">content model
2111: flag</a>.</p>
2112:
2113: <dl><dt>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA
1.91 mike 2114: or RAWTEXT states</dt>
1.1 mike 2115:
2116: <dd>
2117:
2118: <p>Consume the <a href="#next-input-character">next input character</a>. If it is a
2119: U+002F SOLIDUS (/) character, switch to the <a href="#close-tag-open-state">close tag open
2120: state</a>. Otherwise, emit a U+003C LESS-THAN SIGN character
2121: token and reconsume the <a href="#current-input-character">current input character</a> in the
2122: <a href="#data-state">data state</a>.</p>
2123:
2124: </dd>
2125:
2126: <dt>If the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
2127: state</dt>
2128:
2129: <dd>
2130:
2131: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2132:
2133: <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
2134: <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
2135:
2136: <dt>U+002F SOLIDUS (/)</dt>
2137: <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
2138:
2139: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2140: <dd>Create a new start tag token, set its tag name to the
2141: lowercase version of the input character (add 0x0020 to the
2142: character's code point), then switch to the <a href="#tag-name-state">tag name
2143: state</a>. (Don't emit the token yet; further details will
2144: be filled in before it is emitted.)</dd>
2145:
2146: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2147: <dd>Create a new start tag token, set its tag name to the input
2148: character, then switch to the <a href="#tag-name-state">tag name
2149: state</a>. (Don't emit the token yet; further details will
2150: be filled in before it is emitted.)</dd>
2151:
2152: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2153: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2154: character token and a U+003E GREATER-THAN SIGN character
2155: token. Switch to the <a href="#data-state">data state</a>.</dd>
2156:
2157: <dt>U+003F QUESTION MARK (?)</dt>
2158: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2159: comment state</a>.</dd>
2160:
2161: <dt>Anything else</dt>
2162: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2163: character token and reconsume the <a href="#current-input-character">current input character</a> in the
2164: <a href="#data-state">data state</a>.</dd>
2165:
2166: </dl></dd>
2167:
2168: </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.4 </span><dfn>Close tag open state</dfn></h5>
2169:
2170: <p>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA or
1.91 mike 2171: RAWTEXT states but no start tag token has ever been emitted by this
1.1 mike 2172: instance of the tokenizer (<a href="#fragment-case">fragment case</a>), or, if the
1.91 mike 2173: <a href="#content-model-flag">content model flag</a> is set to the RCDATA or RAWTEXT states
1.1 mike 2174: and the next few characters do not match the tag name of the last
2175: start tag token emitted (compared in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2176: case-insensitive</a> manner), or if they do but they are not
2177: immediately followed by one of the following characters:</p>
2178:
2179: <ul class="brief"><li>U+0009 CHARACTER TABULATION</li>
2180: <li>U+000A LINE FEED (LF)</li>
2181: <li>U+000C FORM FEED (FF)</li>
2182: <!--<li>U+000D CARRIAGE RETURN (CR)</li>-->
2183: <li>U+0020 SPACE</li>
2184: <li>U+003E GREATER-THAN SIGN (>)</li>
2185: <li>U+002F SOLIDUS (/)</li>
2186: <li>EOF</li>
2187: </ul><p>...then emit a U+003C LESS-THAN SIGN character token, a U+002F
2188: SOLIDUS character token, and switch to the <a href="#data-state">data state</a>
2189: to process the <a href="#next-input-character">next input character</a>.</p>
2190:
2191: <p>Otherwise, if the <a href="#content-model-flag">content model flag</a> is set to the
2192: PCDATA state, or if the next few characters <em>do</em> match that tag
2193: name, consume the <a href="#next-input-character">next input character</a>:</p>
2194:
2195: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2196: <dd>Create a new end tag token, set its tag name to the lowercase
2197: version of the input character (add 0x0020 to the character's
2198: code point), then switch to the <a href="#tag-name-state">tag name
2199: state</a>. (Don't emit the token yet; further details will be
2200: filled in before it is emitted.)</dd>
2201:
2202: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2203: <dd>Create a new end tag token, set its tag name to the input
2204: character, then switch to the <a href="#tag-name-state">tag name state</a>. (Don't
2205: emit the token yet; further details will be filled in before it
2206: is emitted.)</dd>
2207:
2208: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2209: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
2210: state</a>.</dd>
2211:
2212: <dt>EOF</dt>
2213: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2214: character token and a U+002F SOLIDUS character token. Reconsume
2215: the EOF character in the <a href="#data-state">data state</a>.</dd>
2216:
2217: <dt>Anything else</dt>
2218: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2219: comment state</a>.</dd>
2220:
2221: </dl><h5 id="tag-name-state"><span class="secno">9.2.4.5 </span><dfn>Tag name state</dfn></h5>
2222:
2223: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2224:
2225: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2226: <dt>U+000A LINE FEED (LF)</dt>
2227: <dt>U+000C FORM FEED (FF)</dt>
2228: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2229: <dt>U+0020 SPACE</dt>
2230: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2231:
2232: <dt>U+002F SOLIDUS (/)</dt>
2233: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2234:
2235: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2236: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2237: state</a>.</dd>
2238:
2239: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2240: <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
2241: (add 0x0020 to the character's code point) to the current tag
2242: token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
2243:
2244: <dt>EOF</dt>
2245: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2246: <a href="#data-state">data state</a>.</dd>
2247:
2248: <dt>Anything else</dt>
2249: <dd>Append the <a href="#current-input-character">current input character</a> to the current tag token's
2250: tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
2251:
2252: </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.6 </span><dfn>Before attribute name state</dfn></h5>
2253:
2254: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2255:
2256: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2257: <dt>U+000A LINE FEED (LF)</dt>
2258: <dt>U+000C FORM FEED (FF)</dt>
2259: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2260: <dt>U+0020 SPACE</dt>
2261: <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2262:
2263: <dt>U+002F SOLIDUS (/)</dt>
2264: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2265:
2266: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2267: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2268: state</a>.</dd>
2269:
2270: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2271: <dd>Start a new attribute in the current tag token. Set that
2272: attribute's name to the lowercase version of the <a href="#current-input-character">current input
2273: character</a> (add 0x0020 to the character's code point), and its
2274: value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
2275: state</a>.</dd>
2276:
2277: <dt>U+0022 QUOTATION MARK (")</dt>
2278: <dt>U+0027 APOSTROPHE (')</dt>
2279: <dt>U+003C LESS-THAN SIGN (<)</dt>
2280: <dt>U+003D EQUALS SIGN (=)</dt>
2281: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2282: entry below.</dd>
2283:
2284: <dt>EOF</dt>
2285: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2286: <a href="#data-state">data state</a>.</dd>
2287:
2288: <dt>Anything else</dt>
2289: <dd>Start a new attribute in the current tag token. Set that
2290: attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
2291: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2292: state</a>.</dd>
2293:
2294: </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.7 </span><dfn>Attribute name state</dfn></h5>
2295:
2296: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2297:
2298: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2299: <dt>U+000A LINE FEED (LF)</dt>
2300: <dt>U+000C FORM FEED (FF)</dt>
2301: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2302: <dt>U+0020 SPACE</dt>
2303: <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
2304:
2305: <dt>U+002F SOLIDUS (/)</dt>
2306: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2307:
2308: <dt>U+003D EQUALS SIGN (=)</dt>
2309: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2310:
2311: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2312: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2313: state</a>.</dd>
2314:
2315: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2316: <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
2317: (add 0x0020 to the character's code point) to the current
2318: attribute's name. Stay in the <a href="#attribute-name-state">attribute name
2319: state</a>.</dd>
2320:
2321: <dt>U+0022 QUOTATION MARK (")</dt>
2322: <dt>U+0027 APOSTROPHE (')</dt>
2323: <dt>U+003C LESS-THAN SIGN (<)</dt>
2324: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2325: entry below.</dd>
2326:
2327: <dt>EOF</dt>
2328: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2329: <a href="#data-state">data state</a>.</dd>
2330:
2331: <dt>Anything else</dt>
2332: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2333: name. Stay in the <a href="#attribute-name-state">attribute name state</a>.</dd>
2334:
2335: </dl><p>When the user agent leaves the attribute name state (and before
2336: emitting the tag token, if appropriate), the complete attribute's
2337: name must be compared to the other attributes on the same token;
2338: if there is already an attribute on the token with the exact same
2339: name, then this is a <a href="#parse-error">parse error</a> and the new
2340: attribute must be dropped, along with the value that gets
2341: associated with it (if any).</p>
2342:
2343:
2344: <h5 id="after-attribute-name-state"><span class="secno">9.2.4.8 </span><dfn>After attribute name state</dfn></h5>
2345:
2346: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2347:
2348: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2349: <dt>U+000A LINE FEED (LF)</dt>
2350: <dt>U+000C FORM FEED (FF)</dt>
2351: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2352: <dt>U+0020 SPACE</dt>
2353: <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
2354:
2355: <dt>U+002F SOLIDUS (/)</dt>
2356: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2357:
2358: <dt>U+003D EQUALS SIGN (=)</dt>
2359: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2360:
2361: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2362: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2363: state</a>.</dd>
2364:
2365: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2366: <dd>Start a new attribute in the current tag token. Set that
2367: attribute's name to the lowercase version of the <a href="#current-input-character">current input character</a>
2368: (add 0x0020 to the character's code point), and its value to
2369: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2370: state</a>.</dd>
2371:
2372: <dt>U+0022 QUOTATION MARK (")</dt>
2373: <dt>U+0027 APOSTROPHE (')</dt>
2374: <dt>U+003C LESS-THAN SIGN (<)</dt>
2375: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2376: entry below.</dd>
2377:
2378: <dt>EOF</dt>
2379: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2380: <a href="#data-state">data state</a>.</dd>
2381:
2382: <dt>Anything else</dt>
2383: <dd>Start a new attribute in the current tag token. Set that
2384: attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
2385: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2386: state</a>.</dd>
2387:
2388: </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.9 </span><dfn>Before attribute value state</dfn></h5>
2389:
2390: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2391:
2392: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2393: <dt>U+000A LINE FEED (LF)</dt>
2394: <dt>U+000C FORM FEED (FF)</dt>
2395: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2396: <dt>U+0020 SPACE</dt>
2397: <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2398:
2399: <dt>U+0022 QUOTATION MARK (")</dt>
2400: <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
2401:
2402: <dt>U+0026 AMPERSAND (&)</dt>
2403: <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
2404: and reconsume this input character.</dd>
2405:
2406: <dt>U+0027 APOSTROPHE (')</dt>
2407: <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
2408:
2409: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2410: <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
2411: the <a href="#data-state">data state</a>.</dd>
2412:
2413: <dt>U+003C LESS-THAN SIGN (<)</dt>
2414: <dt>U+003D EQUALS SIGN (=)</dt>
2415: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2416: entry below.</dd>
2417:
2418: <dt>EOF</dt>
2419: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2420: <a href="#data-state">data state</a>.</dd>
2421:
2422: <dt>Anything else</dt>
2423: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2424: attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
2425: state</a>.</dd>
2426:
2427: </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.10 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
2428:
2429: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2430:
2431: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
2432: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
2433: state</a>.</dd>
2434:
2435: <dt>U+0026 AMPERSAND (&)</dt>
2436: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
2437: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2438: being U+0022 QUOTATION MARK (").</dd>
2439:
2440: <dt>EOF</dt>
2441: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2442: <a href="#data-state">data state</a>.</dd>
2443:
2444: <dt>Anything else</dt>
2445: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2446: value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted)
2447: state</a>.</dd>
2448:
2449: </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.11 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
2450:
2451: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2452:
2453: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
2454: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
2455: state</a>.</dd>
2456:
2457: <dt>U+0026 AMPERSAND (&)</dt>
2458: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
2459: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2460: being U+0027 APOSTROPHE (').</dd>
2461:
2462: <dt>EOF</dt>
2463: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2464: <a href="#data-state">data state</a>.</dd>
2465:
2466: <dt>Anything else</dt>
2467: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2468: value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted)
2469: state</a>.</dd>
2470:
2471: </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.12 </span><dfn>Attribute value (unquoted) state</dfn></h5>
2472:
2473: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2474:
2475: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2476: <dt>U+000A LINE FEED (LF)</dt>
2477: <dt>U+000C FORM FEED (FF)</dt>
2478: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2479: <dt>U+0020 SPACE</dt>
2480: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2481:
2482: <dt>U+0026 AMPERSAND (&)</dt>
2483: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
1.299 mike 2484: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2485: being U+003E GREATER-THAN SIGN (>).</dd>
1.1 mike 2486:
2487: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2488: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2489: state</a>.</dd>
2490:
2491: <dt>U+0022 QUOTATION MARK (")</dt>
2492: <dt>U+0027 APOSTROPHE (')</dt>
2493: <dt>U+003C LESS-THAN SIGN (<)</dt>
2494: <dt>U+003D EQUALS SIGN (=)</dt>
2495: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2496: entry below.</dd>
2497:
2498: <dt>EOF</dt>
2499: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2500: <a href="#data-state">data state</a>.</dd>
2501:
2502: <dt>Anything else</dt>
2503: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2504: value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
2505: state</a>.</dd>
2506:
2507: </dl><h5 id="character-reference-in-attribute-value-state"><span class="secno">9.2.4.13 </span><dfn>Character reference in attribute value state</dfn></h5>
2508:
2509: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
2510:
2511: <p>If nothing is returned, append a U+0026 AMPERSAND character to
2512: the current attribute's value.</p>
2513:
2514: <p>Otherwise, append the returned character token to the current
2515: attribute's value.</p>
2516:
2517: <p>Finally, switch back to the attribute value state that you were
2518: in when were switched into this state.</p>
2519:
2520:
2521: <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.14 </span><dfn>After attribute value (quoted) state</dfn></h5>
2522:
2523: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2524:
2525: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2526: <dt>U+000A LINE FEED (LF)</dt>
2527: <dt>U+000C FORM FEED (FF)</dt>
2528: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2529: <dt>U+0020 SPACE</dt>
2530: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2531:
2532: <dt>U+002F SOLIDUS (/)</dt>
2533: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2534:
2535: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2536: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2537: state</a>.</dd>
2538:
2539: <dt>EOF</dt>
2540: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2541: <a href="#data-state">data state</a>.</dd>
2542:
2543: <dt>Anything else</dt>
2544: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
2545: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2546:
2547: </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.15 </span><dfn>Self-closing start tag state</dfn></h5>
2548:
2549: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2550:
2551: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2552: <dd>Set the <i>self-closing flag</i> of the current tag
2553: token. Emit the current tag token. Switch to the <a href="#data-state">data
2554: state</a>.</dd>
2555:
2556: <dt>EOF</dt>
2557: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2558: <a href="#data-state">data state</a>.</dd>
2559:
2560: <dt>Anything else</dt>
2561: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
2562: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2563:
2564: </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.16 </span><dfn>Bogus comment state</dfn></h5>
2565:
2566: <p><i>(This can only happen if the <a href="#content-model-flag">content model
2567: flag</a> is set to the PCDATA state.)</i></p>
2568:
2569: <p>Consume every character up to and including the first U+003E
2570: GREATER-THAN SIGN character (>) or the end of the file (EOF),
2571: whichever comes first. Emit a comment token whose data is the
2572: concatenation of all the characters starting from and including
2573: the character that caused the state machine to switch into the
2574: bogus comment state, up to and including the character immediately
2575: before the last consumed character (i.e. up to the character just
2576: before the U+003E or EOF character). (If the comment was started
2577: by the end of the file (EOF), the token is empty.)</p>
2578:
2579: <p>Switch to the <a href="#data-state">data state</a>.</p>
2580:
2581: <p>If the end of the file was reached, reconsume the EOF
2582: character.</p>
2583:
2584:
2585: <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.17 </span><dfn>Markup declaration open state</dfn></h5>
2586:
2587: <p><i>(This can only happen if the <a href="#content-model-flag">content model
2588: flag</a> is set to the PCDATA state.)</i></p>
2589:
2590: <p>If the next two characters are both U+002D HYPHEN-MINUS (-)
2591: characters, consume those two characters, create a comment token
2592: whose data is the empty string, and switch to the <a href="#comment-start-state">comment
2593: start state</a>.</p>
2594:
2595: <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2596: case-insensitive</a> match for the word "DOCTYPE", then consume
2597: those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
2598:
2599: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
2600: content</a>" and the <a href="#current-node">current node</a> is not an element
2601: in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
2602: an <span>ASCII case-sensitive</span> match for the string "[CDATA["
2603: (the five uppercase letters "CDATA" with a U+005B LEFT SQUARE
2604: BRACKET character before and after), then consume those characters
1.91 mike 2605: and switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1 mike 2606:
2607: <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
2608: <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
2609: consumed, if any, is the first character that will be in the
2610: comment.</p>
2611:
2612:
2613: <h5 id="comment-start-state"><span class="secno">9.2.4.18 </span><dfn>Comment start state</dfn></h5>
2614:
2615: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2616:
2617: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2618: <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
2619:
2620: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2621: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
2622: <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
2623: -->
2624:
2625: <dt>EOF</dt>
2626: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2627: the EOF character in the <a href="#data-state">data state</a>.</dd>
2628:
2629: <dt>Anything else</dt>
2630: <dd>Append the input character to the comment token's
2631: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
2632:
2633: </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.19 </span><dfn>Comment start dash state</dfn></h5>
2634:
2635: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2636:
2637: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2638: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
2639:
2640: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2641: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
2642: the <a href="#data-state">data state</a>.</dd>
2643:
2644: <dt>EOF</dt>
2645: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2646: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2647: in comment end state -->
2648:
2649: <dt>Anything else</dt>
2650: <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
2651: character to the comment token's data. Switch to the
2652: <a href="#comment-state">comment state</a>.</dd>
2653:
2654: </dl><h5 id="comment-state"><span class="secno">9.2.4.20 </span><dfn id="comment">Comment state</dfn></h5>
2655:
2656: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2657:
2658: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2659: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
2660:
2661: <dt>EOF</dt>
2662: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2663: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2664: in comment end state -->
2665:
2666: <dt>Anything else</dt>
2667: <dd>Append the input character to the comment token's data. Stay
2668: in the <a href="#comment-state">comment state</a>.</dd>
2669:
2670: </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.21 </span><dfn>Comment end dash state</dfn></h5>
2671:
2672: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2673:
2674: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2675: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
2676:
2677: <dt>EOF</dt>
2678: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2679: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2680: in comment end state -->
2681:
2682: <dt>Anything else</dt>
2683: <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
2684: character to the comment token's data. Switch to the
2685: <a href="#comment-state">comment state</a>.</dd>
2686:
2687: </dl><h5 id="comment-end-state"><span class="secno">9.2.4.22 </span><dfn>Comment end state</dfn></h5>
2688:
2689: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2690:
2691: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2692: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2693: state</a>.</dd>
2694:
2695: <dt>U+002D HYPHEN-MINUS (-)</dt>
2696: <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
2697: (-) character to the comment token's data. Stay in the
2698: <a href="#comment-end-state">comment end state</a>.</dd>
2699:
2700: <dt>U+0009 CHARACTER TABULATION</dt>
2701: <dt>U+000A LINE FEED (LF)</dt>
2702: <dt>U+000C FORM FEED (FF)</dt>
2703: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2704: <dt>U+0020 SPACE</dt>
2705: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
2706: characters and the input character to the comment token's
2707: data. Switch to the <a href="#comment-end-space-state">comment end space state</a>.</dd>
2708:
2709: <dt>U+0021 EXCLAMATION MARK (!)</dt>
2710: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
2711: state</a>.</dd>
2712:
2713: <dt>EOF</dt>
2714: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2715: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
2716: security reasons: otherwise, hostile user could put a <script> in
2717: a comment e.g. in a blog comment and then DOS the server so that
2718: the end tag isn't read, and then the commented <script> tag would
2719: be treated as live code -->
2720:
2721: <dt>Anything else</dt>
2722: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
2723: characters and the input character to the comment token's
2724: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
2725:
2726: </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.23 </span><dfn>Comment end bang state</dfn></h5>
2727:
2728: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2729:
2730: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2731: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2732: state</a>.</dd>
2733:
2734: <dt>U+002D HYPHEN-MINUS (-)</dt>
2735: <dd>Append two U+002D HYPHEN-MINUS (-) characters and a U+0021
2736: EXCLAMATION MARK (!) character to the comment token's data. Switch
2737: to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
2738:
2739: <dt>EOF</dt>
2740: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2741: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
2742: comment in comment end state -->
2743:
2744: <dt>Anything else</dt>
2745: <dd>Append two U+002D HYPHEN-MINUS (-) characters, a U+0021
2746: EXCLAMATION MARK (!) character, and the input character to the
2747: comment token's data. Switch to the <a href="#comment-state">comment
2748: state</a>.</dd>
2749:
2750: </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.24 </span><dfn>Comment end space state</dfn></h5>
2751:
2752: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2753:
2754: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2755: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2756: state</a>.</dd>
2757:
2758: <dt>U+002D HYPHEN-MINUS (-)</dt>
2759: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
2760:
2761: <dt>U+0009 CHARACTER TABULATION</dt>
2762: <dt>U+000A LINE FEED (LF)</dt>
2763: <dt>U+000C FORM FEED (FF)</dt>
2764: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2765: <dt>U+0020 SPACE</dt>
2766: <dd>Append the input character to the comment token's data. Stay in
2767: the <a href="#comment-end-space-state">comment end space state</a>.</dd>
2768:
2769: <dt>EOF</dt>
2770: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2771: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
2772: comment in comment end state -->
2773:
2774: <dt>Anything else</dt>
2775: <dd>Append the input character to the comment token's data. Switch
2776: to the <a href="#comment-state">comment state</a>.</dd>
2777:
2778: </dl><h5 id="doctype-state"><span class="secno">9.2.4.25 </span><dfn>DOCTYPE state</dfn></h5>
2779:
2780: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2781:
2782: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2783: <dt>U+000A LINE FEED (LF)</dt>
2784: <dt>U+000C FORM FEED (FF)</dt>
2785: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2786: <dt>U+0020 SPACE</dt>
2787: <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2788:
2789: <dt>EOF</dt>
2790: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2791: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
2792: the EOF character in the <a href="#data-state">data state</a>.</dd>
2793:
2794: <dt>Anything else</dt>
2795: <dd><a href="#parse-error">Parse error</a>. Reconsume the current
2796: character in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2797:
2798: </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.26 </span><dfn>Before DOCTYPE name state</dfn></h5>
2799:
2800: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2801:
2802: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2803: <dt>U+000A LINE FEED (LF)</dt>
2804: <dt>U+000C FORM FEED (FF)</dt>
2805: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2806: <dt>U+0020 SPACE</dt>
2807: <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2808:
2809: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2810: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2811: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
2812: the <a href="#data-state">data state</a>.</dd>
2813:
2814: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2815: <dd>Create a new DOCTYPE token. Set the token's name to the
2816: lowercase version of the input character (add 0x0020 to the
2817: character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
2818: state</a>.</dd>
2819:
2820: <dt>EOF</dt>
2821: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2822: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
2823: the EOF character in the <a href="#data-state">data state</a>.</dd>
2824:
2825: <dt>Anything else</dt>
2826: <dd>Create a new DOCTYPE token. Set the token's name to the
2827: <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
2828: state</a>.</dd>
2829:
2830: </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.27 </span><dfn>DOCTYPE name state</dfn></h5>
2831:
2832: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2833:
2834: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2835: <dt>U+000A LINE FEED (LF)</dt>
2836: <dt>U+000C FORM FEED (FF)</dt>
2837: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2838: <dt>U+0020 SPACE</dt>
2839: <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
2840:
2841: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2842: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
2843: state</a>.</dd>
2844:
2845: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2846: <dd>Append the lowercase version of the input character (add 0x0020
2847: to the character's code point) to the current DOCTYPE token's
2848: name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
2849:
2850: <dt>EOF</dt>
2851: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2852: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2853: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2854:
2855: <dt>Anything else</dt>
2856: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
2857: token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
2858:
2859: </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.28 </span><dfn>After DOCTYPE name state</dfn></h5>
2860:
2861: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2862:
2863: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2864: <dt>U+000A LINE FEED (LF)</dt>
2865: <dt>U+000C FORM FEED (FF)</dt>
2866: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2867: <dt>U+0020 SPACE</dt>
2868: <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
2869:
2870: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2871: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
2872: state</a>.</dd>
2873:
2874: <dt>EOF</dt>
2875: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2876: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2877: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2878:
2879: <dt>Anything else</dt>
2880: <dd>
2881:
2882: <p>If the six characters starting from the <a href="#current-input-character">current input
2883: character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
2884: for the word "PUBLIC", then consume those characters and switch to
2885: the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</p>
2886:
2887: <p>Otherwise, if the six characters starting from the
2888: <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2889: case-insensitive</a> match for the word "SYSTEM", then consume
2890: those characters and switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system
2891: identifier state</a>.</p>
2892:
2893: <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
2894: DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
2895: the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
2896:
2897: </dd>
2898:
2899: </dl><h5 id="before-doctype-public-identifier-state"><span class="secno">9.2.4.29 </span><dfn>Before DOCTYPE public identifier state</dfn></h5>
2900:
2901: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2902:
2903: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2904: <dt>U+000A LINE FEED (LF)</dt>
2905: <dt>U+000C FORM FEED (FF)</dt>
2906: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2907: <dt>U+0020 SPACE</dt>
2908: <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
2909:
2910: <dt>U+0022 QUOTATION MARK (")</dt>
2911: <dd>Set the DOCTYPE token's public identifier to the empty string
2912: (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
2913: (double-quoted) state</a>.</dd>
2914:
2915: <dt>U+0027 APOSTROPHE (')</dt>
2916: <dd>Set the DOCTYPE token's public identifier to the empty string
2917: (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
2918: (single-quoted) state</a>.</dd>
2919:
2920: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2921: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2922: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2923: token. Switch to the <a href="#data-state">data state</a>.</dd>
2924:
2925: <dt>EOF</dt>
2926: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2927: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2928: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2929:
2930: <dt>Anything else</dt>
2931: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2932: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
2933: DOCTYPE state</a>.</dd>
2934:
2935: </dl><h5 id="doctype-public-identifier-double-quoted-state"><span class="secno">9.2.4.30 </span><dfn>DOCTYPE public identifier (double-quoted) state</dfn></h5>
2936:
2937: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2938:
2939: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
2940: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
2941:
2942: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2943: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2944: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2945: token. Switch to the <a href="#data-state">data state</a>.</dd>
2946:
2947: <dt>EOF</dt>
2948: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2949: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2950: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2951:
2952: <dt>Anything else</dt>
2953: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
2954: token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
2955: identifier (double-quoted) state</a>.</dd>
2956:
2957: </dl><h5 id="doctype-public-identifier-single-quoted-state"><span class="secno">9.2.4.31 </span><dfn>DOCTYPE public identifier (single-quoted) state</dfn></h5>
2958:
2959: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2960:
2961: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
2962: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
2963:
2964: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2965: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2966: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2967: token. Switch to the <a href="#data-state">data state</a>.</dd>
2968:
2969: <dt>EOF</dt>
2970: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2971: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2972: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2973:
2974: <dt>Anything else</dt>
2975: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
2976: token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
2977: identifier (single-quoted) state</a>.</dd>
2978:
2979: </dl><h5 id="after-doctype-public-identifier-state"><span class="secno">9.2.4.32 </span><dfn>After DOCTYPE public identifier state</dfn></h5>
2980:
2981: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2982:
2983: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2984: <dt>U+000A LINE FEED (LF)</dt>
2985: <dt>U+000C FORM FEED (FF)</dt>
2986: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2987: <dt>U+0020 SPACE</dt>
2988: <dd>Stay in the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
2989:
2990: <dt>U+0022 QUOTATION MARK (")</dt>
2991: <dd>Set the DOCTYPE token's system identifier to the empty string
2992: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
2993: (double-quoted) state</a>.</dd>
2994:
2995: <dt>U+0027 APOSTROPHE (')</dt>
2996: <dd>Set the DOCTYPE token's system identifier to the empty string
2997: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
2998: (single-quoted) state</a>.</dd>
2999:
3000: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3001: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3002: state</a>.</dd>
3003:
3004: <dt>EOF</dt>
3005: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3006: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3007: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3008:
3009: <dt>Anything else</dt>
3010: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3011: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3012: DOCTYPE state</a>.</dd>
3013:
3014: </dl><h5 id="before-doctype-system-identifier-state"><span class="secno">9.2.4.33 </span><dfn>Before DOCTYPE system identifier state</dfn></h5>
3015:
3016: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3017:
3018: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3019: <dt>U+000A LINE FEED (LF)</dt>
3020: <dt>U+000C FORM FEED (FF)</dt>
3021: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3022: <dt>U+0020 SPACE</dt>
3023: <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
3024:
3025: <dt>U+0022 QUOTATION MARK (")</dt>
3026: <dd>Set the DOCTYPE token's system identifier to the empty string
3027: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
3028: (double-quoted) state</a>.</dd>
3029:
3030: <dt>U+0027 APOSTROPHE (')</dt>
3031: <dd>Set the DOCTYPE token's system identifier to the empty string
3032: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
3033: (single-quoted) state</a>.</dd>
3034:
3035: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3036: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3037: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3038: token. Switch to the <a href="#data-state">data state</a>.</dd>
3039:
3040: <dt>EOF</dt>
3041: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3042: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3043: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3044:
3045: <dt>Anything else</dt>
3046: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3047: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3048: DOCTYPE state</a>.</dd>
3049:
3050: </dl><h5 id="doctype-system-identifier-double-quoted-state"><span class="secno">9.2.4.34 </span><dfn>DOCTYPE system identifier (double-quoted) state</dfn></h5>
3051:
3052: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3053:
3054: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
3055: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
3056:
3057: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3058: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3059: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3060: token. Switch to the <a href="#data-state">data state</a>.</dd>
3061:
3062: <dt>EOF</dt>
3063: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3064: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3065: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3066:
3067: <dt>Anything else</dt>
3068: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3069: token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
3070: identifier (double-quoted) state</a>.</dd>
3071:
3072: </dl><h5 id="doctype-system-identifier-single-quoted-state"><span class="secno">9.2.4.35 </span><dfn>DOCTYPE system identifier (single-quoted) state</dfn></h5>
3073:
3074: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3075:
3076: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
3077: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
3078:
3079: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3080: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3081: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3082: token. Switch to the <a href="#data-state">data state</a>.</dd>
3083:
3084: <dt>EOF</dt>
3085: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3086: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3087: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3088:
3089: <dt>Anything else</dt>
3090: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3091: token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
3092: identifier (single-quoted) state</a>.</dd>
3093:
3094: </dl><h5 id="after-doctype-system-identifier-state"><span class="secno">9.2.4.36 </span><dfn>After DOCTYPE system identifier state</dfn></h5>
3095:
3096: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3097:
3098: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3099: <dt>U+000A LINE FEED (LF)</dt>
3100: <dt>U+000C FORM FEED (FF)</dt>
3101: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3102: <dt>U+0020 SPACE</dt>
3103: <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
3104:
3105: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3106: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3107: state</a>.</dd>
3108:
3109: <dt>EOF</dt>
3110: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3111: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3112: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3113:
3114: <dt>Anything else</dt>
3115: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
3116: state</a>. (This does <em>not</em> set the DOCTYPE token's
3117: <i>force-quirks flag</i> to <i>on</i>.)</dd>
3118:
3119: </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.37 </span><dfn>Bogus DOCTYPE state</dfn></h5>
3120:
3121: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3122:
3123: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
3124: <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
3125: state</a>.</dd>
3126:
3127: <dt>EOF</dt>
3128: <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
3129: <a href="#data-state">data state</a>.</dd>
3130:
3131: <dt>Anything else</dt>
3132: <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
3133:
3134: </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.38 </span><dfn>CDATA section state</dfn></h5>
3135:
3136: <p><i>(This can only happen if the <a href="#content-model-flag">content model
1.91 mike 3137: flag</a> is set to the PCDATA state.)</i></p>
1.1 mike 3138:
3139: <p>Consume every character up to the next occurrence of the three
3140: character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
3141: BRACKET U+003E GREATER-THAN SIGN (<code title="">]]></code>), or the
3142: end of the file (EOF), whichever comes first. Emit a series of
3143: character tokens consisting of all the characters consumed except
3144: the matching three character sequence at the end (if one was found
3145: before the end of the file).</p>
3146:
3147: <p>Switch to the <a href="#data-state">data state</a>.</p>
3148:
3149: <p>If the end of the file was reached, reconsume the EOF
3150: character.</p>
3151:
3152:
3153:
3154: <h5 id="tokenizing-character-references"><span class="secno">9.2.4.39 </span>Tokenizing character references</h5>
3155:
3156: <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
3157: reference</dfn>. This definition is used when parsing character
1.299 mike 3158: references <a href="#character-reference-in-data-state" title="character reference in data state">in
1.1 mike 3159: text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
3160: state">in attributes</a>.</p>
3161:
3162: <p>The behavior depends on the identity of the next character (the
3163: one immediately after the U+0026 AMPERSAND character):</p>
3164:
3165: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3166: <dt>U+000A LINE FEED (LF)</dt>
3167: <dt>U+000C FORM FEED (FF)</dt>
3168: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3169: <dt>U+0020 SPACE</dt>
3170: <dt>U+003C LESS-THAN SIGN</dt>
3171: <dt>U+0026 AMPERSAND</dt>
3172: <dt>EOF</dt>
3173: <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
3174:
3175: <dd>Not a character reference. No characters are consumed, and
3176: nothing is returned. (This is not an error, either.)</dd>
3177:
3178:
3179: <dt>U+0023 NUMBER SIGN (#)</dt>
3180:
3181: <dd>
3182:
3183: <p>Consume the U+0023 NUMBER SIGN.</p>
3184:
3185: <p>The behavior further depends on the character after the U+0023
3186: NUMBER SIGN:</p>
3187:
3188: <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
3189: <dt>U+0058 LATIN CAPITAL LETTER X</dt>
3190:
3191: <dd>
3192:
3193: <p>Consume the X.</p>
3194:
3195: <p>Follow the steps below, but using the range of characters
3196: U+0030 DIGIT ZERO through to U+0039 DIGIT NINE, U+0061 LATIN
3197: SMALL LETTER A through to U+0066 LATIN SMALL LETTER F, and
3198: U+0041 LATIN CAPITAL LETTER A, through to U+0046 LATIN CAPITAL
3199: LETTER F (in other words, 0-9, A-F, a-f).</p>
3200:
3201: <p>When it comes to interpreting the number, interpret it as a
3202: hexadecimal number.</p>
3203:
3204: </dd>
3205:
3206:
3207: <dt>Anything else</dt>
3208:
3209: <dd>
3210:
3211: <p>Follow the steps below, but using the range of characters
3212: U+0030 DIGIT ZERO through to U+0039 DIGIT NINE (i.e. just
3213: 0-9).</p>
3214:
3215: <p>When it comes to interpreting the number, interpret it as a
3216: decimal number.</p>
3217:
3218: </dd>
3219:
3220: </dl><p>Consume as many characters as match the range of characters
3221: given above.</p>
3222:
3223: <p>If no characters match the range, then don't consume any
3224: characters (and unconsume the U+0023 NUMBER SIGN character and, if
3225: appropriate, the X character). This is a <a href="#parse-error">parse
3226: error</a>; nothing is returned.</p>
3227:
3228: <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
3229: that too. If it isn't, there is a <a href="#parse-error">parse
3230: error</a>.</p>
3231:
3232: <p>If one or more characters match the range, then take them all
3233: and interpret the string of characters as a number (either
3234: hexadecimal or decimal as appropriate).</p>
3235:
3236: <p>If that number is one of the numbers in the first column of the
3237: following table, then this is a <a href="#parse-error">parse error</a>. Find the
3238: row with that number in the first column, and return a character
3239: token for the Unicode character given in the second column of that
3240: row.</p>
3241:
3242: <table><thead><tr><th>Number </th><th colspan="2">Unicode character
3243: </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
3244: </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
3245: </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN ('€')
3246: </td></tr><tr><td>0x81 </td><td>U+0081 </td><td><control>
3247: </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK ('‚')
3248: </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK ('ƒ')
3249: </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK ('„')
3250: </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS ('…')
3251: </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER ('†')
3252: </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER ('‡')
3253: </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT ('ˆ')
3254: </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN ('‰')
3255: </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON ('Š')
3256: </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK ('‹')
3257: </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE ('Œ')
3258: </td></tr><tr><td>0x8D </td><td>U+008D </td><td><control>
3259: </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON ('Ž')
3260: </td></tr><tr><td>0x8F </td><td>U+008F </td><td><control>
3261: </td></tr><tr><td>0x90 </td><td>U+0090 </td><td><control>
3262: </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK ('‘')
3263: </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK ('’')
3264: </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK ('“')
3265: </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK ('”')
3266: </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET ('•')
3267: </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH ('–')
3268: </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH ('—')
3269: </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE ('˜')
3270: </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN ('™')
3271: </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON ('š')
3272: </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK ('›')
3273: </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE ('œ')
3274: </td></tr><tr><td>0x9D </td><td>U+009D </td><td><control>
3275: </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON ('ž')
3276: </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS ('Ÿ')
1.315 mike 3277: </td></tr></tbody></table><p>Otherwise, if the number is in the range 0xD800 to 0xDFFF<!--
3278: surrogates not allowed; see the comment in the "preprocessing the
3279: input stream" section for details --> or is greater than 0x10FFFF,
3280: then this is a <a href="#parse-error">parse error</a>. Return a U+FFFD
3281: REPLACEMENT CHARACTER.</p>
1.18 mike 3282:
3283: <p>Otherwise, return a character token for the Unicode character
1.1 mike 3284: whose code point is that number.
3285:
3286: <!-- this is the same as the equivalent list in the input stream
3287: section -->
3288: If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
3289: allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
3290: allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
1.315 mike 3291: 0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xFDD0 to
3292: 0xFDEF, or is one of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF,
3293: 0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE,
3294: 0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF,
3295: 0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE,
3296: 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF,
3297: 0x10FFFE, or 0x10FFFF, then this is a <a href="#parse-error">parse
3298: error</a>.</p>
1.1 mike 3299:
3300: </dd>
3301:
3302:
3303: <dt>Anything else</dt>
3304:
3305: <dd>
3306:
3307: <p>Consume the maximum number of characters possible, with the
3308: consumed characters matching one of the identifiers in the first
3309: column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
3310: <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
3311:
3312: <p>If no match can be made, then this is a <a href="#parse-error">parse
3313: error</a>. No characters are consumed, and nothing is
3314: returned.</p>
3315:
3316: <p>If the last character matched is not a U+003B SEMICOLON (<code title="">;</code>), there is a <a href="#parse-error">parse error</a>.</p>
3317:
3318: <p>If the character reference is being consumed <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value state">as part of an
3319: attribute</a>, and the last character matched is not a U+003B
3320: SEMICOLON (<code title="">;</code>), and the next character is in
3321: the range U+0030 DIGIT ZERO to U+0039 DIGIT NINE, U+0041 LATIN
3322: CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z, or U+0061 LATIN
3323: SMALL LETTER A to U+007A LATIN SMALL LETTER Z, then, for
3324: historical reasons, all the characters that were matched after the
3325: U+0026 AMPERSAND (&) must be unconsumed, and nothing is
3326: returned.</p>
3327:
3328: <p>Otherwise, return a character token for the character
3329: corresponding to the character reference name (as given by the
3330: second column of the <a href="named-character-references.html#named-character-references">named character references</a>
3331: table).</p>
3332:
3333: <div class="example">
3334:
3335: <p>If the markup contains <code title="">I'm &notit; I tell
3336: you</code>, the character reference is parsed as "not", as in,
3337: <code title="">I'm ¬it; I tell you</code>. But if the markup
3338: was <code title="">I'm &notin; I tell you</code>, the
3339: character reference would be parsed as "notin;", resulting in
3340: <code title="">I'm ∉ I tell you</code>.</p>
3341:
3342: </div>
3343:
3344: </dd>
3345:
1.266 mike 3346: </dl></div><div class="impl">
3347:
3348: <h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4>
1.1 mike 3349:
3350: <p>The input to the tree construction stage is a sequence of tokens
3351: from the <a href="#tokenization">tokenization</a> stage. The tree construction
3352: stage is associated with a DOM <code>Document</code> object when a
3353: parser is created. The "output" of this stage consists of
3354: dynamically modifying or extending that document's DOM tree.</p>
3355:
3356: <p>This specification does not define when an interactive user agent
3357: has to render the <code>Document</code> so that it is available to
3358: the user, or when it has to begin accepting user input.</p>
3359:
3360: <p>As each token is emitted from the tokenizer, the user agent must
3361: process the token according to the rules given in the section
3362: corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
3363:
3364: <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
3365: character</dfn> into a node, if that node has a child immediately
3366: before where the character is to be inserted, and that child is a
3367: <code>Text</code> node, and that <code>Text</code> node was the last
3368: node that the parser inserted into the document, then the character
3369: must be appended to that <code>Text</code> node; otherwise, a new
3370: <code>Text</code> node whose data is just that character must be
3371: inserted in the appropriate place.</p>
3372:
3373: <div class="example">
3374:
3375: <p>Here are some sample inputs to the parser and the corresponding
3376: number of text nodes that they result in, assuming a user agent
3377: that executes scripts.</p>
3378:
3379: <table><thead><tr><th>Input </th><th>Number of text nodes
3380: </th></tr></thead><tbody><tr><td><pre>A<script>
3381: var script = document.getElementsByTagName('script')[0];
3382: document.body.removeChild(script);
3383: </script>B</pre>
3384: </td><td>Two adjacent text nodes in the document, containing "A" and "B".
3385: </td></tr><tr><td><pre>A<script>
3386: var text = document.createTextNode('B');
3387: document.body.appendChild(text);
3388: </script>C</pre>
3389: </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
3390: </td></tr><tr><td><pre>A<script>
3391: var text = document.getElementsByTagName('script')[0].firstChild;
3392: text.data = 'B';
3393: document.body.appendChild(text);
3394: </script>B</pre>
3395: </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
3396: </td></tr><tr><td><pre>A<table>B<tr>C</tr>C</table></pre>
3397: </td><td>Three adjacent text nodes before the table, containing "A", "B", and "CC" respectively. (This is caused by <a href="#foster-parent" title="foster parent">foster parenting</a>.)
3398: </td></tr><tr><td><pre>A<table><tr> B</tr> B</table></pre>
3399: </td><td>Two adjacent text nodes before the table, containing "A" and " B B" (space-B-space-B) respectively. (This is caused by <a href="#foster-parent" title="foster parent">foster parenting</a>.)
3400: </td></tr><tr><td><pre>A<table><tr> B</tr> </em>C</table></pre>
3401: </td><td>Three adjacent text nodes before the table, containing "A", " B" (space-B), and "C" respectively, and one text node inside the table (as a child of a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>) with a single space character. (Space characters separated from non-space characters by non-character tokens are not affected by <a href="#foster-parent" title="foster parent">foster parenting</a>, even if those other tokens then get ignored.)
3402: </td></tr></tbody></table></div>
3403:
3404: <p id="mutation-during-parsing">DOM mutation events must not fire
3405: for changes caused by the UA parsing the document. (Conceptually,
3406: the parser is not mutating the DOM, it is constructing it.) This
1.159 mike 3407: includes the parsing of any content inserted using <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code> and <code title="dom-document-writeln"><a href="embedded-content-0.html#dom-document-writeln">document.writeln()</a></code> calls. <a href="references.html#refsDOMEVENTS">[DOMEVENTS]</a></p>
1.1 mike 3408:
3409: <p class="note">Not all of the tag names mentioned below are
3410: conformant tag names in this specification; many are included to
3411: handle legacy content. They still form part of the algorithm that
3412: implementations are required to implement to claim conformance.</p>
3413:
3414: <p class="note">The algorithm described below places no limit on the
3415: depth of the DOM tree generated, or on the length of tag names,
3416: attribute names, attribute values, text nodes, etc. While
3417: implementors are encouraged to avoid arbitrary limits, it is
3418: recognized that <a href="infrastructure.html#hardwareLimitations">practical
3419: concerns</a> will likely force user agents to impose nesting
3420: depths.</p>
3421:
3422:
3423: <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5>
3424:
3425: <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
3426: element for the token">create an element for a token</dfn> in a
3427: particular namespace, the UA must create a node implementing the
3428: interface appropriate for the element type corresponding to the tag
3429: name of the token in the given namespace (as given in the
3430: specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
3431: element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
3432: defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
3433: the tag name being the name of that element, with the node being in
3434: the given namespace, and with the attributes on the node being those
3435: given in the given token.</p>
3436:
3437: <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
3438: namespace</a> that is not defined in this specification is
1.44 mike 3439: <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1 mike 3440: interface is not defined by that namespace's specification must use
3441: the interface <code>Element</code>.</p>
3442:
3443: <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
3444: created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
3445: invoked once the attributes are set. (This initializes the element's
3446: <a href="forms.html#concept-fe-value" title="concept-fe-value">value</a> and <a href="forms.html#concept-fe-checked" title="concept-fe-checked">checkedness</a> based on the element's
3447: attributes.)</p>
3448:
3449: <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
3450: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
3451: for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
3452: append this node to the <a href="#current-node">current node</a>, and push it onto
3453: the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
3454: <a href="#current-node">current node</a>.</p>
3455:
3456: <p>The steps below may also require that the UA insert an HTML
3457: element in a particular place, in which case the UA must follow the
3458: same steps except that it must insert or append the new node in the
3459: location specified instead of appending it to the <a href="#current-node">current
3460: node</a>. (This happens in particular during the parsing of
3461: tables with invalid content.)</p>
3462:
3463: <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
3464: algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
3465: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
3466: and the newly created element doesn't have a <code title="attr-fae-form"><a href="forms.html#attr-fae-form">form</a></code> attribute, the user agent must
3467: <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
3468: created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
3469: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
3470: inserting it wherever it is to be inserted.</p>
3471:
3472: <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
3473: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
3474: for the token</a> in the given namespace, and then append this
3475: node to the <a href="#current-node">current node</a>, and push it onto the
3476: <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
3477: <a href="#current-node">current node</a>. If the newly created element has an <code title="">xmlns</code> attribute in the <a href="#xmlns-namespace">XMLNS namespace</a>
3478: whose value is not exactly the same as the element's namespace, that
3479: is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
3480: element has an <code title="">xmlns:xlink</code> attribute in the
3481: <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
3482: Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
3483:
3484: <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
3485: attributes</dfn> for a token, then, if the token has an attribute
3486: named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
3487:
3488: <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
3489: attributes</dfn> for a token, then, for each attribute on the token
3490: whose attribute name is one of the ones in the first column of the
3491: following table, change the attribute's name to the name given in
3492: the corresponding cell in the second column. (This fixes the case of
3493: SVG attributes that are not all lowercase.)</p>
3494:
3495: <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
3496: </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
3497: </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
3498: </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
3499: </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
3500: </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
3501: </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
3502: </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
3503: </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
3504: </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
3505: </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
3506: </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
3507: </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
3508: </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
3509: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
3510: </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
3511: </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
3512: </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
3513: </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
3514: </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
3515: </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
3516: </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
3517: </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
3518: </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
3519: </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
3520: </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
3521: </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
3522: </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
3523: </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
3524: </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
3525: </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
3526: </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
3527: </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
3528: </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
3529: </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
3530: </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
3531: </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
3532: </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
3533: </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
3534: </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
3535: </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
3536: </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
3537: </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
3538: </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
3539: </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
3540: </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
3541: </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
3542: </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
3543: </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
3544: </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
3545: </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
3546: </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
3547: </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
3548: </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
3549: </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
3550: </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
3551: </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
3552: </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
3553: </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
3554: </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
3555: </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
3556: </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
3557: </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
3558: </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
3559: foreign attributes</dfn> for a token, then, if any of the attributes
3560: on the token match the strings given in the first column of the
3561: following table, let the attribute be a namespaced attribute, with
3562: the prefix being the string given in the corresponding cell in the
3563: second column, the local name being the string given in the
3564: corresponding cell in the third column, and the namespace being the
3565: namespace given in the corresponding cell in the fourth
3566: column. (This fixes the use of namespaced attributes, in particular
3567: <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
3568: the <span>XML namespace</span></a>.)</p>
3569:
3570: <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
3571: </th></tr></thead><tbody><tr><td> <code title="">xlink:actuate</code> </td><td> <code title="">xlink</code> </td><td> <code title="">actuate</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3572: </td></tr><tr><td> <code title="">xlink:arcrole</code> </td><td> <code title="">xlink</code> </td><td> <code title="">arcrole</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3573: </td></tr><tr><td> <code title="">xlink:href</code> </td><td> <code title="">xlink</code> </td><td> <code title="">href</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3574: </td></tr><tr><td> <code title="">xlink:role</code> </td><td> <code title="">xlink</code> </td><td> <code title="">role</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3575: </td></tr><tr><td> <code title="">xlink:show</code> </td><td> <code title="">xlink</code> </td><td> <code title="">show</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3576: </td></tr><tr><td> <code title="">xlink:title</code> </td><td> <code title="">xlink</code> </td><td> <code title="">title</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3577: </td></tr><tr><td> <code title="">xlink:type</code> </td><td> <code title="">xlink</code> </td><td> <code title="">type</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3578: </td></tr><tr><td> <code title="">xml:base</code> </td><td> <code title="">xml</code> </td><td> <code title="">base</code> </td><td> <a href="#xml-namespace">XML namespace</a> <!-- attr-xml-base -->
3579: </td></tr><tr><td> <code title="">xml:lang</code> </td><td> <code title="">xml</code> </td><td> <code title="">lang</code> </td><td> <a href="#xml-namespace">XML namespace</a>
3580: </td></tr><tr><td> <code title="">xml:space</code> </td><td> <code title="">xml</code> </td><td> <code title="">space</code> </td><td> <a href="#xml-namespace">XML namespace</a>
3581: </td></tr><tr><td> <code title="">xmlns</code> </td><td> (none) </td><td> <code title="">xmlns</code> </td><td> <a href="#xmlns-namespace">XMLNS namespace</a>
3582: </td></tr><tr><td> <code title="">xmlns:xlink</code> </td><td> <code title="">xmlns</code> </td><td> <code title="">xlink</code> </td><td> <a href="#xmlns-namespace">XMLNS namespace</a>
1.91 mike 3583: </td></tr></tbody></table><hr><p>The <dfn id="generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</dfn> and the
1.1 mike 3584: <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
3585: following steps. These algorithms are always invoked in response to
3586: a start tag token.</p>
3587:
3588: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
3589:
1.91 mike 3590: <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
3591: text element parsing algorithm</a>, switch the tokenizer's
3592: <a href="#content-model-flag">content model flag</a> to the RAWTEXT state; otherwise the
1.1 mike 3593: algorithm invoked was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing
3594: algorithm</a>, switch the tokenizer's <a href="#content-model-flag">content model
3595: flag</a> to the RCDATA state.</p></li>
3596:
3597: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
3598: <a href="#insertion-mode">insertion mode</a>.</p>
3599:
1.91 mike 3600: </li><li><p>Then, switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
3601: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 3602:
3603: </ol><h5 id="closing-elements-that-have-implied-end-tags"><span class="secno">9.2.5.2 </span>Closing elements that have implied end tags</h5>
3604:
1.305 mike 3605: <!-- <dc> and <ds> are here speculatively for future expansion (they're not defined elements yet) -->
1.1 mike 3606: <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
3607: tags</dfn>, then, while the <a href="#current-node">current node</a> is a
1.305 mike 3608: <code>dc</code> element, a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
3609: <code>ds</code> element, a <code><a href="semantics.html#the-dt-element">dt</a></code> element, an
1.1 mike 3610: <code><a href="semantics.html#the-li-element">li</a></code> element, an <code><a href="forms.html#the-option-element">option</a></code> element, an
3611: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, a <code><a href="semantics.html#the-p-element">p</a></code> element, an
3612: <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element, or an <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element, the UA must
3613: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
3614: elements</a>.</p>
3615:
3616: <p>If a step requires the UA to generate implied end tags but lists
3617: an element to exclude from the process, then the UA must perform the
3618: above steps as if that element was not in the above list.</p>
3619:
3620:
3621: <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5>
3622:
3623: <p>Foster parenting happens when content is misnested in tables.</p>
3624:
3625: <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
3626: parent">foster parented</dfn>, the node <var title="">node</var>
3627: must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
3628:
3629: <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
3630: last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
3631: elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
3632: such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
3633: the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
3634: case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
3635: element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
1.159 mike 3636: <code><a href="semantics.html#the-html-element-0">html</a></code> element). Otherwise, if there is a
1.1 mike 3637: <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
3638: elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
3639: <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
3640: node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
3641: the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
3642: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
3643:
3644: <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
3645: last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
3646: elements</a>, then <var title="">node</var> must be inserted
3647: immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
3648: the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
3649: element</a></i>; otherwise, <var title="">node</var> must be
3650: <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
3651:
3652:
3653:
3654: <h5 id="the-initial-insertion-mode"><span class="secno">9.2.5.4 </span>The "<dfn title="insertion mode: initial">initial</dfn>" insertion mode</h5>
3655:
3656: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
3657: mode: initial">initial</a>", tokens must be handled as follows:</p>
3658:
3659: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
3660: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3661: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3662: <dd>
3663: <p>Ignore the token.</p>
3664: </dd>
3665:
3666: <dt>A comment token</dt>
3667: <dd>
3668: <p>Append a <code>Comment</code> node to the <code>Document</code>
3669: object with the <code title="">data</code> attribute set to the
3670: data given in the comment token.</p>
3671: </dd>
3672:
3673: <dt>A DOCTYPE token</dt>
3674: <dd>
3675:
3676: <p>If the DOCTYPE token's name is not a
3677: <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string "<code title="">html</code>", or the token's public identifier is not
3678: missing, or the token's system identifier is neither missing nor a
3679: <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
3680: "<code>about:legacy-compat</code>", and none of the sets of
3681: conditions in the following list are matched, then there is a
3682: <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
3683: following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
3684: permitted DOCTYPE</dfn>.</p>
3685:
3686: <ul><!-- only things that trigger no-quirks mode and were valid in
3687: some other spec are allowed in this list --><li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3688: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3689: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD HTML 4.0//EN</code>", and the
3690: token's system identifier is either missing or the
3691: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
3692:
3693: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3694: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3695: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD HTML 4.01//EN</code>", and the
3696: token's system identifier is either missing or the
3697: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
3698:
3699: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3700: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3701: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD XHTML 1.0 Strict//EN</code>",
3702: and the token's system identifier is the
3703: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
3704:
3705: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3706: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3707: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD XHTML 1.1//EN</code>", and the
3708: token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
3709: string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
3710:
3711: </ul><p>Conformance checkers may, based on the values (including
3712: presence or lack thereof) of the DOCTYPE token's name, public
3713: identifier, or system identifier, switch to a conformance checking
3714: mode for another language (e.g. based on the DOCTYPE token a
3715: conformance checker could recognize that the document is an
1.183 mike 3716: HTML4-era document, and defer to an HTML4 conformance
1.1 mike 3717: checker.)</p>
3718:
3719: <p>Append a <code>DocumentType</code> node to the
3720: <code>Document</code> node, with the <code title="">name</code>
3721: attribute set to the name given in the DOCTYPE token, or the empty
3722: string if the name was missing; the <code title="">publicId</code>
3723: attribute set to the public identifier given in the DOCTYPE token,
3724: or the empty string if the public identifier was missing; the
3725: <code title="">systemId</code> attribute set to the system
3726: identifier given in the DOCTYPE token, or the empty string if the
3727: system identifier was missing; and the other attributes specific
3728: to <code>DocumentType</code> objects set to null and empty lists
3729: as appropriate. Associate the <code>DocumentType</code> node with
3730: the <code>Document</code> object so that it is returned as the
3731: value of the <code title="">doctype</code> attribute of the
3732: <code>Document</code> object.</p>
3733:
3734: <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
3735: one of the conditions in the following list, then set the
3736: <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
3737:
3738: <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
3739: <li> The name is set to anything other than "<code title="">HTML</code>". </li>
3740: <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
3741: <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
3742: <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
3743: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
3744: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
3745: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
3746: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
3747: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
3748: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
3749: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
3750: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
3751: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
3752: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
3753: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
3754: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
3755: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
3756: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
3757: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
3758: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
3759: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
3760: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
3761: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
3762: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
3763: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
3764: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
3765: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
3766: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
3767: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
3768: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
3769: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
3770: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
3771: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
3772: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
3773: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
3774: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
3775: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
3776: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
3777: <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
3778: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
3779: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
3780: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
3781: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
3782: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
3783: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
3784: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
3785: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
3786: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
3787: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
3788: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
3789: <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
3790: <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
3791: <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
3792: <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
3793: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
3794: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
3795: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
3796: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
3797: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
3798: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
3799: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
3800: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
3801: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
3802: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
3803: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
3804: <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
3805: <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
3806: <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
3807: <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
3808: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
3809: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
3810: <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
3811: <li> The public identifier is set to: "<code title="">HTML</code>" </li>
3812: <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
3813: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
3814: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
3815: </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
3816: in the following list, then set the <code>Document</code> to
3817: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
3818:
3819: <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
3820: <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
3821: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
3822: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
3823: </ul><p>The name, system identifier, and public identifier strings must
3824: be compared to the values given in the lists above in an
3825: <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
3826: whose value is the empty string is not considered missing for the
3827: purposes of the conditions above.</p>
3828:
3829: <p>Then, switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>".</p>
3830:
3831: </dd>
3832:
3833: <dt>Anything else</dt>
3834: <dd>
3835:
3836: <p><a href="#parse-error">Parse error</a>.</p>
3837:
3838: <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
3839:
3840: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>", then
3841: reprocess the current token.</p>
3842:
3843: </dd>
3844:
3845: </dl><h5 id="the-before-html-insertion-mode"><span class="secno">9.2.5.5 </span>The "<dfn title="insertion mode: before html">before html</dfn>" insertion mode</h5>
3846:
3847: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
3848: mode: before html">before html</a>", tokens must be handled as follows:</p>
3849:
3850: <dl class="switch"><dt>A DOCTYPE token</dt>
3851: <dd>
3852: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3853: </dd>
3854:
3855: <dt>A comment token</dt>
3856: <dd>
3857: <p>Append a <code>Comment</code> node to the <code>Document</code>
3858: object with the <code title="">data</code> attribute set to the
3859: data given in the comment token.</p>
3860: </dd>
3861:
3862: <dt>A character token that is one of U+0009 CHARACTER
3863: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3864: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3865: <dd>
3866: <p>Ignore the token.</p>
3867: </dd>
3868:
3869: <dt>A start tag whose tag name is "html"</dt>
3870: <dd>
3871:
3872: <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
3873: namespace</a>. Append it to the <code>Document</code>
3874: object. Put this element in the <a href="#stack-of-open-elements">stack of open
3875: elements</a>.</p>
3876:
3877: <p id="parser-appcache">If the <code>Document</code> is being
3878: loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
3879: <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
3880: has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
3881: then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
3882: attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
3883: created element, and if that is successful, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
1.29 mike 3884: algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
3885: any <a href="infrastructure.html#url-fragment" title="url-fragment"><fragment></a> component
3886: removed; otherwise, if there is no such attribute or resolving it
3887: fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
3888: cache selection algorithm</a> with no manifest. The algorithm
3889: must be passed the <code>Document</code> object.</p>
1.1 mike 3890:
3891: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>".</p>
3892:
3893: </dd>
3894:
3895: <dt>Anything else</dt>
3896: <dd>
3897:
1.159 mike 3898: <p>Create an <code><a href="semantics.html#the-html-element-0">html</a></code> element. Append it to the
1.1 mike 3899: <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
3900: of open elements</a>.</p>
3901:
3902: <p>If the <code>Document</code> is being loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a <a href="browsers.html#browsing-context">browsing
3903: context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
3904: algorithm</a> with no manifest, passing it the
3905: <code>Document</code> object.</p>
3906:
3907: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>", then
3908: reprocess the current token.</p>
3909:
3910: <p class="XXX">Should probably make end tags be ignored, so
3911: that "</head><!-- --><html>" puts the comment before the
3912: root node (or should we?)</p>
3913:
3914: </dd>
3915:
3916: </dl><p>The root element can end up being removed from the
3917: <code>Document</code> object, e.g. by scripts; nothing in particular
3918: happens in such cases, content continues being appended to the nodes
3919: as described in the next section.</p>
3920:
3921:
3922: <h5 id="the-before-head-insertion-mode"><span class="secno">9.2.5.6 </span>The "<dfn title="insertion mode: before head">before head</dfn>" insertion mode</h5>
3923:
3924: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
3925: mode: before head">before head</a>", tokens must be handled as follows:</p>
3926:
3927: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
3928: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3929: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3930: <dd>
3931: <p>Ignore the token.</p> <!-- :-( -->
3932: </dd>
3933:
3934: <dt>A comment token</dt>
3935: <dd>
3936: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
3937: node</a> with the <code title="">data</code> attribute set to
3938: the data given in the comment token.</p>
3939: </dd>
3940:
3941: <dt>A DOCTYPE token</dt>
3942: <dd>
3943: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3944: </dd>
3945:
3946: <dt>A start tag whose tag name is "html"</dt>
3947: <dd>
3948: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
3949: mode</a>.</p>
3950: </dd>
3951:
3952: <dt>A start tag whose tag name is "head"</dt>
3953: <dd>
3954:
3955: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
3956:
3957: <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
1.159 mike 3958: to the newly created <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 3959:
3960: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>".</p>
3961:
3962: </dd>
3963:
3964: <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
3965: <dd>
3966:
3967: <p>Act as if a start tag token with the tag name "head" and no
3968: attributes had been seen, then reprocess the current token.</p>
3969:
3970: </dd>
3971:
3972: <dt>Any other end tag</dt>
3973: <dd>
3974:
3975: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3976:
3977: </dd>
3978:
3979: <dt>Anything else</dt>
3980: <dd>
3981:
3982: <p>Act as if a start tag token with the tag name "head" and no
3983: attributes had been seen, then reprocess the current
3984: token.</p>
3985:
3986: </dd>
3987:
3988: </dl><h5 id="parsing-main-inhead"><span class="secno">9.2.5.7 </span>The "<dfn title="insertion mode: in head">in head</dfn>" insertion mode</h5>
3989:
3990: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
3991: mode: in head">in head</a>", tokens must be handled as follows:</p>
3992:
3993: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
3994: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3995: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3996: <dd>
3997: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
3998: the <a href="#current-node">current node</a>.</p>
3999: </dd>
4000:
4001: <dt>A comment token</dt>
4002: <dd>
4003: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4004: node</a> with the <code title="">data</code> attribute set to
4005: the data given in the comment token.</p>
4006: </dd>
4007:
4008: <dt>A DOCTYPE token</dt>
4009: <dd>
4010: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4011: </dd>
4012:
4013: <dt>A start tag whose tag name is "html"</dt>
4014: <dd>
4015: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
4016: mode</a>.</p>
4017: </dd>
4018:
4019: <dt>A start tag whose tag name is one of: "base", "command",
4020: "link"</dt>
4021: <dd>
4022:
4023: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4024: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4025: elements</a>.</p>
4026:
4027: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4028: token's <i>self-closing flag</i></a>, if it is set.</p>
4029:
4030: </dd>
4031:
4032: <dt>A start tag whose tag name is "meta"</dt>
4033: <dd>
4034:
4035: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4036: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4037: elements</a>.</p>
4038:
4039: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4040: token's <i>self-closing flag</i></a>, if it is set.</p>
4041:
4042: <p id="meta-charset-during-parse">If the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute, and its
4043: value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
4044: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
4045: encoding</a> to the encoding given by the value of the
4046: <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
4047:
4048: <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
4049: applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
4050: Content-Type</a> to its value returns a supported encoding
4051: <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
4052: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
4053: encoding</a> to the encoding <var title="">encoding</var>.</p>
4054:
4055: </dd>
4056:
4057: <dt>A start tag whose tag name is "title"</dt>
4058: <dd>
4059: <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
4060: </dd>
4061:
4062: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
4063: <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
4064: <dd>
1.91 mike 4065: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 4066: </dd>
4067:
4068: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
4069: <dd>
4070:
4071: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4072:
4073: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
4074: noscript</a>".</p>
4075:
4076: </dd>
4077:
4078: <dt id="scriptTag">A start tag whose tag name is "script"</dt>
4079: <dd>
4080:
4081: <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
4082: <a href="#html-namespace-0">HTML namespace</a>.</p></li>
4083:
4084: <li>
4085:
4086: <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
4087:
4088: <p class="note">This ensures that, if the script is external,
1.159 mike 4089: any <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>
1.1 mike 4090: calls in the script will execute in-line, instead of blowing the
4091: document away, as would happen in most other cases. It also
4092: prevents the script from executing until the end tag is
4093: seen.</p>
4094:
4095: </li>
4096:
4097: <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
4098: fragment parsing algorithm</a>, then mark the
4099: <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
4100: executed"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
4101:
4102: <li><p>Append the new element to the <a href="#current-node">current node</a>
4103: and push it onto the <a href="#stack-of-open-elements">stack of open
4104: elements</a>.</p></li>
4105:
4106: <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
1.91 mike 4107: the RAWTEXT state.</p></li>
1.1 mike 4108:
4109: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
4110: <a href="#insertion-mode">insertion mode</a>.</p>
4111:
1.91 mike 4112: </li><li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
4113: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 4114:
4115: </ol></dd>
4116:
4117: <dt>An end tag whose tag name is "head"</dt>
4118: <dd>
4119:
4120: <p>Pop the <a href="#current-node">current node</a> (which will be the
1.159 mike 4121: <code><a href="semantics.html#the-head-element-0">head</a></code> element) off the <a href="#stack-of-open-elements">stack of open
1.1 mike 4122: elements</a>.</p>
4123:
4124: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-after-head-insertion-mode" title="insertion mode: after head">after head</a>".</p>
4125:
4126: </dd>
4127:
4128: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
4129: <dd>
4130: <p>Act as described in the "anything else" entry below.</p>
4131: </dd>
4132:
4133: <dt>A start tag whose tag name is "head"</dt>
4134: <dt>Any other end tag</dt>
4135: <dd>
4136: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4137: </dd>
4138:
4139: <dt>Anything else</dt>
4140: <dd>
4141:
4142: <!-- can't get here with an EOF and a fragment case -->
4143:
4144: <p>Act as if an end tag token with the tag name "head" had
4145: been seen, and reprocess the current token.</p>
4146:
4147: <p class="XXX">In certain UAs, <a href="https://bugzilla.mozilla.org/attachment.cgi?id=180157&action=view">some
4148: elements</a> don't trigger the "in body" mode straight away,
4149: but instead get put into the head. Do we want to copy
4150: that?</p>
4151:
4152: </dd>
4153:
4154: </dl><h5 id="parsing-main-inheadnoscript"><span class="secno">9.2.5.8 </span>The "<dfn title="insertion mode: in head noscript">in head noscript</dfn>" insertion mode</h5>
4155:
4156: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
4157: mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
4158:
4159: <dl class="switch"><dt>A DOCTYPE token</dt>
4160: <dd>
4161: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4162: </dd>
4163:
4164: <dt>A start tag whose tag name is "html"</dt>
4165: <dd>
4166: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
4167: mode</a>.</p>
4168: </dd>
4169:
4170: <dt>An end tag whose tag name is "noscript"</dt>
4171: <dd>
4172:
4173: <p>Pop the <a href="#current-node">current node</a> (which will be a
4174: <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
4175: elements</a>; the new <a href="#current-node">current node</a> will be a
1.159 mike 4176: <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 4177:
4178: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>".</p>
4179:
4180: </dd>
4181:
4182: <dt>A character token that is one of U+0009 CHARACTER
4183: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4184: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4185: <dt>A comment token</dt>
4186: <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
4187: <dd>
4188: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
4189: mode</a>.</p>
4190: </dd>
4191:
4192: <dt>An end tag whose tag name is "br"</dt>
4193: <dd>
4194: <p>Act as described in the "anything else" entry below.</p>
4195: </dd>
4196:
4197: <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
4198: <dt>Any other end tag</dt>
4199: <dd>
4200: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4201: </dd>
4202:
4203: <dt>Anything else</dt>
4204: <dd>
4205:
4206: <!-- can't get here with an EOF and a fragment case -->
4207:
4208: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
4209: name "noscript" had been seen and reprocess the current
4210: token.</p>
4211:
4212: </dd>
4213:
4214: </dl><h5 id="the-after-head-insertion-mode"><span class="secno">9.2.5.9 </span>The "<dfn title="insertion mode: after head">after head</dfn>" insertion mode</h5>
4215:
4216: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
4217: mode: after head">after head</a>", tokens must be handled as follows:</p>
4218:
4219: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4220: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4221: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4222: <dd>
4223: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
4224: the <a href="#current-node">current node</a>.</p>
4225: </dd>
4226:
4227: <dt>A comment token</dt>
4228: <dd>
4229: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4230: node</a> with the <code title="">data</code> attribute set to
4231: the data given in the comment token.</p>
4232: </dd>
4233:
4234: <dt>A DOCTYPE token</dt>
4235: <dd>
4236: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4237: </dd>
4238:
4239: <dt>A start tag whose tag name is "html"</dt>
4240: <dd>
4241: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
4242: mode</a>.</p>
4243: </dd>
4244:
4245: <dt>A start tag whose tag name is "body"</dt>
4246: <dd>
4247:
4248: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4249:
4250: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4251:
4252: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>".</p>
4253:
4254: </dd>
4255:
4256: <dt>A start tag whose tag name is "frameset"</dt>
4257: <dd>
4258:
4259: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4260:
4261: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>".</p>
4262:
4263: </dd>
4264:
4265: <dt>A start tag token whose tag name is one of: "base", "link",
4266: "meta", "noframes", "script", "style", "title"</dt>
4267: <dd>
4268:
4269: <p><a href="#parse-error">Parse error</a>.</p>
4270:
4271: <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
4272: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
4273:
4274: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
4275: mode</a>.</p>
4276:
4277: <p>Remove the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> from the <a href="#stack-of-open-elements">stack
4278: of open elements</a>.</p>
4279:
4280: <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
4281: pointer</a> cannot be null at this point.</p>
4282:
4283: </dd>
4284:
4285: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
4286: <dd>
4287: <p>Act as described in the "anything else" entry below.</p>
4288: </dd>
4289:
4290: <dt>A start tag whose tag name is "head"</dt>
4291: <dt>Any other end tag</dt>
4292: <dd>
4293: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4294: </dd>
4295:
4296: <dt>Anything else</dt>
4297: <dd>
4298: <p>Act as if a start tag token with the tag name "body" and no
4299: attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
4300: flag</a> back to "ok", and then reprocess the current
4301: token.</p>
4302: </dd>
4303:
4304: </dl><h5 id="parsing-main-inbody"><span class="secno">9.2.5.10 </span>The "<dfn title="insertion mode: in body">in body</dfn>" insertion mode</h5>
4305:
4306: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
4307: mode: in body">in body</a>", tokens must be handled as follows:</p>
4308:
4309: <dl class="switch"><dt>A character token</dt>
4310: <dd>
4311:
4312: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4313: any.</p>
4314:
4315: <p><a href="#insert-a-character" title="insert a character">Insert the token's
4316: character</a> into the <a href="#current-node">current node</a>.</p>
4317:
4318: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
4319: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
4320: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
4321: flag</a> to "not ok".</p>
4322:
4323: </dd>
4324:
4325: <dt>A comment token</dt>
4326: <dd>
4327: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4328: node</a> with the <code title="">data</code> attribute set to
4329: the data given in the comment token.</p>
4330: </dd>
4331:
4332: <dt>A DOCTYPE token</dt>
4333: <dd>
4334: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4335: </dd>
4336:
4337: <dt>A start tag whose tag name is "html"</dt>
4338: <dd>
4339: <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
4340: check to see if the attribute is already present on the top
4341: element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
4342: add the attribute and its corresponding value to that element.</p>
4343: </dd>
4344:
4345: <dt>A start tag token whose tag name is one of: "base", "command",
4346: "link", "meta", "noframes", "script", "style", "title"</dt>
4347: <dd>
4348: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
4349: mode</a>.</p>
4350: </dd>
4351:
4352: <dt>A start tag whose tag name is "body"</dt>
4353: <dd>
4354:
4355: <p><a href="#parse-error">Parse error</a>.</p>
4356:
4357: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159 mike 4358: elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1 mike 4359: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
4360: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
4361:
4362: <p>Otherwise, for each attribute on the token, check to see if
1.159 mike 4363: the attribute is already present on the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 4364: element (the second element) on the <a href="#stack-of-open-elements">stack of open
4365: elements</a>. If it is not, add the attribute and its
4366: corresponding value to that element.</p>
4367:
4368: </dd>
4369:
4370: <dt>A start tag whose tag name is "frameset"</dt>
4371: <dd>
4372:
4373: <p><a href="#parse-error">Parse error</a>.</p>
4374:
4375: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159 mike 4376: elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1 mike 4377: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
4378: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
4379:
4380: <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
4381: the token.</p>
4382:
4383: <p>Otherwise, run the following steps:</p>
4384:
4385: <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
4386: elements</a> from its parent node, if it has one.</p></li>
4387:
4388: <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
4389: open elements</a>, from the <a href="#current-node">current node</a> up to,
1.159 mike 4390: but not including, the root <code><a href="semantics.html#the-html-element-0">html</a></code> element.</p>
1.1 mike 4391:
4392: </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
4393: token.</p></li>
4394:
4395: <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>".</p>
4396:
4397: </li></ol></dd>
4398:
4399: <dt>An end-of-file token</dt>
4400: <dd>
4401:
4402: <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
1.305 mike 4403: that is not either a <code>dc</code> element, a <code><a href="semantics.html#the-dd-element">dd</a></code>
4404: element, a <code>ds</code> element, a <code><a href="semantics.html#the-dt-element">dt</a></code> element, an
4405: <code><a href="semantics.html#the-li-element">li</a></code> element, a <code><a href="semantics.html#the-p-element">p</a></code> element, a
1.1 mike 4406: <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, a <code><a href="tabular-data.html#the-td-element">td</a></code> element, a
4407: <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element, a <code><a href="tabular-data.html#the-th-element">th</a></code> element, a
4408: <code><a href="tabular-data.html#the-thead-element">thead</a></code> element, a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the
1.159 mike 4409: <code><a href="semantics.html#the-body-element-0">body</a></code> element, or the <code><a href="semantics.html#the-html-element-0">html</a></code> element, then
1.1 mike 4410: this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
1.305 mike 4411: fragment cases) --> <!-- <dc> and <ds> are there speculatively -->
1.1 mike 4412:
4413: <p><a href="#stop-parsing">Stop parsing</a>.</p>
4414:
4415: </dd>
4416:
4417: <dt>An end tag whose tag name is "body"</dt>
4418: <dd>
4419:
4420: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-scope" title="has an element in scope">have a <code>body</code> element
4421: in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
4422: token.</p>
4423:
4424: <!-- if we get here, the insertion mode here is forcibly "in
4425: body". -->
4426:
4427: <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
1.305 mike 4428: elements</a> that is not either a <code>dc</code> element, a
4429: <code><a href="semantics.html#the-dd-element">dd</a></code> element, a <code>ds</code> element, a
1.1 mike 4430: <code><a href="semantics.html#the-dt-element">dt</a></code> element, an <code><a href="semantics.html#the-li-element">li</a></code> element, an
4431: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, an <code><a href="forms.html#the-option-element">option</a></code> element, a
4432: <code><a href="semantics.html#the-p-element">p</a></code> element, an <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element, an
4433: <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element, a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, a
4434: <code><a href="tabular-data.html#the-td-element">td</a></code> element, a <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element, a
4435: <code><a href="tabular-data.html#the-th-element">th</a></code> element, a <code><a href="tabular-data.html#the-thead-element">thead</a></code> element, a
1.159 mike 4436: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the <code><a href="semantics.html#the-body-element-0">body</a></code> element, or the
4437: <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1 mike 4438: error</a>.</p> <!-- (some of those are fragment cases, e.g. for
4439: <tbody> you'd have hit the first paragraph since the <body>
1.305 mike 4440: wouldn't be in scope, unless it was a fragment case) --> <!-- <dc>
4441: and <ds> are there speculatively -->
1.1 mike 4442:
4443: <!-- If we ever change the frameset-ok flag to an insertion mode,
4444: then we'd have to somehow keep track of its state when we switch
4445: to after-body. -->
4446:
4447: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterbody" title="insertion mode: after body">after body</a>".</p>
4448:
4449: </dd>
4450:
4451: <dt>An end tag whose tag name is "html"</dt>
4452: <dd>
4453:
4454: <p>Act as if an end tag with tag name "body" had been seen,
4455: then, if that token wasn't ignored, reprocess the current
4456: token.</p>
4457:
4458: <p class="note">The fake end tag token here can only be
4459: ignored in the <a href="#fragment-case">fragment case</a>.</p>
4460:
4461: </dd>
4462:
4463: <!-- start tags for non-phrasing flow content elements -->
4464:
4465: <!-- the normal ones -->
4466: <dt>A start tag whose tag name is one of: "address", "article",
1.86 mike 4467: "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305 mike 4468: "details", "dir", "div", "dl", "fieldset", "figure", "footer",
4469: "header", "hgroup", "menu", "nav", "ol", "p", "section", "ul"</dt>
1.1 mike 4470: <dd>
4471:
4472: <!-- As of May 2008 this doesn't match any browser exactly, but is
4473: as close to what IE does as I can get without doing the non-tree
4474: DOM nonsense, and thus should actually afford better compatibility
4475: when implemented by the other browsers. -->
4476:
4477: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4478: an element in scope">has a <code>p</code> element in
4479: scope</a>, then act as if an end tag with the tag name
4480: "p" had been seen.</p>
4481:
4482: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4483:
4484: </dd>
4485:
4486: <!-- as normal, but close h1-h6 if it's the current node -->
4487: <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
4488: "h5", "h6"</dt>
4489: <dd>
4490:
4491: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4492: an element in scope">has a <code>p</code> element in
4493: scope</a>, then act as if an end tag with the tag name
4494: "p" had been seen.</p>
4495:
4496: <p>If the <a href="#current-node">current node</a> is an element whose tag name
4497: is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
4498: <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
4499: the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
4500: <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
4501:
4502: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4503:
4504: </dd>
4505:
4506: <!-- as normal, but drops leading newline -->
4507: <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
4508: <dd>
4509:
4510: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4511: an element in scope">has a <code>p</code> element in
4512: scope</a>, then act as if an end tag with the tag name
4513: "p" had been seen.</p>
4514:
4515: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4516:
4517: <p>If the next token is a U+000A LINE FEED (LF) character
4518: token, then ignore that token and move on to the next
4519: one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
4520: ignored as an authoring convenience.)</p>
4521:
4522: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4523:
4524: </dd>
4525:
4526: <!-- as normal, but interacts with the form element pointer -->
4527: <dt>A start tag whose tag name is "form"</dt>
4528: <dd>
4529:
4530: <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
4531: pointer</a> is not null, then this is a <a href="#parse-error">parse
4532: error</a>; ignore the token.</p>
4533:
4534: <p>Otherwise:</p>
4535:
4536: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4537: an element in scope">has a <code>p</code> element in
4538: scope</a>, then act as if an end tag with the tag name
4539: "p" had been seen.</p>
4540:
4541: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
4542: <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
4543: point to the element created.</p>
4544:
4545: </dd>
4546:
4547: <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
4548: <dt>A start tag whose tag name is "li"</dt>
4549: <dd>
4550:
4551: <p>Run the following algorithm:</p>
4552:
4553: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
4554:
4555: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
4556: node</a> (the bottommost node of the stack).</p></li>
4557:
4558: <li><p>If <var title="">node</var> is an <code><a href="semantics.html#the-li-element">li</a></code> element,
4559: then act as if an end tag with the tag name "li" had
4560: been seen, then jump to the last step.</p></li>
4561:
4562: <li><p><i>Loop</i>: If <var title="">node</var> is not in the
4563: <a href="#formatting">formatting</a> category, and is not in the
4564: <a href="#phrasing">phrasing</a> category, and is not an
1.306 mike 4565: <code><a href="semantics.html#the-address-element">address</a></code>, <code><a href="semantics.html#the-div-element">div</a></code>, or <code><a href="semantics.html#the-p-element">p</a></code>
1.1 mike 4566: element, then jump to the last step.</p></li> <!-- an element
4567: <foo> is in this list if the following markup:
4568:
4569: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
4570:
4571: ...results in the second <li> not being (in any way) a descendant
4572: of the first <li>, or if <foo> is a formatting element that gets
4573: reopened later. -->
4574:
4575: <li><p>Otherwise, set <var title="">node</var> to the previous
4576: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
4577: the step labeled <i>loop</i>.</p></li>
4578:
4579: <li>
4580:
4581: <p>This is the last step.</p>
4582:
4583: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4584: an element in scope">has a <code>p</code> element in
4585: scope</a>, then act as if an end tag with the tag name
4586: "p" had been seen.</p>
4587:
4588: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
4589: token.</p>
4590:
4591: </li>
4592:
4593: </ol></dd>
4594:
4595: <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases -->
1.305 mike 4596: <!-- <dc> and <ds> are here speculatively for future expansion (they're not defined elements yet) -->
4597: <dt>A start tag whose tag name is one of: "dc", "dd", "ds", "dt"</dt>
1.1 mike 4598: <dd>
4599:
4600: <p>Run the following algorithm:</p>
4601:
4602: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
4603:
4604: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
4605: node</a> (the bottommost node of the stack).</p></li>
4606:
4607: <li><p><i>Loop</i>: If <var title="">node</var> is a
1.305 mike 4608: <code>dc</code>, <code><a href="semantics.html#the-dd-element">dd</a></code>, <code>ds</code>, or
4609: <code><a href="semantics.html#the-dt-element">dt</a></code> element, then act as if an end tag with the same
4610: tag name as <var title="">node</var> had been seen, then jump to
4611: the last step.</p></li>
1.1 mike 4612:
4613: <li><p>If <var title="">node</var> is not in the
4614: <a href="#formatting">formatting</a> category, and is not in the
4615: <a href="#phrasing">phrasing</a> category, and is not an
1.306 mike 4616: <code><a href="semantics.html#the-address-element">address</a></code>, <code><a href="semantics.html#the-div-element">div</a></code>, or <code><a href="semantics.html#the-p-element">p</a></code>
1.1 mike 4617: element, then jump to the last step.</p></li> <!-- an element
4618: <foo> is in this list if the following markup:
4619:
4620: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
4621:
4622: ...results in the second <dt> not being (in any way) a descendant
4623: of the first <dt>, or if <foo> is a formatting element that gets
4624: reopened later. -->
4625:
4626: <li><p>Otherwise, set <var title="">node</var> to the previous
4627: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
4628: the step labeled <i>loop</i>.</p></li>
4629:
4630: <li>
4631:
4632: <p>This is the last step.</p>
4633:
4634: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4635: an element in scope">has a <code>p</code> element in
4636: scope</a>, then act as if an end tag with the tag name
4637: "p" had been seen.</p>
4638:
4639: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
4640: token.</p>
4641:
4642: </li>
4643:
4644: </ol></dd>
4645:
4646: <!-- same as normal, but effectively ends parsing -->
4647: <dt>A start tag whose tag name is "plaintext"</dt>
4648: <dd>
4649:
4650: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4651: an element in scope">has a <code>p</code> element in
4652: scope</a>, then act as if an end tag with the tag name
4653: "p" had been seen.</p>
4654:
4655: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4656:
4657: <p>Switch the <a href="#content-model-flag">content model flag</a> to the PLAINTEXT
4658: state.</p>
4659:
4660: <p class="note">Once a start tag with the tag name "plaintext"
4661: has been seen, that will be the last token ever seen other
4662: than character tokens (and the end-of-file token), because
4663: there is no way to switch the <a href="#content-model-flag">content model flag</a>
4664: out of the PLAINTEXT state.</p>
4665:
4666: </dd>
4667:
4668: <!-- end tags for non-phrasing flow content elements -->
4669:
4670: <!-- the normal ones -->
4671: <dt>An end tag whose tag name is one of: "address", "article",
1.86 mike 4672: "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305 mike 4673: "details", "dir", "div", "dl", "fieldset", "figure", "footer",
4674: "header", "hgroup", "listing", "menu", "nav", "ol", "pre",
4675: "section", "ul"</dt>
1.1 mike 4676: <dd>
4677:
4678: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
4679: with the same tag name as that of the token, then this is a
4680: <a href="#parse-error">parse error</a>; ignore the token.</p>
4681:
4682: <p>Otherwise, run these steps:</p>
4683:
4684: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4685:
4686: <li><p>If the <a href="#current-node">current node</a> is not an element with
4687: the same tag name as that of the token, then this is a
4688: <a href="#parse-error">parse error</a>.</p></li>
4689:
4690: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4691: until an element with the same tag name as the token has been
4692: popped from the stack.</p></li>
4693:
4694: </ol></dd>
4695:
4696: <!-- removes the form element pointer instead of the matching node -->
4697: <dt>An end tag whose tag name is "form"</dt>
4698: <dd>
4699:
4700: <p>Let <var title="">node</var> be the element that the
4701: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
4702: to.</p>
4703:
4704: <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
4705: to null.</p>
4706:
4707: <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
4708: elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
4709: scope">have <var title="">node</var> in scope</a>, then this is
4710: a <a href="#parse-error">parse error</a>; ignore the token.</p>
4711:
4712: <p>Otherwise, run these steps:</p>
4713:
4714: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4715:
4716: <li><p>If the <a href="#current-node">current node</a> is not <var title="">node</var>, then this is a <a href="#parse-error">parse
4717: error</a>.</p></li>
4718:
4719: <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
4720: open elements</a>.</p></li>
4721:
4722: </ol></dd>
4723:
4724: <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
4725: <dt>An end tag whose tag name is "p"</dt>
4726: <dd>
4727:
4728: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
4729: with the same tag name as that of the token, then this is a
4730: <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
4731: "p" had been seen, then reprocess the current token.</p>
4732:
4733: <p>Otherwise, run these steps:</p>
4734:
4735: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
4736: for elements with the same tag name as the token.</p></li>
4737:
4738: <li><p>If the <a href="#current-node">current node</a> is not an element with
4739: the same tag name as that of the token, then this is a
4740: <a href="#parse-error">parse error</a>.</p></li>
4741:
4742: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4743: until an element with the same tag name as the token has been
4744: popped from the stack.</p></li>
4745:
4746: </ol></dd>
4747:
1.234 mike 4748: <!-- as normal, but needs care as the elements have optional tags, and are further scoped by <ol>/<ul> -->
4749: <dt>An end tag whose tag name is "li"</dt>
4750: <dd>
4751:
4752: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-list-item-scope" title="has an element in list item scope">have an element in list
4753: item scope</a> with the same tag name as that of the token,
4754: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
4755:
4756: <p>Otherwise, run these steps:</p>
4757:
4758: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
4759: for elements with the same tag name as the token.</p></li>
4760:
4761: <li><p>If the <a href="#current-node">current node</a> is not an element with
4762: the same tag name as that of the token, then this is a
4763: <a href="#parse-error">parse error</a>.</p></li>
4764:
4765: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4766: until an element with the same tag name as the token has been
4767: popped from the stack.</p></li>
4768:
4769: </ol></dd>
4770:
1.1 mike 4771: <!-- as normal, but needs care as the elements have optional tags -->
1.305 mike 4772: <!-- <dc> and <ds> are here speculatively for future expansion (they're not defined elements yet) -->
4773: <dt>An end tag whose tag name is one of: "dc", "dd", "ds", "dt"</dt>
1.1 mike 4774: <dd>
4775:
4776: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
4777: with the same tag name as that of the token, then this is a
4778: <a href="#parse-error">parse error</a>; ignore the token.</p>
4779:
4780: <p>Otherwise, run these steps:</p>
4781:
4782: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
4783: for elements with the same tag name as the token.</p></li>
4784:
4785: <li><p>If the <a href="#current-node">current node</a> is not an element with
4786: the same tag name as that of the token, then this is a
4787: <a href="#parse-error">parse error</a>.</p></li>
4788:
4789: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4790: until an element with the same tag name as the token has been
4791: popped from the stack.</p></li>
4792:
4793: </ol></dd>
4794:
4795: <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
4796: <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
4797: <dd>
4798:
4799: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
4800: whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
4801: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
4802:
4803: <p>Otherwise, run these steps:</p>
4804:
4805: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4806:
4807: <li><p>If the <a href="#current-node">current node</a> is not an element with
4808: the same tag name as that of the token, then this is a
4809: <a href="#parse-error">parse error</a>.</p></li>
4810:
4811: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4812: until an element whose tag name is one of "h1", "h2", "h3", "h4",
4813: "h5", or "h6" has been popped from the stack.</p></li>
4814:
4815: </ol></dd>
4816:
4817: <dt>An end tag whose tag name is "sarcasm"</dt>
4818: <dd>
4819: <p>Take a deep breath, then act as described in the "any other end
4820: tag" entry below.</p>
4821: </dd>
4822:
4823: <!-- ADOPTION AGENCY ELEMENTS
4824: Mozilla-only: bdo blink del ins sub sup q
4825: Safari-only: code dfn kbd nobr samp var wbr
4826: Both: a b big em font i s small strike strong tt u -->
4827:
4828: <dt>A start tag whose tag name is "a"</dt>
4829: <dd>
4830:
4831: <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
4832: contains an element whose tag name is "a" between the end of
4833: the list and the last marker on the list (or the start of the
4834: list if there is no marker on the list), then this is a
4835: <a href="#parse-error">parse error</a>; act as if an end tag with the tag
4836: name "a" had been seen, then remove that element from the
4837: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
4838: <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
4839: already remove it (it might not have if the element is not
4840: <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
4841: scope</a>).</p>
4842:
4843: <p class="example">In the non-conforming stream
4844: <code><a href="a">a<table><a href="b">b</table>x</code>,
4845: the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
4846: the second one, and the "x" character would be inside a link
4847: to "b", not to "a". This is despite the fact that the outer
4848: <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
4849: regular <code></a></code> end tag at the start of the table
4850: wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
4851:
4852: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4853: any.</p>
4854:
4855: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
4856: element to the <a href="#list-of-active-formatting-elements">list of active formatting
4857: elements</a>.</p>
4858:
4859: </dd>
4860:
4861: <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
4862: "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
4863: <dd>
4864:
4865: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4866: any.</p>
4867:
4868: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
4869: element to the <a href="#list-of-active-formatting-elements">list of active formatting
4870: elements</a>.</p>
4871:
4872: </dd>
4873:
4874: <dt>A start tag whose tag name is "nobr"</dt>
4875: <dd>
4876:
4877: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4878: any.</p>
4879:
4880: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
4881: element in scope">has a <code>nobr</code> element in scope</a>,
4882: then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
4883: the tag name "nobr" had been seen, then once again
4884: <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
4885: any.</p>
4886:
4887: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
4888: element to the <a href="#list-of-active-formatting-elements">list of active formatting
4889: elements</a>.</p>
4890:
4891: </dd>
4892:
4893: <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
4894: "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
4895: "strike", "strong", "tt", "u"</dt>
4896: <dd>
4897:
4898: <p>Follow these steps:</p>
4899:
4900: <ol><li>
4901:
4902: <p>Let the <var title="">formatting element</var> be the
4903: last element in the <a href="#list-of-active-formatting-elements">list of active formatting
4904: elements</a> that:</p>
4905:
4906: <ul><li>is between the end of the list and the last scope
4907: marker in the list, if any, or the start of the list
4908: otherwise, and</li>
4909:
4910: <li>has the same tag name as the token.</li>
4911:
4912: </ul><p>If there is no such node, or, if that node is also in the
4913: <a href="#stack-of-open-elements">stack of open elements</a> but the element is not <a href="#has-an-element-in-scope" title="has an element in scope">in scope</a>, then this is a
4914: <a href="#parse-error">parse error</a>; ignore the token, and abort these
4915: steps.</p>
4916:
4917: <p>Otherwise, if there is such a node, but that node is not
4918: in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
4919: <a href="#parse-error">parse error</a>; remove the element from the list,
4920: and abort these steps.</p>
4921:
4922: <p>Otherwise, there is a <var title="">formatting
4923: element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
4924: open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
4925: element in scope">in scope</a>. If the element is not the
4926: <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
4927: error</a>. In any case, proceed with the algorithm as
4928: written in the following steps.</p>
4929:
4930: </li>
4931:
4932: <li><p>Let the <var title="">furthest block</var> be the
4933: topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
4934: is lower in the stack than the <var title="">formatting
4935: element</var>, and is not an element in the
4936: <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
4937: categories. There might not be one.</p></li>
4938:
4939: <li><p>If there is no <var title="">furthest block</var>,
4940: then the UA must skip the subsequent steps and instead just
4941: pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
4942: elements</a>, from the <a href="#current-node">current node</a> up to and
4943: including the <var title="">formatting element</var>, and
4944: remove the <var title="">formatting element</var> from the
4945: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
4946:
4947: <li><p>Let the <var title="">common ancestor</var> be the element
4948: immediately above the <var title="">formatting element</var> in the
4949: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
4950:
4951: <li><p>Let a bookmark note the position of the <var title="">formatting element</var> in the <a href="#list-of-active-formatting-elements">list of active
4952: formatting elements</a> relative to the elements on either
4953: side of it in the list.</p></li>
4954:
4955: <li>
4956:
4957: <p>Let <var title="">node</var> and <var title="">last node</var> be the
4958: <var title="">furthest block</var>. Follow these steps:</p>
4959:
4960: <ol><li>Let <var title="">node</var> be the element immediately
4961: above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
4962: elements</a>.</li>
4963:
4964: <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
4965: active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
4966: elements</a> and then go back to step 1.</li>
4967:
4968: <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
4969: in the overall algorithm.</li>
4970:
4971: <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
4972: bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
4973: elements</a>.</li>
4974:
4975: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
4976: element <var title="">node</var> was created, replace the entry
4977: for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
4978: formatting elements</a> with an entry for the new element,
4979: replace the entry for <var title="">node</var> in the
4980: <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
4981: element, and let <var title="">node</var> be the new
4982: element.</li>
4983:
4984: <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
4985: parent node if any.</li>
4986:
4987: <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
4988:
4989: <li>Return to step 1 of this inner set of steps.</li>
4990:
4991: </ol></li>
4992:
4993: <li>
4994:
4995: <p>If the <var title="">common ancestor</var> node is a
4996: <code><a href="tabular-data.html#the-table-element">table</a></code>, <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>,
4997: <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then,
4998: <a href="#foster-parent">foster parent</a> whatever <var title="">last
4999: node</var> ended up being in the previous step, first removing
5000: it from its previous parent node if any.</p>
5001:
5002: <p>Otherwise, append whatever <var title="">last node</var>
5003: ended up being in the previous step to the <var title="">common
5004: ancestor</var> node, first removing it from its previous parent
5005: node if any.</p>
5006:
5007: </li>
5008:
5009: <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
5010: <var title="">formatting element</var> was created.</p></li>
5011:
5012: <li><p>Take all of the child nodes of the <var title="">furthest
5013: block</var> and append them to the element created in the last
5014: step.</p></li>
5015:
5016: <li><p>Append that new element to the <var title="">furthest
5017: block</var>.</p></li>
5018:
5019: <li><p>Remove the <var title="">formatting element</var> from the
5020: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
5021: new element into the <a href="#list-of-active-formatting-elements">list of active formatting
5022: elements</a> at the position of the aforementioned
5023: bookmark.</p></li>
5024:
5025: <li><p>Remove the <var title="">formatting element</var> from the
5026: <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
5027: into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
5028: the position of the <var title="">furthest block</var> in that
5029: stack.</p></li>
5030:
5031: <li><p>Jump back to step 1 in this series of steps.</p></li>
5032:
5033: </ol><!--XXX
5034: <div class="example">
5035: <p class="XXX">Need an example.</p>
5036: </div>
1.304 mike 5037: --><p class="note">Because of the way this algorithm causes elements
5038: to change parents, it has been dubbed the "adoption agency
5039: algorithm" (in contrast with other possible algorithms for dealing
5040: with misnested content, which included the "incest algorithm", the
1.1 mike 5041: "secret affair algorithm", and the "Heisenberg algorithm").</p>
5042:
5043: </dd>
5044:
5045: <dt>A start tag whose tag name is "button"</dt>
5046: <dd>
5047:
5048: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5049: an element in scope">has a <code>button</code> element in
5050: scope</a>, then this is a <a href="#parse-error">parse error</a>;
5051: act as if an end tag with the tag name "button" had been seen,
5052: then reprocess the token.</p>
5053:
5054: <p>Otherwise:</p>
5055:
5056: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5057: any.</p>
5058:
5059: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5060:
5061: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5062: formatting elements</a>.</p>
5063:
5064: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5065:
5066: </dd>
5067:
5068: <dt>A start tag token whose tag name is one of: "applet",
5069: "marquee", "object"</dt>
5070: <dd>
5071:
5072: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5073: any.</p>
5074:
5075: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5076:
5077: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5078: formatting elements</a>.</p>
5079:
5080: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5081:
5082: </dd>
5083:
5084: <dt>An end tag token whose tag name is one of: "applet", "button",
5085: "marquee", "object"</dt>
5086: <dd>
5087:
5088: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
5089: with the same tag name as that of the token, then this is a
5090: <a href="#parse-error">parse error</a>; ignore the token.</p>
5091:
5092: <p>Otherwise, run these steps:</p>
5093:
5094: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5095:
5096: <li><p>If the <a href="#current-node">current node</a> is not an element with
5097: the same tag name as that of the token, then this is a
5098: <a href="#parse-error">parse error</a>.</p></li>
5099:
5100: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5101: until an element with the same tag name as the token has been
5102: popped from the stack.</p></li>
5103:
5104: <li><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to the
5105: last marker</a>.</li>
5106:
5107: </ol></dd>
5108:
5109: <dt>A start tag whose tag name is "table"</dt>
5110: <dd>
5111:
5112: <p>If the <code>Document</code> is <em>not</em> set to
5113: <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
5114: elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
5115: <code>p</code> element in scope</a>, then act as if an end tag
5116: with the tag name "p" had been seen.</p> <!-- i hate myself (this
5117: quirk was basically caused by acid2; if i'd realised we could
5118: change the specs when i wrote acid2, we could have avoided having
5119: any parsing-mode quirks) -Hixie -->
5120:
5121: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5122:
5123: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5124:
5125: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
5126:
5127: </dd>
5128:
5129: <dt>A start tag whose tag name is one of: "area", "basefont",
5130: "bgsound", "br", "embed", "img", "input", "keygen", "spacer",
5131: "wbr"</dt>
5132: <dd>
5133:
5134: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5135: any.</p>
5136:
5137: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5138: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5139: elements</a>.</p>
5140:
5141: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5142: token's <i>self-closing flag</i></a>, if it is set.</p>
5143:
5144: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
5145: shouldn't really do it for <area>, <basefont>, <bgsound>, and
5146: <spacer> -->
5147:
5148: </dd>
5149:
5150: <dt>A start tag whose tag name is one of: "param", "source"</dt>
5151: <dd>
5152:
5153: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5154: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5155: elements</a>.</p>
5156:
5157: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5158: token's <i>self-closing flag</i></a>, if it is set.</p>
5159:
5160: </dd>
5161:
5162: <dt>A start tag whose tag name is "hr"</dt>
5163: <dd>
5164:
5165: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5166: an element in scope">has a <code>p</code> element in
5167: scope</a>, then act as if an end tag with the tag name
5168: "p" had been seen.</p>
5169:
5170: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5171: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5172: elements</a>.</p>
5173:
5174: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5175: token's <i>self-closing flag</i></a>, if it is set.</p>
5176:
5177: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5178:
5179: </dd>
5180:
5181: <dt>A start tag whose tag name is "image"</dt>
5182: <dd>
5183: <p><a href="#parse-error">Parse error</a>. Change the token's tag name
5184: to "img" and reprocess it. (Don't ask.)</p> <!-- As of
5185: 2005-12, studies showed that around 0.2% of pages used the
5186: <image> element. -->
5187: </dd>
5188:
5189: <dt id="isindex">A start tag whose tag name is "isindex"</dt>
5190: <dd>
5191:
5192: <p><a href="#parse-error">Parse error</a>.</p>
5193:
5194: <p>If the <a href="#form-element-pointer"><code title="">form</code> element
5195: pointer</a> is not null, then ignore the token.</p>
5196:
5197: <p>Otherwise:</p>
5198:
5199: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5200: token's <i>self-closing flag</i></a>, if it is set.</p> <!--
5201: purely to reduce the number of errors (we don't care if they
5202: included the /, they're not supposed to be including the tag at
5203: all! -->
5204:
5205: <p>Act as if a start tag token with the tag name "form" had been seen.</p>
5206:
5207: <p>If the token has an attribute called "action", set the
5208: <code title="attr-form-action">action</code> attribute on the
5209: resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
5210: "action" attribute of the token.</p>
5211:
5212: <p>Act as if a start tag token with the tag name "hr" had been
5213: seen.</p>
5214:
5215: <p>Act as if a start tag token with the tag name "label" had been
5216: seen.</p>
5217:
5218: <p>Act as if a stream of character tokens had been seen (see below
5219: for what they should say).</p>
5220:
5221: <p>Act as if a start tag token with the tag name "input" had been
5222: seen, with all the attributes from the "isindex" token except
5223: "name", "action", and "prompt". Set the <code title="attr-fe-name"><a href="forms.html#attr-fe-name">name</a></code> attribute of the resulting
5224: <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
5225:
5226: <p>Act as if a stream of character tokens had been seen (see
5227: below for what they should say).</p>
5228:
5229: <p>Act as if an end tag token with the tag name "label" had been
5230: seen.</p>
5231:
5232: <p>Act as if a start tag token with the tag name "hr" had been
5233: seen.</p>
5234:
5235: <p>Act as if an end tag token with the tag name "form" had been
5236: seen.</p>
5237:
5238: <p>If the token has an attribute with the name "prompt", then the
5239: first stream of characters must be the same string as given in
5240: that attribute, and the second stream of characters must be
5241: empty. Otherwise, the two streams of character tokens together
5242: should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
5243: equivalent of "This is a searchable index. Insert your search
5244: keywords here: (input field)" in the user's preferred
5245: language.</p>
5246:
5247: </dd>
5248:
5249: <dt>A start tag whose tag name is "textarea"</dt>
5250: <dd>
5251:
5252: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
5253: token.</p></li>
5254:
5255: <li><p>If the next token is a U+000A LINE FEED (LF) character
5256: token, then ignore that token and move on to the next
5257: one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
5258: ignored as an authoring convenience.)</p></li>
5259:
5260: <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
5261: the RCDATA state.</p></li>
5262:
5263: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
5264: current <a href="#insertion-mode">insertion mode</a>.</p>
5265:
5266: </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
5267: ok".</p></li>
5268:
1.91 mike 5269: <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
5270: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 5271:
5272: </ol></dd>
5273:
5274: <dt>A start tag whose tag name is "xmp"</dt>
5275: <dd>
5276:
1.233 mike 5277: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5278: an element in scope">has a <code>p</code> element in
5279: scope</a>, then act as if an end tag with the tag name
5280: "p" had been seen.</p>
5281:
1.1 mike 5282: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5283: any.</p>
5284:
5285: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5286:
1.91 mike 5287: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5288:
5289: </dd>
5290:
5291: <dt>A start tag whose tag name is "iframe"</dt>
5292: <dd>
5293:
5294: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5295:
1.91 mike 5296: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5297:
5298: </dd>
5299:
5300: <dt>A start tag whose tag name is "noembed"</dt>
5301: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
5302: <dd>
5303:
1.91 mike 5304: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5305:
5306: </dd>
5307:
5308: <dt>A start tag whose tag name is "select"</dt>
5309: <dd>
5310:
5311: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5312: any.</p>
5313:
5314: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5315:
5316: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5317:
5318: <p>If the <a href="#insertion-mode">insertion mode</a> is one of <a href="#parsing-main-intable" title="insertion mode: in table">in table</a>", "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>", "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column group</a>",
5319: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
5320: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
5321: row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
5322: cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
5323: "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
5324: table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
5325: to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
5326:
5327: </dd>
5328:
5329: <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
5330: <dd>
5331:
5332: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5333: element in scope">has an <code>option</code> element in
5334: scope</a>, then act as if an end tag with the tag name "option"
5335: had been seen.</p>
5336:
5337: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5338: any.</p>
5339:
5340: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5341:
5342: </dd>
5343:
5344: <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
5345: <dd>
5346:
5347: <!-- the parsing rules for ruby really don't match IE much at all,
5348: but in practice the markup used is very simple and so strict
5349: compatibility with IE isn't required. For example, as defined
5350: here we get very, very different behaviour than IE for
5351: pathological cases like:
5352:
5353: <ruby><ol><li><p>a<rt>b
5354: <ruby>a<rt>b<p>c
5355:
5356: But in practice most ruby markup falls into these cases:
5357:
5358: <ruby>a<rt>b</ruby>
5359: <ruby>a<rp>b<rt>c<rp>d</ruby>
5360: <ruby>a<rt>b</rt></ruby>
5361: <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
5362:
5363: -->
5364:
5365: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5366: element in scope">has a <code>ruby</code> element in scope</a>,
5367: then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
5368: node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
5369: <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
5370: node</a> up to the node immediately before the bottommost
5371: <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element on the <a href="#stack-of-open-elements">stack of open
5372: elements</a>.</p>
5373:
5374: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5375:
5376: </dd>
5377:
5378: <dt>An end tag whose tag name is "br"</dt>
5379: <dd>
5380: <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
5381: the tag name "br" had been seen. Ignore the end tag token.</p>
5382: </dd>
5383:
5384: <dt>A start tag whose tag name is "math"</dt>
5385: <dd>
5386:
5387: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5388: any.</p>
5389:
5390: <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
5391: fixes the case of MathML attributes that are not all
5392: lowercase.)</p>
5393:
5394: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
5395: fixes the use of namespaced attributes, in particular XLink.)</p>
5396:
5397: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
5398: <a href="#mathml-namespace">MathML namespace</a>.</p>
5399:
5400: <!-- If we ever change the frameset-ok flag to an insertion mode,
5401: the following change would be implied, except we'd have to do it
5402: even in the face of a self-closed tag:
5403: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
5404: -->
5405:
5406: <p>If the token has its <i>self-closing flag</i> set, pop the
5407: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5408: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
5409: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
5410:
5411: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
5412: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
5413: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
5414: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
5415: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
5416: foreign content">in foreign content</a>".</p>
5417:
5418: </dd>
5419:
5420: <dt>A start tag whose tag name is "svg"</dt>
5421: <dd>
5422:
5423: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5424: any.</p>
5425:
5426: <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
5427: the case of SVG attributes that are not all lowercase.)</p>
5428:
5429: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
5430: fixes the use of namespaced attributes, in particular XLink in
5431: SVG.)</p>
5432:
5433: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
5434: <a href="#svg-namespace">SVG namespace</a>.</p>
5435:
5436: <!-- If we ever change the frameset-ok flag to an insertion mode,
5437: the following change would be implied, except we'd have to do it
5438: even in the face of a self-closed tag:
5439: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
5440: -->
5441:
5442: <p>If the token has its <i>self-closing flag</i> set, pop the
5443: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5444: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
5445: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
5446:
5447: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
5448: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
5449: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
5450: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
5451: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
5452: foreign content">in foreign content</a>".</p>
5453:
5454: </dd>
5455:
5456: <dt>A start <!--or end--> tag whose tag name is one of: "caption",
5457: "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
5458: "thead", "tr"</dt>
5459: <!--<dt>An end tag whose tag name is one of: "area", "base",
5460: "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
5461: "img", "input", "isindex", "keygen", "link", "meta", "noembed",
5462: "noframes", "param", "script", "select", "source", "spacer",
5463: "style", "table", "textarea", "title", "wbr"</dt>-->
5464: <!--<dt>An end tag whose tag name is "noscript", if the
5465: <span>scripting flag</span> is enabled</dt>-->
5466: <dd>
5467: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5468: <!-- end tags are commented out because since they can never end
5469: up on the stack anyway, the default end tag clause will
5470: automatically handle them. we don't want to have text in the spec
5471: that is just an optimisation, as that detracts from the spec
5472: itself -->
5473: </dd>
5474:
5475: <dt>Any other start tag</dt>
5476: <dd>
5477:
5478: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5479: any.</p>
5480:
5481: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5482:
5483: <p class="note">This element will be a <a href="#phrasing">phrasing</a>
5484: element.</p>
5485:
5486: </dd>
5487:
5488: <dt>Any other end tag</dt>
5489: <dd>
5490:
5491: <p>Run the following steps:</p>
5492:
5493: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
5494: node</a> (the bottommost node of the stack).</p></li>
5495:
5496: <li><p>If <var title="">node</var> has the same tag name as
5497: the end tag token, then:</p>
5498:
5499: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5500:
5501: <li><p>If the tag name of the end tag token does not match
5502: the tag name of the <a href="#current-node">current node</a>, this is a
5503: <a href="#parse-error">parse error</a>.</p></li>
5504:
5505: <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
5506: to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
5507:
5508: </ol></li>
5509:
5510: <li><p>Otherwise, if <var title="">node</var> is in neither the
5511: <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
5512: category, then this is a <a href="#parse-error">parse error</a>; ignore the
5513: token, and abort these steps.</p></li>
5514:
5515: <li><p>Set <var title="">node</var> to the previous entry in the
5516: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
5517:
5518: <li><p>Return to step 2.</p></li>
5519:
5520: </ol></dd>
5521:
1.91 mike 5522: </dl><h5 id="parsing-main-incdata"><span class="secno">9.2.5.11 </span>The "<dfn title="insertion mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</dfn>" insertion mode</h5>
1.1 mike 5523:
5524: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.91 mike 5525: mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>", tokens must be
1.1 mike 5526: handled as follows:</p>
5527:
5528: <dl class="switch"><dt>A character token</dt>
5529: <dd>
5530:
5531: <p><a href="#insert-a-character" title="insert a character">Insert the token's
5532: character</a> into the <a href="#current-node">current node</a>.</p>
5533:
5534: </dd>
5535:
5536: <dt>An end-of-file token</dt>
5537: <dd>
5538:
5539: <!-- can't be the fragment case -->
5540: <p><a href="#parse-error">Parse error</a>.</p>
5541:
5542: <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
5543: element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
5544: executed"</a>.</p>
5545:
5546: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5547: elements</a>.</p>
5548:
5549: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5550: insertion mode</a> and reprocess the current token.</p>
5551:
5552: </dd>
5553:
5554: <dt>An end tag whose tag name is "script"</dt>
5555: <dd>
5556:
5557: <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
5558: (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
5559:
5560: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5561: elements</a>.</p>
5562:
5563: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5564: insertion mode</a>.</p>
5565:
5566: <p>Let the <var title="">old insertion point</var> have the
5567: same value as the current <a href="#insertion-point">insertion point</a>. Let
5568: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
5569: input character</a>.</p>
5570:
5571: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
5572: one.</p>
5573:
5574: <p><a href="semantics.html#running-a-script" title="running a script">Run</a> the <var title="">script</var>. This might cause some script to execute,
1.159 mike 5575: which might cause <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters
1.1 mike 5576: to be inserted into the tokenizer</a>, and might cause the
5577: tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
5578:
5579: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
5580: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
5581: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
5582:
5583: <p>Let the <a href="#insertion-point">insertion point</a> have the value of the <var title="">old insertion point</var>. (In other words, restore the
5584: <a href="#insertion-point">insertion point</a> to its previous value. This value
5585: might be the "undefined" value.)</p>
5586:
5587: <p id="scriptTagParserResumes">At this stage, if there is a
5588: <a href="semantics.html#pending-external-script">pending external script</a>, then:</p>
5589:
5590: <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
5591:
5592: <dd>
5593:
5594: <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
5595: processing of any nested invocations of the tokenizer, yielding
5596: control back to the caller. (Tokenization will resume when the
5597: caller returns to the "outer" tree construction stage.)</p>
5598:
5599: <p class="note">The tree construction stage of this particular
5600: parser is <a href="#nestedParsing">being called reentrantly</a>,
1.159 mike 5601: say from a call to <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>.</p>
1.1 mike 5602:
5603: </dd>
5604:
5605:
5606: <dt>Otherwise:</dt>
5607:
5608: <dd>
5609:
5610: <p>Follow these steps:</p>
5611:
5612: <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-external-script">pending
5613: external script</a>. There is no longer a <a href="semantics.html#pending-external-script">pending
5614: external script</a>.</p></li>
5615:
5616: <li><p><a href="browsers.html#pause">Pause</a> until the script has <a href="semantics.html#completed-loading">completed
5617: loading</a>.</p></li>
5618:
5619: <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
5620: <a href="#next-input-character">next input character</a>.</p></li>
5621:
5622: <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
5623: by one (it should be zero before this step, so this sets it to
5624: one).</p></li>
5625:
5626: <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute the
5627: script</a>.</p></li>
5628:
5629: <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
5630: by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
5631: zero (which it always should be at this point), then set the
5632: <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
5633:
5634: </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
5635: again.</p></li>
5636:
5637: <li><p>If there is once again a <a href="semantics.html#pending-external-script">pending external
5638: script</a>, then repeat these steps from step 1.</p></li>
5639:
5640: </ol></dd>
5641:
5642: </dl></dd>
5643:
5644: <dt>Any other end tag</dt>
5645: <dd>
5646:
5647: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5648: elements</a>.</p>
5649:
5650: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5651: insertion mode</a>.</p>
5652:
5653: </dd>
5654:
5655: </dl><h5 id="parsing-main-intable"><span class="secno">9.2.5.12 </span>The "<dfn title="insertion mode: in table">in table</dfn>" insertion mode</h5>
5656:
5657: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
5658: mode: in table">in table</a>", tokens must be handled as follows:</p>
5659:
5660: <dl class="switch"><dt>A character token</dt>
5661: <dd>
5662:
5663: <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
5664: be an empty list of tokens.</p>
5665:
5666: <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
5667: <a href="#insertion-mode">insertion mode</a>.</p>
5668:
5669: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table text</a>" and
5670: reprocess the token.</p>
5671:
5672: </dd>
5673:
5674: <dt>A comment token</dt>
5675: <dd>
5676: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
5677: node</a> with the <code title="">data</code> attribute set to
5678: the data given in the comment token.</p>
5679: </dd>
5680:
5681: <dt>A DOCTYPE token</dt>
5682: <dd>
5683: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5684: </dd>
5685:
5686: <dt>A start tag whose tag name is "caption"</dt>
5687: <dd>
5688:
5689: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5690: below.)</p>
5691:
5692: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5693: formatting elements</a>.</p>
5694:
5695: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5696: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
5697:
5698: </dd>
5699:
5700: <dt>A start tag whose tag name is "colgroup"</dt>
5701: <dd>
5702:
5703: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5704: below.)</p>
5705:
5706: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5707: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
5708: group</a>".</p>
5709:
5710: </dd>
5711:
5712: <dt>A start tag whose tag name is "col"</dt>
5713: <dd>
5714: <p>Act as if a start tag token with the tag name "colgroup"
5715: had been seen, then reprocess the current token.</p>
5716: </dd>
5717:
5718: <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
5719: <dd>
5720:
5721: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5722: below.)</p>
5723:
5724: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5725: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
5726: body</a>".</p>
5727:
5728: </dd>
5729:
5730: <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
5731: <dd>
5732: <p>Act as if a start tag token with the tag name "tbody" had
5733: been seen, then reprocess the current token.</p>
5734: </dd>
5735:
5736: <dt>A start tag whose tag name is "table"</dt>
5737: <dd>
5738:
5739: <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
5740: the tag name "table" had been seen, then, if that token wasn't
5741: ignored, reprocess the current token.</p>
5742:
5743: <p class="note">The fake end tag token here can only be
5744: ignored in the <a href="#fragment-case">fragment case</a>.</p>
5745:
5746: </dd>
5747:
5748: <dt>An end tag whose tag name is "table"</dt>
5749: <dd>
5750:
5751: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
5752: scope</a> with the same tag name as the token, this is a
5753: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
5754: case</a>)</p>
5755:
5756: <p>Otherwise:</p>
5757:
5758: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
5759: element has been popped from the stack.</p>
5760:
5761: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
5762:
5763: </dd>
5764:
5765: <dt>An end tag whose tag name is one of: "body", "caption",
5766: "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
5767: "thead", "tr"</dt>
5768: <dd>
5769: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5770: </dd>
5771:
5772: <dt>A start tag whose tag name is one of: "style", "script"</dt>
5773: <dd>
5774:
5775: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
5776: mode</a>.</p>
5777:
5778: </dd>
5779:
5780: <dt>A start tag whose tag name is "input"</dt>
5781: <dd>
5782:
5783: <p>If the token does not have an attribute with the name "type",
5784: or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
5785: case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
5786: else" entry below.</p>
5787:
5788: <p>Otherwise:</p>
5789:
5790: <p><a href="#parse-error">Parse error</a>.</p>
5791:
5792: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5793:
5794: <p>Pop that <code><a href="forms.html#the-input-element">input</a></code> element off the <a href="#stack-of-open-elements">stack of
5795: open elements</a>.</p>
5796:
5797: </dd>
5798:
5799: <dt>An end-of-file token</dt>
5800: <dd>
5801:
5802: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 5803: <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1 mike 5804: error</a>.</p>
5805:
5806: <p class="note">It can only be the <a href="#current-node">current node</a> in
5807: the <a href="#fragment-case">fragment case</a>.</p>
5808:
5809: <p><a href="#stop-parsing">Stop parsing</a>.</p>
5810:
5811: </dd>
5812:
5813: <dt>Anything else</dt>
5814: <dd>
5815:
5816: <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
5817: rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
5818: body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
5819: <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
5820: <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or
5821: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
5822: into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
5823:
5824: </dd>
5825:
5826: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
5827: back to a table context</dfn>, it means that the UA must, while
5828: the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-table-element">table</a></code>
1.159 mike 5829: element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1 mike 5830: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
5831:
5832: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 5833: <code><a href="semantics.html#the-html-element-0">html</a></code> element after this process is a <a href="#fragment-case">fragment
1.1 mike 5834: case</a>.</p>
5835:
5836:
5837:
5838: <h5 id="parsing-main-intabletext"><span class="secno">9.2.5.13 </span>The "<dfn title="insertion mode: in table text">in table text</dfn>" insertion mode</h5>
5839:
5840: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
5841: mode: in table text">in table text</a>", tokens must be handled
5842: as follows:</p>
5843:
5844: <dl class="switch"><dt>A character token</dt>
5845: <dd>
5846:
5847: <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
5848: tokens</a></var> list.</p>
5849:
5850: </dd>
5851:
5852:
5853: <dt>Anything else</dt>
5854: <dd>
5855:
5856: <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
5857: tokens</a></var> list are character tokens that are not one of U+0009
5858: CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
5859: (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
5860: reprocess those character tokens using the rules given in the
5861: "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
5862: table">in table</a>" insertion mode.</p>
5863:
5864: <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
5865: characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
5866: tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
5867:
5868: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5869: insertion mode</a> and reprocess the token.</p>
5870:
5871: </dd>
5872:
5873: </dl><h5 id="parsing-main-incaption"><span class="secno">9.2.5.14 </span>The "<dfn title="insertion mode: in caption">in caption</dfn>" insertion mode</h5>
5874:
5875: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
5876: mode: in caption">in caption</a>", tokens must be handled as follows:</p>
5877:
5878: <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
5879: <dd>
5880:
5881: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
5882: scope</a> with the same tag name as the token, this is a
5883: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
5884: case</a>)</p>
5885:
5886: <p>Otherwise:</p>
5887:
5888: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
5889:
5890: <p>Now, if the <a href="#current-node">current node</a> is not a
5891: <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
5892: error</a>.</p>
5893:
5894: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
5895: element has been popped from the stack.</p>
5896:
5897: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
5898: the last marker</a>.</p>
5899:
5900: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
5901:
5902: </dd>
5903:
5904: <dt>A start tag whose tag name is one of: "caption", "col",
5905: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
5906: <dt>An end tag whose tag name is "table"</dt>
5907: <dd>
5908:
5909: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
5910: name "caption" had been seen, then, if that token wasn't
5911: ignored, reprocess the current token.</p>
5912:
5913: <p class="note">The fake end tag token here can only be
5914: ignored in the <a href="#fragment-case">fragment case</a>.</p>
5915:
5916: </dd>
5917:
5918: <dt>An end tag whose tag name is one of: "body", "col",
5919: "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
5920: "tr"</dt>
5921: <dd>
5922: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5923: </dd>
5924:
5925: <dt>Anything else</dt>
5926: <dd>
5927: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
5928: mode</a>.</p>
5929: </dd>
5930:
5931: </dl><h5 id="parsing-main-incolgroup"><span class="secno">9.2.5.15 </span>The "<dfn title="insertion mode: in column group">in column group</dfn>" insertion mode</h5>
5932:
5933: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
5934: mode: in column group">in column group</a>", tokens must be handled as follows:</p>
5935:
5936: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
5937: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
5938: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
5939: <dd>
5940: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
5941: the <a href="#current-node">current node</a>.</p>
5942: </dd>
5943:
5944: <dt>A comment token</dt>
5945: <dd>
5946: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
5947: node</a> with the <code title="">data</code> attribute set to
5948: the data given in the comment token.</p>
5949: </dd>
5950:
5951: <dt>A DOCTYPE token</dt>
5952: <dd>
5953: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5954: </dd>
5955:
5956: <dt>A start tag whose tag name is "html"</dt>
5957: <dd>
5958: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
5959: mode</a>.</p>
5960: </dd>
5961:
5962: <dt>A start tag whose tag name is "col"</dt>
5963: <dd>
5964:
5965: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5966: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5967: elements</a>.</p>
5968:
5969: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5970: token's <i>self-closing flag</i></a>, if it is set.</p>
5971:
5972: </dd>
5973:
5974: <dt>An end tag whose tag name is "colgroup"</dt>
5975: <dd>
5976:
5977: <p>If the <a href="#current-node">current node</a> is the root
1.159 mike 5978: <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1 mike 5979: error</a>; ignore the token. (<a href="#fragment-case">fragment
5980: case</a>)</p>
5981:
5982: <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
5983: a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element) from the <a href="#stack-of-open-elements">stack of open
5984: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
5985: "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
5986:
5987: </dd>
5988:
5989: <dt>An end tag whose tag name is "col"</dt>
5990: <dd>
5991: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5992: </dd>
5993:
5994: <dt>An end-of-file token</dt>
5995: <dd>
5996:
1.159 mike 5997: <p>If the <a href="#current-node">current node</a> is the root <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1 mike 5998: element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
5999: case</a>)</p>
6000:
6001: <p>Otherwise, act as described in the "anything else" entry
6002: below.</p>
6003:
6004: </dd>
6005:
6006: <dt>Anything else</dt>
6007: <dd>
6008:
6009: <p>Act as if an end tag with the tag name "colgroup" had been
6010: seen, and then, if that token wasn't ignored, reprocess the
6011: current token.</p>
6012:
6013: <p class="note">The fake end tag token here can only be
6014: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6015:
6016: </dd>
6017:
6018: </dl><h5 id="parsing-main-intbody"><span class="secno">9.2.5.16 </span>The "<dfn title="insertion mode: in table body">in table body</dfn>" insertion mode</h5>
6019:
6020: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
6021: mode: in table body">in table body</a>", tokens must be handled as follows:</p>
6022:
6023: <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
6024: <dd>
6025:
6026: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6027: context</a>. (See below.)</p>
6028:
6029: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
6030: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
6031: in row">in row</a>".</p>
6032:
6033: </dd>
6034:
6035: <dt>A start tag whose tag name is one of: "th", "td"</dt>
6036: <dd>
6037: <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
6038: the tag name "tr" had been seen, then reprocess the current
6039: token.</p>
6040: </dd>
6041:
6042: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
6043: "thead"</dt>
6044: <dd>
6045:
6046: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
6047: scope</a> with the same tag name as the token, this is a
6048: <a href="#parse-error">parse error</a>. Ignore the token.</p>
6049:
6050: <p>Otherwise:</p>
6051:
6052: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6053: context</a>. (See below.)</p>
6054:
6055: <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
6056: open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
6057: to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
6058:
6059: </dd>
6060:
6061: <dt>A start tag whose tag name is one of: "caption", "col",
6062: "colgroup", "tbody", "tfoot", "thead"</dt>
6063: <dt>An end tag whose tag name is "table"</dt>
6064: <dd>
6065:
6066: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
6067: <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
6068: element in table scope</a>, this is a <a href="#parse-error">parse
6069: error</a>. Ignore the token. (<a href="#fragment-case">fragment
6070: case</a>)</p>
6071:
6072: <p>Otherwise:</p>
6073:
6074: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6075: context</a>. (See below.)</p>
6076:
6077: <p>Act as if an end tag with the same tag name as the
6078: <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
6079: been seen, then reprocess the current token.</p>
6080:
6081: </dd>
6082:
6083: <dt>An end tag whose tag name is one of: "body", "caption",
6084: "col", "colgroup", "html", "td", "th", "tr"</dt>
6085: <dd>
6086: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6087: </dd>
6088:
6089: <dt>Anything else</dt>
6090: <dd>
6091: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" <a href="#insertion-mode">insertion
6092: mode</a>.</p>
6093: </dd>
6094:
6095: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
6096: back to a table body context</dfn>, it means that the UA must,
6097: while the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
1.159 mike 6098: <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1 mike 6099: element, pop elements from the <a href="#stack-of-open-elements">stack of open
6100: elements</a>.</p>
6101:
6102: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 6103: <code><a href="semantics.html#the-html-element-0">html</a></code> element after this process is a <a href="#fragment-case">fragment
1.1 mike 6104: case</a>.</p>
6105:
6106:
6107: <h5 id="parsing-main-intr"><span class="secno">9.2.5.17 </span>The "<dfn title="insertion mode: in row">in row</dfn>" insertion mode</h5>
6108:
6109: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
6110: mode: in row">in row</a>", tokens must be handled as follows:</p>
6111:
6112: <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
6113: <dd>
6114:
6115: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
6116: context</a>. (See below.)</p>
6117:
6118: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
6119: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
6120: in cell">in cell</a>".</p>
6121:
6122: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
6123: formatting elements</a>.</p>
6124:
6125: </dd>
6126:
6127: <dt>An end tag whose tag name is "tr"</dt>
6128: <dd>
6129:
6130: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
6131: scope</a> with the same tag name as the token, this is a
6132: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6133: case</a>)</p>
6134:
6135: <p>Otherwise:</p>
6136:
6137: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
6138: context</a>. (See below.)</p>
6139:
6140: <p>Pop the <a href="#current-node">current node</a> (which will be a
6141: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
6142: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
6143: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
6144: body</a>".</p>
6145:
6146: </dd>
6147:
6148: <dt>A start tag whose tag name is one of: "caption", "col",
6149: "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
6150: <dt>An end tag whose tag name is "table"</dt>
6151: <dd>
6152:
6153: <p>Act as if an end tag with the tag name "tr" had been seen,
6154: then, if that token wasn't ignored, reprocess the current
6155: token.</p>
6156:
6157: <p class="note">The fake end tag token here can only be
6158: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6159:
6160: </dd>
6161:
6162: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
6163: "thead"</dt>
6164: <dd>
6165:
6166: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
6167: scope</a> with the same tag name as the token, this is a
6168: <a href="#parse-error">parse error</a>. Ignore the token.</p>
6169:
6170: <p>Otherwise, act as if an end tag with the tag name "tr" had
6171: been seen, then reprocess the current token.</p>
6172:
6173: </dd>
6174:
6175: <dt>An end tag whose tag name is one of: "body", "caption",
6176: "col", "colgroup", "html", "td", "th"</dt>
6177: <dd>
6178: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6179: </dd>
6180:
6181: <dt>Anything else</dt>
6182: <dd>
6183: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" <a href="#insertion-mode">insertion
6184: mode</a>.</p>
6185: </dd>
6186:
6187: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
6188: back to a table row context</dfn>, it means that the UA must,
6189: while the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tr-element">tr</a></code>
1.159 mike 6190: element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1 mike 6191: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6192:
6193: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 6194: <code><a href="semantics.html#the-html-element-0">html</a></code> element after this process is a <a href="#fragment-case">fragment
1.1 mike 6195: case</a>.</p>
6196:
6197:
6198: <h5 id="parsing-main-intd"><span class="secno">9.2.5.18 </span>The "<dfn title="insertion mode: in cell">in cell</dfn>" insertion mode</h5>
6199:
6200: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
6201: mode: in cell">in cell</a>", tokens must be handled as follows:</p>
6202:
6203: <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
6204: <dd>
6205:
6206: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
6207: scope</a> with the same tag name as that of the token, then
6208: this is a <a href="#parse-error">parse error</a> and the token must be
6209: ignored.</p>
6210:
6211: <p>Otherwise:</p>
6212:
6213: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
6214:
6215: <p>Now, if the <a href="#current-node">current node</a> is not an element
6216: with the same tag name as the token, then this is a
6217: <a href="#parse-error">parse error</a>.</p>
6218:
6219: <p>Pop elements from this stack until an element with the same
6220: tag name as the token has been popped from the stack.</p>
6221:
6222: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
6223: the last marker</a>.</p>
6224:
6225: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>". (The
6226: <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
6227: this point.)</p>
6228:
6229: </dd>
6230:
6231: <dt>A start tag whose tag name is one of: "caption", "col",
6232: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
6233: <dd>
6234:
6235: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
6236: <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
6237: a <code>td</code> or <code>th</code> element in table
6238: scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
6239: the token. (<a href="#fragment-case">fragment case</a>)</p>
6240:
6241: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
6242: reprocess the current token.</p>
6243:
6244: </dd>
6245:
6246: <dt>An end tag whose tag name is one of: "body", "caption",
6247: "col", "colgroup", "html"</dt>
6248: <dd>
6249: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6250: </dd>
6251:
6252: <dt>An end tag whose tag name is one of: "table", "tbody",
6253: "tfoot", "thead", "tr"</dt>
6254: <dd>
6255:
6256: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
6257: scope</a> with the same tag name as that of the token
6258: (which can only happen for "tbody", "tfoot" and "thead", or,
6259: in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
6260: error</a> and the token must be ignored.</p>
6261:
6262: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
6263: reprocess the current token.</p>
6264:
6265: </dd>
6266:
6267: <dt>Anything else</dt>
6268: <dd>
6269: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
6270: mode</a>.</p>
6271: </dd>
6272:
6273: </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
6274: mean to run the following algorithm:</p>
6275:
6276: <ol><li><p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope" title="has an element in table scope">has a <code>td</code>
6277: element in table scope</a>, then act as if an end tag token
6278: with the tag name "td" had been seen.</p></li>
6279:
6280: <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
6281: <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
6282: <code>th</code> element in table scope</a>; act as if an end
6283: tag token with the tag name "th" had been seen.</p></li>
6284:
6285: </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
6286: have both a <code><a href="tabular-data.html#the-td-element">td</a></code> and a <code><a href="tabular-data.html#the-th-element">th</a></code> element <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table scope</a> at
6287: the same time, nor can it have neither when the <a href="#insertion-mode">insertion
6288: mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
6289: cell</a>".</p>
6290:
6291:
6292: <h5 id="parsing-main-inselect"><span class="secno">9.2.5.19 </span>The "<dfn title="insertion mode: in select">in select</dfn>" insertion mode</h5>
6293:
6294: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
6295: mode: in select">in select</a>", tokens must be handled as follows:</p>
6296:
6297: <dl class="switch"><dt>A character token</dt>
6298: <dd>
6299: <p><a href="#insert-a-character" title="insert a character">Insert the token's
6300: character</a> into the <a href="#current-node">current node</a>.</p>
6301: </dd>
6302:
6303: <dt>A comment token</dt>
6304: <dd>
6305: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6306: node</a> with the <code title="">data</code> attribute set to
6307: the data given in the comment token.</p>
6308: </dd>
6309:
6310: <dt>A DOCTYPE token</dt>
6311: <dd>
6312: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6313: </dd>
6314:
6315: <dt>A start tag whose tag name is "html"</dt>
6316: <dd>
6317: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
6318: mode</a>.</p>
6319: </dd>
6320:
6321: <dt>A start tag whose tag name is "option"</dt>
6322: <dd>
6323:
6324: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6325: element, act as if an end tag with the tag name "option" had
6326: been seen.</p>
6327:
6328: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6329:
6330: </dd>
6331:
6332: <dt>A start tag whose tag name is "optgroup"</dt>
6333: <dd>
6334:
6335: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6336: element, act as if an end tag with the tag name "option" had
6337: been seen.</p>
6338:
6339: <p>If the <a href="#current-node">current node</a> is an
6340: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
6341: tag name "optgroup" had been seen.</p>
6342:
6343: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6344:
6345: </dd>
6346:
6347: <dt>An end tag whose tag name is "optgroup"</dt>
6348: <dd>
6349:
6350: <p>First, if the <a href="#current-node">current node</a> is an
6351: <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
6352: it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
6353: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
6354: the tag name "option" had been seen.</p>
6355:
6356: <p>If the <a href="#current-node">current node</a> is an
6357: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
6358: <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
6359: <a href="#parse-error">parse error</a>; ignore the token.</p>
6360:
6361: </dd>
6362:
6363: <dt>An end tag whose tag name is "option"</dt>
6364: <dd>
6365:
6366: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6367: element, then pop that node from the <a href="#stack-of-open-elements">stack of open
6368: elements</a>. Otherwise, this is a <a href="#parse-error">parse
6369: error</a>; ignore the token.</p>
6370:
6371: </dd>
6372:
6373: <dt>An end tag whose tag name is "select"</dt>
6374: <dd>
6375:
6376: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
6377: scope</a> with the same tag name as the token, this is a
6378: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6379: case</a>)</p>
6380:
6381: <p>Otherwise:</p>
6382:
6383: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
6384: until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
6385: stack.</p>
6386:
6387: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
6388:
6389: </dd>
6390:
6391: <dt>A start tag whose tag name is "select"</dt>
6392: <dd>
6393:
6394: <p><a href="#parse-error">Parse error</a>. Act as if the token had been
6395: an end tag with the tag name "select" instead.</p>
6396:
6397: </dd>
6398:
6399: <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
6400: <dd>
1.73 mike 6401:
6402: <p><a href="#parse-error">Parse error</a>.</p>
6403:
1.124 mike 6404: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a <code>select</code>
6405: element in table scope</a>, ignore the token. (<a href="#fragment-case">fragment
6406: case</a>)</p>
1.73 mike 6407:
6408: <p>Otherwise, act as if an end tag with the tag name "select" had
6409: been seen, and reprocess the token.</p>
6410:
1.1 mike 6411: </dd>
6412:
6413: <dt>A start tag token whose tag name is "script"</dt>
6414: <dd>
6415: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
6416: mode</a>.</p>
6417: </dd>
6418:
6419: <dt>An end-of-file token</dt>
6420: <dd>
6421:
6422: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 6423: <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1 mike 6424: error</a>.</p>
6425:
6426: <p class="note">It can only be the <a href="#current-node">current node</a> in
6427: the <a href="#fragment-case">fragment case</a>.</p>
6428:
6429: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6430:
6431: </dd>
6432:
6433: <dt>Anything else</dt>
6434: <dd>
6435: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6436: </dd>
6437:
6438: </dl><h5 id="parsing-main-inselectintable"><span class="secno">9.2.5.20 </span>The "<dfn title="insertion mode: in select in table">in select in table</dfn>" insertion mode</h5>
6439:
6440: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
6441: mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
6442:
6443: <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
6444: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
6445: <dd>
6446: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
6447: name "select" had been seen, and reprocess the token.</p>
6448: </dd>
6449:
6450: <dt>An end tag whose tag name is one of: "caption", "table",
6451: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
6452: <dd>
6453:
6454: <p><a href="#parse-error">Parse error</a>.</p>
6455:
6456: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
6457: element in table scope</a> with the same tag name as that
6458: of the token, then act as if an end tag with the tag name
6459: "select" had been seen, and reprocess the token. Otherwise,
6460: ignore the token.</p>
6461:
6462: </dd>
6463:
6464: <dt>Anything else</dt>
6465: <dd>
6466: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>" <a href="#insertion-mode">insertion
6467: mode</a>.</p>
6468: </dd>
6469:
1.168 mike 6470: </dl><h5 id="parsing-main-inforeign"><span class="secno">9.2.5.21 </span>The "<dfn title="insertion mode: in foreign content">in foreign content</dfn>" insertion mode</h5>
1.1 mike 6471:
6472: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
6473: mode: in foreign content">in foreign content</a>", tokens must be
6474: handled as follows:</p>
6475:
6476: <dl class="switch"><dt>A character token</dt>
6477: <dd>
6478:
6479: <p><a href="#insert-a-character" title="insert a character">Insert the token's
6480: character</a> into the <a href="#current-node">current node</a>.</p>
6481:
6482: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
6483: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
6484: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
6485: flag</a> to "not ok".</p>
6486:
6487: </dd>
6488:
6489: <dt>A comment token</dt>
6490: <dd>
6491: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6492: node</a> with the <code title="">data</code> attribute set to
6493: the data given in the comment token.</p>
6494: </dd>
6495:
6496: <dt>A DOCTYPE token</dt>
6497: <dd>
6498: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6499: </dd>
6500:
6501: <dt>An end tag whose tag name is "script", if the <a href="#current-node">current node</a> is a <code title="">script</code> element in the <a href="#svg-namespace">SVG namespace</a>.</dt>
6502: <dd>
6503:
6504: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6505: elements</a>.</p>
6506:
6507: <p>Let the <var title="">old insertion point</var> have the
6508: same value as the current <a href="#insertion-point">insertion point</a>. Let
6509: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
6510: input character</a>.</p>
6511:
6512: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
6513: one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
6514:
6515: <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
6516: the <code title="">script</code> element</a> according to the SVG
1.187 mike 6517: rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
1.1 mike 6518:
1.159 mike 6519: <p class="note">Even if this causes <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters to be inserted into the
1.1 mike 6520: tokenizer</a>, the parser will not be executed reentrantly,
6521: since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
6522:
6523: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
6524: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
6525: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
6526:
6527: <p>Let the <a href="#insertion-point">insertion point</a> have the value of the <var title="">old insertion point</var>. (In other words, restore the
6528: <a href="#insertion-point">insertion point</a> to its previous value. This value
6529: might be the "undefined" value.)</p>
6530:
6531: </dd>
6532:
6533: <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">mi</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
6534: <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">mo</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
6535: <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">mn</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
6536: <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">ms</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
6537: <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">mtext</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
6538: <dt>A start tag whose tag name is "svg", if the <a href="#current-node">current node</a> is an <code title="">annotation-xml</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
6539: <dt>A start tag, if the <a href="#current-node">current node</a> is a <code title="">foreignObject</code> element in the <a href="#svg-namespace">SVG namespace</a>.</dt>
6540: <dt>A start tag, if the <a href="#current-node">current node</a> is a <code title="">desc</code> element in the <a href="#svg-namespace">SVG namespace</a>.</dt>
6541: <dt>A start tag, if the <a href="#current-node">current node</a> is a <code title="">title</code> element in the <a href="#svg-namespace">SVG namespace</a>.</dt>
6542: <dt>A start tag, if the <a href="#current-node">current node</a> is an element in the <a href="#html-namespace-0">HTML namespace</a>.</dt>
6543: <dt>An end tag</dt>
6544: <dd>
6545:
6546: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
6547: <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
6548:
6549: <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
6550: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
6551: content</a>", but there is no element in scope that has a
6552: namespace other than the <a href="#html-namespace-0">HTML namespace</a><!-- XXX this
6553: isn't well-defined; it means check to see if the bottom-most HTML
6554: element on the stack is in scope -->, switch the <a href="#insertion-mode">insertion
6555: mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
6556:
6557: </dd>
6558:
6559: <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
6560: "blockquote", "body"<!--by inspection-->, "br", "center", "code",
1.305 mike 6561: "dc"<!-- with dt -->, "dd", "div", "dl", "ds"<!-- with dt -->,
6562: "dt"<!-- so that dd and dt can be handled uniformly throughout the
6563: parser; dc and ds are here for the same reason -->, "em", "embed",
6564: "h1", "h2", "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
1.1 mike 6565: completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
6566: "li", "listing"<!-- so that pre and listing can be handled
6567: uniformly throughout the parser -->, "menu", "meta", "nobr",
6568: "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
6569: the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
6570: "span", "strong", "strike"<!-- so that s and strike can be handled
6571: uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
1.305 mike 6572: "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt> <!-- this
6573: list was determined empirically by studying over 6,000,000,000
6574: pages that were specifically not XML pages --> <dt>A start tag
6575: whose tag name is "font", if the token has any attributes named
6576: "color", "face", or "size"</dt> <!-- the attributes here are
6577: required so that SVG <font> will go through as SVG but legacy
6578: <font>s won't --> <dt>An end-of-file token</dt> <dd>
1.1 mike 6579:
6580: <p><a href="#parse-error">Parse error</a>.</p>
6581:
6582: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
6583: the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
6584: namespace</a>.</p>
6585:
6586: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
6587: insertion mode</a>, and reprocess the token.</p>
6588:
6589: </dd>
6590:
6591: <dt>Any other start tag</dt>
6592: <dd>
6593:
6594: <p>If the <a href="#current-node">current node</a> is an element in the
6595: <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
6596: attributes</a> for the token. (This fixes the case of MathML
6597: attributes that are not all lowercase.)</p>
6598:
6599: <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
6600: namespace</a>, and the token's tag name is one of the ones in
6601: the first column of the following table, change the tag name to
6602: the name given in the corresponding cell in the second
6603: column. (This fixes the case of SVG elements that are not all
6604: lowercase.)</p>
6605:
6606: <table><thead><tr><th> Tag name </th><th> Element name
6607: </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
6608: </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
6609: </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
6610: </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
6611: </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
6612: </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
6613: </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
6614: </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
6615: </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
6616: </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
6617: </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
6618: </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
6619: </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
6620: </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
6621: </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
6622: </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
6623: </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
6624: </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
6625: </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
6626: </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
6627: </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
6628: </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
6629: </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
6630: </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
6631: </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
6632: </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
6633: </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
6634: </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
6635: </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
6636: </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
6637: </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
6638: </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
6639: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
6640: </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
6641: </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
6642: <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
6643: </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
6644: </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
6645: namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
6646: token. (This fixes the case of SVG attributes that are not all
6647: lowercase.)</p>
6648:
6649: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
6650: fixes the use of namespaced attributes, in particular XLink in
6651: SVG.)</p>
6652:
6653: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
6654: same namespace as the <a href="#current-node">current node</a>.</p>
6655:
6656: <p>If the token has its <i>self-closing flag</i> set, pop the
6657: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6658: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
6659: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
6660:
6661: </dd>
6662:
6663: </dl><h5 id="parsing-main-afterbody"><span class="secno">9.2.5.22 </span>The "<dfn title="insertion mode: after body">after body</dfn>" insertion mode</h5>
6664:
6665: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
6666: mode: after body">after body</a>", tokens must be handled as follows:</p>
6667:
6668: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6669: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6670: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6671: <dd>
6672: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
6673: mode</a>.</p>
6674: </dd>
6675:
6676: <dt>A comment token</dt>
6677: <dd>
6678: <p>Append a <code>Comment</code> node to the first element in
1.159 mike 6679: the <a href="#stack-of-open-elements">stack of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1 mike 6680: element), with the <code title="">data</code> attribute set to
6681: the data given in the comment token.</p>
6682: </dd>
6683:
6684: <dt>A DOCTYPE token</dt>
6685: <dd>
6686: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6687: </dd>
6688:
6689: <dt>A start tag whose tag name is "html"</dt>
6690: <dd>
6691: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
6692: mode</a>.</p>
6693: </dd>
6694:
6695: <dt>An end tag whose tag name is "html"</dt>
6696: <dd>
6697:
6698: <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
6699: fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
6700: error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
6701:
6702: <p>Otherwise, switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-after-after-body-insertion-mode" title="insertion mode: after after body">after after
6703: body</a>".</p>
6704:
6705: </dd>
6706:
6707: <dt>An end-of-file token</dt>
6708: <dd>
6709: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6710: </dd>
6711:
6712: <dt>Anything else</dt>
6713: <dd>
6714:
6715: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
6716: mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
6717: body</a>" and reprocess the token.</p>
6718:
6719: </dd>
6720:
6721: </dl><h5 id="parsing-main-inframeset"><span class="secno">9.2.5.23 </span>The "<dfn title="insertion mode: in frameset">in frameset</dfn>" insertion mode</h5>
6722:
6723: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
6724: mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
6725:
6726: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6727: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6728: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6729: <dd>
6730: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6731: the <a href="#current-node">current node</a>.</p>
6732: </dd>
6733:
6734: <dt>A comment token</dt>
6735: <dd>
6736: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6737: node</a> with the <code title="">data</code> attribute set to
6738: the data given in the comment token.</p>
6739: </dd>
6740:
6741: <dt>A DOCTYPE token</dt>
6742: <dd>
6743: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6744: </dd>
6745:
6746: <dt>A start tag whose tag name is "html"</dt>
6747: <dd>
6748: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
6749: mode</a>.</p>
6750: </dd>
6751:
6752: <dt>A start tag whose tag name is "frameset"</dt>
6753: <dd>
6754: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6755: </dd>
6756:
6757: <dt>An end tag whose tag name is "frameset"</dt>
6758: <dd>
6759:
6760: <p>If the <a href="#current-node">current node</a> is the root
1.159 mike 6761: <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1 mike 6762: error</a>; ignore the token. (<a href="#fragment-case">fragment
6763: case</a>)</p>
6764:
6765: <p>Otherwise, pop the <a href="#current-node">current node</a> from the
6766: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6767:
6768: <p>If the parser was <em>not</em> originally created as part
6769: of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
6770: (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5 mike 6771: node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1 mike 6772: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
6773: frameset</a>".</p>
6774:
6775: </dd>
6776:
6777: <dt>A start tag whose tag name is "frame"</dt>
6778: <dd>
6779:
6780: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
6781: Immediately pop the <a href="#current-node">current node</a> off the
6782: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6783:
6784: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6785: token's <i>self-closing flag</i></a>, if it is set.</p>
6786:
6787: </dd>
6788:
6789: <dt>A start tag whose tag name is "noframes"</dt>
6790: <dd>
6791: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
6792: mode</a>.</p>
6793: </dd>
6794:
6795: <dt>An end-of-file token</dt>
6796: <dd>
6797:
6798: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 6799: <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1 mike 6800: error</a>.</p>
6801:
6802: <p class="note">It can only be the <a href="#current-node">current node</a> in
6803: the <a href="#fragment-case">fragment case</a>.</p>
6804:
6805: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6806:
6807: </dd>
6808:
6809: <dt>Anything else</dt>
6810: <dd>
6811: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6812: </dd>
6813:
6814: </dl><h5 id="parsing-main-afterframeset"><span class="secno">9.2.5.24 </span>The "<dfn title="insertion mode: after frameset">after frameset</dfn>" insertion mode</h5>
6815:
6816: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
6817: mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
6818:
6819: <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
6820: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6821: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6822: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6823: <dd>
6824: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6825: the <a href="#current-node">current node</a>.</p>
6826: </dd>
6827:
6828: <dt>A comment token</dt>
6829: <dd>
6830: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6831: node</a> with the <code title="">data</code> attribute set to
6832: the data given in the comment token.</p>
6833: </dd>
6834:
6835: <dt>A DOCTYPE token</dt>
6836: <dd>
6837: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6838: </dd>
6839:
6840: <dt>A start tag whose tag name is "html"</dt>
6841: <dd>
6842: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
6843: mode</a>.</p>
6844: </dd>
6845:
6846: <dt>An end tag whose tag name is "html"</dt>
6847: <dd>
6848: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
6849: frameset</a>".</p>
6850: </dd>
6851:
6852: <dt>A start tag whose tag name is "noframes"</dt>
6853: <dd>
6854: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
6855: mode</a>.</p>
6856: </dd>
6857:
6858: <dt>An end-of-file token</dt>
6859: <dd>
6860: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6861: </dd>
6862:
6863: <dt>Anything else</dt>
6864: <dd>
6865: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6866: </dd>
6867:
6868: </dl><p class="XXX">This doesn't handle UAs that don't support
6869: frames, or that do support frames but want to show the NOFRAMES
6870: content. Supporting the former is easy; supporting the latter is
6871: harder.</p>
6872:
6873:
6874: <h5 id="the-after-after-body-insertion-mode"><span class="secno">9.2.5.25 </span>The "<dfn title="insertion mode: after after body">after after body</dfn>" insertion mode</h5>
6875:
6876: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
6877: mode: after after body">after after body</a>", tokens must be handled as follows:</p>
6878:
6879: <dl class="switch"><dt>A comment token</dt>
6880: <dd>
6881: <p>Append a <code>Comment</code> node to the <code>Document</code>
6882: object with the <code title="">data</code> attribute set to the
6883: data given in the comment token.</p>
6884: </dd>
6885:
6886: <dt>A DOCTYPE token</dt>
6887: <dt>A character token that is one of U+0009 CHARACTER
6888: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6889: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6890: <dt>A start tag whose tag name is "html"</dt>
6891: <dd>
6892: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
6893: mode</a>.</p>
6894: </dd>
6895:
6896: <dt>An end-of-file token</dt>
6897: <dd>
6898: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6899: </dd>
6900:
6901: <dt>Anything else</dt>
6902: <dd>
6903: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
6904: to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
6905: reprocess the token.</p>
6906: </dd>
6907:
6908: </dl><h5 id="the-after-after-frameset-insertion-mode"><span class="secno">9.2.5.26 </span>The "<dfn title="insertion mode: after after frameset">after after frameset</dfn>" insertion mode</h5>
6909:
6910: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
6911: mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
6912:
6913: <dl class="switch"><dt>A comment token</dt>
6914: <dd>
6915: <p>Append a <code>Comment</code> node to the <code>Document</code>
6916: object with the <code title="">data</code> attribute set to the
6917: data given in the comment token.</p>
6918: </dd>
6919:
6920: <dt>A DOCTYPE token</dt>
6921: <dt>A character token that is one of U+0009 CHARACTER
6922: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6923: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6924: <dt>A start tag whose tag name is "html"</dt>
6925: <dd>
6926: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
6927: mode</a>.</p>
6928: </dd>
6929:
6930: <dt>An end-of-file token</dt>
6931: <dd>
6932: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6933: </dd>
6934:
6935: <dt>A start tag whose tag name is "noframes"</dt>
6936: <dd>
6937: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
6938: mode</a>.</p>
6939: </dd>
6940:
6941: <dt>Anything else</dt>
6942: <dd>
6943: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6944: </dd>
6945:
1.266 mike 6946: </dl></div><div class="impl">
6947:
6948: <h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4>
1.1 mike 6949:
6950: <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
6951: the document, the user agent must follow the steps in this
6952: section.</p>
6953:
1.10 mike 6954: <!-- this happens as part of one of the tasks that runs the parser -->
1.1 mike 6955:
1.10 mike 6956: <p>First, the user agent must set the <a href="dom.html#current-document-readiness">current document
6957: readiness</a> to "interactive" and the <a href="#insertion-point">insertion
6958: point</a> to undefined.</p>
6959:
6960: <p>Then, the user agent must then make a list of all the scripts
6961: that are in the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the
6962: document has finished parsing</a>, the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that
6963: will execute asynchronously</a>, and the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts
6964: that will execute as soon as possible</a>. This is the <dfn id="list-of-scripts-pending-after-the-parser-stopped">list
6965: of scripts pending after the parser stopped</dfn>.</p>
6966:
6967: <p>The rules for <a href="semantics.html#when-a-script-completes-loading">when a script completes loading</a> start
6968: applying (script execution is no longer managed by the parser).</p>
1.1 mike 6969:
6970: <p>If any of the scripts in the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will
6971: execute as soon as possible</a> have <a href="semantics.html#completed-loading">completed
6972: loading</a>, or if the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that will execute
6973: asynchronously</a> is not empty and the first script in that list
6974: has <a href="semantics.html#completed-loading">completed loading</a>, then the user agent must act as
6975: if those scripts just completed loading, following the rules given
6976: for that in the <code><a href="semantics.html#script">script</a></code> element definition.</p>
6977:
1.10 mike 6978: <p>If the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the document
6979: has finished parsing</a> is not empty, and the first item in this
6980: list has already <a href="semantics.html#completed-loading">completed loading</a>, then the user agent
6981: must act as if that script just finished loading.</p>
6982:
6983: <p class="note">By this point, there will be no scripts that have
6984: loaded but have not yet been executed.</p>
6985:
6986: <hr><!-- async --><p>Once all the scripts on the <a href="#list-of-scripts-pending-after-the-parser-stopped">list of scripts pending after
6987: the parser stopped</a> have <a href="semantics.html#completed-loading">completed loading</a> and
6988: been <a href="semantics.html#executing-a-script-block" title="executing a script block">executed</a>, the
6989: user agent must <a href="browsers.html#queue-a-task">queue a task</a> to <a href="browsers.html#fire-a-simple-event">fire a simple
6990: event</a> called <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
6991: <code>Document</code>. (If the list is empty, this happens
6992: immediately.)</p>
1.1 mike 6993:
1.10 mike 6994: <hr><!-- async --><p>Once everything that <dfn id="delay-the-load-event" title="delay the load event">delays the
1.1 mike 6995: load event</dfn> of the document has completed, the user agent must
6996: run the following steps:</p>
6997:
6998: <ol><li><a href="browsers.html#queue-a-task">Queue a task</a> to set the <a href="dom.html#current-document-readiness">current document
6999: readiness</a> to "complete".</li>
7000:
7001: <li>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
7002: context</a>, then <a href="browsers.html#queue-a-task">queue a task</a> to <a href="browsers.html#fire-a-simple-event">fire a
7003: simple event</a> called <code title="event-load"><a href="video.html#event-load">load</a></code> at
7004: the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
7005: its <code title="dom-event-target">target</code> set to the
7006: <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
7007: <code><a href="browsers.html#window">Window</a></code> object).</li>
7008:
7009: <li>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
7010: object</a>, then <a href="browsers.html#queue-a-task">queue a task</a> to fire a <code title="event-popstate"><a href="history.html#event-popstate">popstate</a></code> event in no namespace on the
7011: <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
7012: <code><a href="history.html#popstateevent">PopStateEvent</a></code> interface, with the <code title="dom-PopStateEvent-state"><a href="history.html#dom-popstateevent-state">state</a></code> attribute set to the
7013: current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
7014: must bubble but not be cancelable and has no default action.</li>
7015:
1.228 mike 7016: </ol><p>The <a href="browsers.html#task-source">task source</a> for these <span title="concept-tasks">tasks</span> is the <a href="browsers.html#dom-manipulation-task-source">DOM manipulation
7017: task source</a>.</p>
1.1 mike 7018:
7019: <!-- XXX make sure things "delay the load event", e.g. applet and
7020: object element's frame contents -->
7021:
7022: <p class="XXX">delaying the load event for things like image
7023: loads allows for intranet port scans (even without
7024: javascript!). Should we really encode that into the spec?</p>
7025:
7026:
7027: <!--XXX need to handle
7028: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#2354
7029: 2354 // Don't open transient styles if it makes the stack deep, bug 58917.
7030: -->
7031:
7032: <!--XXX
7033: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/nsHTMLTokenizer.cpp#749
7034: -->
7035:
7036: <!--
7037: see also CTextToken::ConsumeCharacterData() for CDATA parsing?
7038:
7039: 1212 1 Here's a tricky case from bug 22596: <h5><li><h5>
7040: 1213 How do we know that the 2nd <h5> should close the <LI> rather than nest inside the <LI>?
7041: 1214 (Afterall, the <h5> is a legal child of the <LI>).
7042: 1215
7043: 1216 The way you know is that there is no root between the two, so the <h5> binds more
7044: 1217 tightly to the 1st <h5> than to the <LI>.
7045: 1218 2. Also, bug 6148 shows this case: <SPAN><DIV><SPAN>
7046: 1219 From this case we learned not to execute this logic if the parent is a block.
7047: 1220
7048: 1221 3. Fix for 26583
7049: 1222 Ex. <A href=foo.html><B>foo<A href-bar.html>bar</A></B></A> <- A legal HTML
7050: 1223 In the above example clicking on "foo" or "bar" should link to
7051: 1224 foo.html or bar.html respectively. That is, the inner <A> should be informed
7052: 1225 about the presence of an open <A> above <B>..so that the inner <A> can close out
7053: 1226 the outer <A>. The following code does it for us.
7054: 1227
7055: 1228 4. Fix for 27865 [ similer to 22596 ]. Ex: <DL><DD><LI>one<DD><LI>two
7056: - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1211
7057:
7058: 815 // Here's a problem. If theTag is legal in here, we don't move it
7059: 816 // out. So if we're moving stuff out of here, the parent of theTag
7060: 817 // gets closed at this point. But some things are legal
7061: 818 // _everywhere_ and hence would effectively close out misplaced
7062: 819 // content in tables. This is undesirable, so treat them as
7063: 820 // illegal here so they'll be shipped out with their parents and
7064: 821 // siblings. See bug 40855 for an explanation (that bug was for
7065: 822 // comments, but the same issues arise with whitespace, newlines,
7066: 823 // noscript, etc). Script is special, though. Shipping it out
7067: 824 // breaks document.write stuff. See bug 243064.
7068: - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#825
7069:
7070:
7071: 1326 /**************************************************************************************
7072: 1327 *
7073: 1328 * Now a little code to deal with bug #49687 (crash when layout stack gets too deep)
7074: 1329 * I've also opened this up to any container (not just inlines): re bug 55095
7075: 1330 * Improved to handle bug 55980 (infinite loop caused when DEPTH is exceeded and
7076: 1331 * </P> is encountered by itself (<P>) is continuously produced.
7077: 1332 *
7078: 1333 **************************************************************************************/
7079:
7080: 1912 // Oh boy!! we found a "stray" tag. Nav4.x and IE introduce line break in
7081: 1913 // such cases. So, let's simulate that effect for compatibility.
7082: 1914 // Ex. <html><body>Hello</P>There</body></html>
7083: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1912
7084:
7085: http://lxr.mozilla.org/seamonkey/search?string=nested
7086: /parser/htmlparser/src/CNavDTD.cpp, line 791 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
7087: /parser/htmlparser/src/CNavDTD.cpp, line 792 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
7088: /parser/htmlparser/src/CNavDTD.cpp, line 2562 - // Discard nested forms - bug 72639
7089: /parser/htmlparser/src/nsElementTable.cpp, line 1453 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
7090: /parser/htmlparser/src/nsElementTable.cpp, line 1454 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
7091: /parser/htmlparser/src/nsElementTable.cpp, line 1901 - // Ex: <H1><LI><H1><LI>. Inner LI has the potential of getting nested
7092: -->
7093:
1.266 mike 7094: </div><div class="impl">
1.1 mike 7095:
7096: <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4>
7097:
7098: <p>When an application uses an <a href="#html-parser">HTML parser</a> in
7099: conjunction with an XML pipeline, it is possible that the
7100: constructed DOM is not compatible with the XML tool chain in certain
7101: subtle ways. For example, an XML toolchain might not be able to
7102: represent attributes with the name <code title="">xmlns</code>,
7103: since they conflict with the Namespaces in XML syntax. There is also
7104: some data that the <a href="#html-parser">HTML parser</a> generates that isn't
7105: included in the DOM itself. This section specifies some rules for
7106: handling these issues.</p>
7107:
7108: <p>If the XML API being used doesn't support DOCTYPEs, the tool may
7109: drop DOCTYPEs altogether.</p>
7110:
7111: <p>If the XML API doesn't support attributes in no namespace that
7112: are named "<code title="">xmlns</code>", attributes whose names
7113: start with "<code title="">xmlns:</code>", or attributes in the
7114: <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
7115: attributes.</p>
7116:
7117: <p>The tool may annotate the output with any namespace declarations
7118: required for proper operation.</p>
7119:
7120: <p>If the XML API being used restricts the allowable characters in
7121: the local names of elements and attributes, then the tool may map
7122: all element and attribute local names that the API wouldn't support
7123: to a set of names that <em>are</em> allowed, by replacing any
7124: character that isn't supported with the uppercase letter U and the
7125: six digits of the character's Unicode code point when expressed in
7126: hexadecimal, using digits 0-9 and capital letters A-F as the
7127: symbols, in increasing numeric order.</p>
7128:
7129: <p class="example">For example, the element name <code title="">foo<bar</code>, which can be output by the <a href="#html-parser">HTML
7130: parser</a>, though it is neither a legal HTML element name nor a
7131: well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
7132: element name (though it's still not legal in HTML by any means).</p>
7133:
7134: <p class="example">As another example, consider the attribute
7135: <code>xlink:href</code>. Used on a MathML element, it becomes, after
7136: being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
7137: attribute with a prefix "<code title="">xlink</code>" and a local
7138: name "<code title="">href</code>". However, used on an HTML element,
7139: it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
7140: might not be accepted by an XML API. It could thus get converted,
7141: becoming "<code title="">xlinkU00003Ahref</code>".</p>
7142:
7143: <p class="note">The resulting names from this conversion
7144: conveniently can't clash with any attribute generated by the
7145: <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
7146: those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
7147: algorithm's table.</p>
7148:
7149: <p>If the XML API restricts comments from having two consecutive
7150: U+002D HYPHEN-MINUS characters (--), the tool may insert a single
7151: U+0020 SPACE character between any such offending characters.</p>
7152:
7153: <p>If the XML API restricts comments from ending in a
7154: U+002D HYPHEN-MINUS character (-), the tool may insert a single
7155: U+0020 SPACE character at the end of such comments.</p>
7156:
7157: <p>If the XML API restricts allowed characters in character data,
7158: the tool may replace any U+000C FORM FEED (FF) character with a
7159: U+0020 SPACE character, and any other literal non-XML character with
7160: a U+FFFD REPLACEMENT CHARACTER.</p>
7161:
7162: <p>If the tool has no way to convey out-of-band information, then
7163: the tool may drop the following information:</p>
7164:
7165: <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
7166: <i><a href="dom.html#limited-quirks-mode">limited quirks mode</a></i>, or <i><a href="dom.html#quirks-mode">quirks mode</a></i></li>
7167:
7168: <li>The association between form controls and forms that aren't
7169: their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
7170: <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
7171:
7172: </ul><p class="note">The mutations allowed by this section apply
7173: <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
7174: applied. For example, a <code title=""><a::></code> start tag
7175: will be closed by a <code title=""></a::></code> end tag, and
7176: never by a <code title=""></aU00003AU00003A></code> end tag, even
7177: if the user agent is using the rules above to then generate an
7178: actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
7179:
1.266 mike 7180: </div><div class="impl">
1.1 mike 7181:
1.35 mike 7182: <h4 id="an-introduction-to-error-handling-and-strange-cases-in-the-parser"><span class="secno">9.2.8 </span>An introduction to error handling and strange cases in the parser</h4>
1.1 mike 7183:
7184: <p><i>This section is non-normative.</i></p>
7185:
7186: <p>This section examines some erroneous markup and discusses how
7187: the <a href="#html-parser">HTML parser</a> handles these cases.</p>
7188:
7189:
7190: <h5 id="misnested-tags:-b-i-b-i"><span class="secno">9.2.8.1 </span>Misnested tags: <b><i></b></i></h5>
7191:
7192: <p><i>This section is non-normative.</i></p>
7193:
7194: <p>The most-often discussed example of erroneous markup is as
7195: follows:</p>
7196:
7197: <pre><p>1<b>2<i>3</b>4</i>5</p></pre>
7198:
7199: <p>The parsing of this markup is straightforward up to the "3". At
7200: this point, the DOM looks like this:</p>
7201:
1.159 mike 7202: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>Here, the <a href="#stack-of-open-elements">stack of open elements</a> has five elements
7203: on it: <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>,
1.1 mike 7204: <code><a href="text-level-semantics.html#the-b-element">b</a></code>, and <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The <a href="#list-of-active-formatting-elements">list of active
7205: formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
7206: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>".</p>
7207:
7208: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
7209: invoked. This is a simple case, in that the <var title="">formatting
7210: element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
7211: <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
1.159 mike 7212: elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element-0">html</a></code>,
7213: <code><a href="semantics.html#the-body-element-0">body</a></code>, and <code><a href="semantics.html#the-p-element">p</a></code>, while the <a href="#list-of-active-formatting-elements">list of
1.1 mike 7214: active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
7215: DOM tree is unmodified at this point.</p>
7216:
7217: <p>The next token is a character ("4"), triggers the <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">reconstruction of
7218: the active formatting elements</a>, in this case just the
7219: <code><a href="text-level-semantics.html#the-i-element">i</a></code> element. A new <code><a href="text-level-semantics.html#the-i-element">i</a></code> element is thus created
7220: for the "4" text node. After the end tag token for the "i" is also
7221: received, and the "5" text node is inserted, the DOM looks as
7222: follows:</p>
7223:
1.159 mike 7224: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">4</span></li></ul></li><li class="t3"><code>#text</code>: <span title="">5</span></li></ul></li></ul></li></ul></li></ul><h5 id="misnested-tags:-b-p-b-p"><span class="secno">9.2.8.2 </span>Misnested tags: <b><p></b></p></h5>
1.1 mike 7225:
7226: <p><i>This section is non-normative.</i></p>
7227:
7228: <p>A case similar to the previous one is the following:</p>
7229:
7230: <pre><b>1<p>2</b>3</p></pre>
7231:
7232: <p>Up to the "2" the parsing here is straightforward:</p>
7233:
1.159 mike 7234: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>The interesting part is when the end tag token with the tag name
1.1 mike 7235: "b" is parsed.</p>
7236:
7237: <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
1.159 mike 7238: elements</a> has four elements on it: <code><a href="semantics.html#the-html-element-0">html</a></code>,
7239: <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="text-level-semantics.html#the-b-element">b</a></code>, and <code><a href="semantics.html#the-p-element">p</a></code>. The
1.1 mike 7240: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
7241: <code><a href="text-level-semantics.html#the-b-element">b</a></code>. The <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>".</p>
7242:
7243: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
7244: in the previous example. However, in this case, there <em>is</em> a
7245: <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
7246: this time the adoption agency algorithm isn't skipped over.</p>
7247:
1.159 mike 7248: <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 7249: element. A conceptual "bookmark" marks the position of the
7250: <code><a href="text-level-semantics.html#the-b-element">b</a></code> in the <a href="#list-of-active-formatting-elements">list of active formatting
7251: elements</a>, but since that list has only one element in it,
7252: it won't have much effect.</p>
7253:
7254: <p>As the algorithm progresses, <var title="">node</var> ends up set
7255: to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
7256: node</var> ends up set to the <var title="">furthest block</var>
7257: (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
7258:
7259: <p>The <var title="">last node</var> gets appended (moved) to the
7260: <var title="">common ancestor</var>, so that the DOM looks like:</p>
7261:
1.159 mike 7262: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul><p>A new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created, and the children of the
1.1 mike 7263: <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
7264:
1.159 mike 7265: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code></li></ul></li></ul></li></ul><ul class="domTree"><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul><p>Finally, the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is appended to the
1.1 mike 7266: <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
7267:
1.159 mike 7268: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>The <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is removed from the <a href="#list-of-active-formatting-elements">list of
1.1 mike 7269: active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
7270: elements</a>, so that when the "3" is parsed, it is appended to
7271: the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
7272:
1.159 mike 7273: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li></ul></li></ul><h5 id="unexpected-markup-in-tables"><span class="secno">9.2.8.3 </span>Unexpected markup in tables</h5>
1.1 mike 7274:
7275: <p><i>This section is non-normative.</i></p>
7276:
7277: <p>Error handling in tables is, for historical reasons, especially
7278: strange. For example, consider the following markup:</p>
7279:
7280: <pre><table><strong><b></strong><tr><td>aaa</td></tr><strong>bbb</strong></table>ccc</pre>
7281:
7282: <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
7283: directly inside a table like that, and the parser handles this case
7284: by placing the element <em>before</em> the table. (This is called <i title="foster parent"><a href="#foster-parent">foster parenting</a></i>.) This can be seen by
7285: examining the DOM tree as it stands just after the
7286: <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
7287:
1.159 mike 7288: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code></li></ul></li></ul></li></ul><p>...and then immediately after the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start
1.1 mike 7289: tag has been seen:</p>
7290:
1.159 mike 7291: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code></li></ul></li></ul></li></ul><p>At this point, the <a href="#stack-of-open-elements">stack of open elements</a> has on it
7292: the elements <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>,
1.1 mike 7293: <code><a href="tabular-data.html#the-table-element">table</a></code>, and <code><a href="text-level-semantics.html#the-b-element">b</a></code> (in that order, despite the
7294: resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
7295: elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
7296: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
7297: table">in table</a>".</p>
7298:
7299: <p>The <code><a href="tabular-data.html#the-tr-element">tr</a></code> start tag causes the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element
7300: to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
7301: implied; the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> and <code><a href="tabular-data.html#the-tr-element">tr</a></code> elements are
7302: then handled in a rather straight-forward manner, taking the parser
7303: through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
7304: body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
7305: row</a>" insertion modes, after which the DOM looks as
7306: follows:</p>
7307:
1.159 mike 7308: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code></li></ul></li></ul></li></ul></li></ul></li></ul><p>Here, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
7309: elements <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
1.1 mike 7310: <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, and <code><a href="tabular-data.html#the-tr-element">tr</a></code>; the <a href="#list-of-active-formatting-elements">list of active
7311: formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
7312: it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
7313: mode: in row">in row</a>".</p>
7314:
7315: <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
7316: <code><a href="tabular-data.html#the-td-element">td</a></code> element on the tree, puts a marker on the <a href="#list-of-active-formatting-elements">list
7317: of active formatting elements</a> (it also switches to the "<a href="#parsing-main-intd" title="insertion mode: in cell">in cell</a>" <a href="#insertion-mode">insertion
7318: mode</a>).</p>
7319:
1.159 mike 7320: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The marker means that when the "aaa" character tokens are seen,
1.1 mike 7321: no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
7322: node:</p>
7323:
1.159 mike 7324: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The end tags are handled in a straight-forward manner; after
1.1 mike 7325: handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
1.159 mike 7326: elements <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
1.1 mike 7327: and <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>; the <a href="#list-of-active-formatting-elements">list of active formatting
7328: elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
7329: marker having been removed by the "td" end tag token); and the
7330: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
7331: table body">in table body</a>".</p>
7332:
7333: <p>Thus it is that the "bbb" character tokens are found. These
7334: trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
7335: text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
7336: insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
7337: body">in table body</a>"). The character tokens are collected,
7338: and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
7339: seen, they are processed as a group. Since they are not all spaces,
7340: they are handled as per the "anything else" rules in the "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" insertion mode,
7341: which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
7342: body</a>" insertion mode but with <a href="#foster-parent" title="foster
7343: parent">foster parenting</a>.</p>
7344:
7345: <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
7346: active formatting elements are reconstructed</a>, a
7347: <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
7348: parent">foster parented</a>, and then the "bbb" text node is
7349: appended to it:</p>
7350:
1.159 mike 7351: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">bbb</span></li></ul></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The <a href="#stack-of-open-elements">stack of open elements</a> has on it the elements
7352: <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
1.1 mike 7353: <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, and the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> (again, note that
7354: this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
7355: formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
7356: and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
7357: mode: in table body">in table body</a>".</p>
7358:
7359: <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
7360: character">space characters</a> instead of "bbb", then those
7361: <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
7362: appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
7363:
7364: <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
7365: tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
7366: elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
7367: but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
7368: elements</a>, so the "ccc" character tokens after the table
7369: result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
7370: time after the table:</p>
7371:
1.159 mike 7372: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">bbb</span></li></ul></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">ccc</span></li></ul></li></ul></li></ul></li></ul><h5 id="scripts-that-modify-the-page-as-it-is-being-parsed"><span class="secno">9.2.8.4 </span>Scripts that modify the page as it is being parsed</h5>
1.1 mike 7373:
7374: <p><i>This section is non-normative.</i></p>
7375:
7376: <p>Consider the following markup, which for this example we will
7377: assume is the document with <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/inner</code>, being rendered as the
1.159 mike 7378: content of an <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code> in another document with the
1.1 mike 7379: <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
7380:
7381: <pre><div id=a>
7382: <script>
7383: var div = document.getElementById('a');
7384: parent.document.body.appendChild(div);
7385: </script>
7386: <script>
7387: alert(document.URL);
7388: </script>
7389: </div>
7390: <script>
7391: alert(document.URL);
7392: </script></pre>
7393:
7394: <p>Up to the first "script" end tag, before the script is parsed,
7395: the result is relatively straightforward:</p>
7396:
1.306 mike 7397: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-div-element">div</a></code> <span class="t2" title=""><code class="attribute name">id</code>="<code class="attribute value"><a href="text-level-semantics.html#the-a-element">a</a></code>"</span><ul><li class="t3"><code>#text</code>: <span title="">
7398: </span></li><li class="t1"><code><a href="semantics.html#script">script</a></code><ul><li class="t3"><code>#text</code>: <span title="">var div = document.getElementById('a'); ⏎ parent.document.body.appendChild(div);</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>After the script is parsed, though, the <code><a href="semantics.html#the-div-element">div</a></code> element
1.1 mike 7399: and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
7400:
1.159 mike 7401: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code></li></ul></li></ul><p>They are, at this point, in the <code>Document</code> of the
1.1 mike 7402: aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
7403: <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
1.306 mike 7404: <code><a href="semantics.html#the-div-element">div</a></code> element</em>.</p>
1.1 mike 7405:
7406: <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
7407: is inserted <em>into the outer <code>Document</code>
7408: object</em>.</p>
7409:
7410: <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
7411: the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
7412: object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
1.159 mike 7413: <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>.</p>
1.1 mike 7414:
7415: <p class="note">This isn't a security problem since the script that
1.306 mike 7416: moves the <code><a href="semantics.html#the-div-element">div</a></code> into the outer <code>Document</code> can
1.1 mike 7417: only do so because they have the two <code>Document</code> object
1.159 mike 7418: have the same <a href="browsers.html#origin">origin</a>.</p>
1.1 mike 7419:
7420: <p>Thus, the first alert says "http://example.com/outer".</p>
7421:
1.306 mike 7422: <p>Once the <code><a href="semantics.html#the-div-element">div</a></code> element's end tag is parsed, the
7423: <code><a href="semantics.html#the-div-element">div</a></code> element is popped off the stack, and so the next
1.1 mike 7424: <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
7425:
1.159 mike 7426: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="semantics.html#script">script</a></code><ul><li class="t3"><code>#text</code>: <span title="">alert(document.URL);</span></li></ul></li></ul></li></ul></li></ul><p>This second alert will say "http://example.com/inner".</p>
1.1 mike 7427:
7428:
7429:
1.215 mike 7430: <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3>
1.1 mike 7431:
7432: <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
7433:
7434: <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
7435:
7436: <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
7437:
7438: <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
7439:
7440: <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
7441:
7442: <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
7443:
7444: <hr><p>Data mining tools and other user agents that perform operations
1.83 mike 7445: on <code><a href="iana-considerations.html#text-html">text/html</a></code> content without running scripts,
1.1 mike 7446: evaluating CSS or XPath expressions, or otherwise exposing the
7447: resulting DOM to arbitrary content, may "support namespaces" by just
7448: asserting that their DOM node analogues are in certain namespaces,
7449: without actually exposing the above strings.</p>
7450:
7451:
7452:
7453:
7454: <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3>
7455:
7456: <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
7457: algorithm</dfn>. The algorithm takes as input a DOM
7458: <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
7459: exception.</p>
7460:
7461: <p class="note">This algorithm serializes the <em>children</em> of
7462: the node being serialized, not the node itself.</p>
7463:
7464: <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
7465: the empty string.</p></li>
7466:
7467: <li>
7468:
7469: <p>For each child node of <var title="">the node</var>, in
7470: <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
7471:
7472: </p><ol><li><p>Let <var title="">current node</var> be the child node
7473: being processed.</p></li>
7474:
7475: <li>
7476:
7477: <p>Append the appropriate string from the following list to
7478: <var title="">s</var>:</p>
7479:
7480: <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
7481:
7482: <dd>
7483:
7484: <p>Append a U+003C LESS-THAN SIGN (<code title=""><</code>)
7485: character, followed by the element's tag name. (For nodes
7486: created by the <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
7487: lowercase.)</p>
7488:
7489: <p>For each attribute that the element has, append a U+0020
7490: SPACE character, the attribute's name (which, for attributes
7491: set by the <a href="#html-parser">HTML parser</a> or by <code title="">Element.setAttributeNode()</code> or <code title="">Element.setAttribute()</code>, will be lowercase), a
7492: U+003D EQUALS SIGN (<code title="">=</code>) character, a
7493: U+0022 QUOTATION MARK (<code title="">"</code>)
7494: character, the attribute's value, <a href="#escapingString" title="escaping a
7495: string">escaped as described below</a> in <i>attribute
7496: mode</i>, and a second U+0022 QUOTATION MARK (<code title="">"</code>) character.</p>
7497:
7498: <p>While the exact order of attributes is UA-defined, and may
7499: depend on factors such as the order that the attributes were
7500: given in the original markup, the sort order must be stable,
7501: such that consecutive invocations of this algorithm serialize an
7502: element's attributes in the same order.</p>
7503:
7504: <p>Append a U+003E GREATER-THAN SIGN (<code title="">></code>)
7505: character.</p>
7506:
7507: <p>If <var title="">current node</var> is an
1.5 mike 7508: <code><a href="the-canvas-element.html#the-area-element">area</a></code>, <code><a href="semantics.html#the-base-element">base</a></code>, <code><a href="obsolete.html#basefont">basefont</a></code>,
1.1 mike 7509: <code>bgsound</code>, <code><a href="semantics.html#the-br-element">br</a></code>, <code><a href="tabular-data.html#the-col-element">col</a></code>,
1.159 mike 7510: <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>, <code><a href="obsolete.html#frame">frame</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>,
7511: <code><a href="text-level-semantics.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="forms.html#the-keygen-element">keygen</a></code>,
7512: <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#meta">meta</a></code>, <code><a href="text-level-semantics.html#the-param-element">param</a></code>,
1.5 mike 7513: <code><a href="obsolete.html#spacer">spacer</a></code>, or <code>wbr</code> element, then
1.1 mike 7514: continue on to the next child node at this point.</p> <!--
7515: also, i guess: image and isindex, but we don't list those
7516: because we don't consider those "elements", more "macros", and
7517: thus we should never serialize them -->
7518:
7519: <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42 mike 7520: <code><a href="forms.html#the-textarea-element">textarea</a></code>, or <code><a href="obsolete.html#listing">listing</a></code> element, append
1.1 mike 7521: a U+000A LINE FEED (LF) character.</p>
7522:
7523: <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
7524: serialization algorithm</a> on the <var title="">current
7525: node</var> element (thus recursing into this algorithm for
7526: that element), followed by a U+003C LESS-THAN SIGN (<code title=""><</code>) character, a U+002F SOLIDUS (<code title="">/</code>) character, the element's tag name again,
7527: and finally a U+003E GREATER-THAN SIGN (<code title="">></code>) character.</p>
7528:
7529: </dd>
7530:
7531:
7532: <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
7533: node</dt>
7534:
7535: <dd>
7536:
1.19 mike 7537: <p>If the parent of <var title="">current node</var> is a
1.42 mike 7538: <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="semantics.html#script">script</a></code>, <code><a href="obsolete.html#xmp">xmp</a></code>,
1.159 mike 7539: <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>,
1.222 mike 7540: <code><a href="obsolete.html#noframes">noframes</a></code>, or <code><a href="obsolete.html#plaintext">plaintext</a></code> element, or
7541: if the parent of <var title="">current node</var> is
7542: <code><a href="semantics.html#the-noscript-element">noscript</a></code> element and <a href="browsers.html#concept-n-script" title="concept-n-script">scripting is enabled</a> for the
7543: node, then append the value of <var title="">current
7544: node</var>'s <code title="">data</code> IDL attribute
7545: literally.</p>
1.1 mike 7546:
7547: <p>Otherwise, append the value of <var title="">current
1.192 mike 7548: node</var>'s <code title="">data</code> IDL attribute, <a href="#escapingString" title="escaping a string">escaped as described
1.1 mike 7549: below</a>.</p>
7550:
7551: </dd>
7552:
7553:
7554: <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
7555:
7556: <dd>
7557:
7558: <p>Append the literal string <code><!--</code> (U+003C
7559: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
1.192 mike 7560: U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1 mike 7561: attribute, followed by the literal string <code>--></code>
7562: (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
7563: SIGN).</p>
7564:
7565: </dd>
7566:
7567:
7568: <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
7569:
7570: <dd>
7571:
7572: <p>Append the literal string <code><?</code> (U+003C
7573: LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
1.192 mike 7574: of <var title="">current node</var>'s <code title="">target</code> IDL attribute, followed by a single
7575: U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1 mike 7576: attribute, followed by a single U+003E GREATER-THAN SIGN
7577: character ('>').</p>
7578:
7579: </dd>
7580:
7581:
7582: <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
7583:
7584: <dd>
7585:
7586: <p>Append the literal string <code><!DOCTYPE</code> (U+003C
7587: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
7588: LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
7589: LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
7590: LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
7591: LETTER E), followed by a space (U+0020 SPACE), followed by the
1.192 mike 7592: value of <var title="">current node</var>'s <code title="">name</code> IDL attribute, followed by the literal
1.1 mike 7593: string <code>></code> (U+003E GREATER-THAN SIGN).</p>
7594:
7595: </dd>
7596:
7597:
7598: </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
7599: occur as children of elements. If, despite this, they somehow do
7600: occur, this algorithm must raise an
7601: <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
7602:
7603: </li>
7604:
7605: </ol></li>
7606:
7607: <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
7608:
7609: </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
7610: purposes of the algorithm above) consists of replacing any
7611: occurrences of the "<code title="">&</code>" character by the
7612: string "<code title="">&amp;</code>", any occurrences of the
7613: U+00A0 NO-BREAK SPACE character by the string "<code title="">&nbsp;</code>", and, if the algorithm was invoked in
7614: the <i>attribute mode</i>, any occurrences of the "<code title="">"</code>" character by the string "<code title="">&quot;</code>", or if it was not, any occurrences of
7615: the "<code title=""><</code>" character by the string "<code title="">&lt;</code>", any occurrences of the "<code title="">></code>" character by the string "<code title="">&gt;</code>".</p>
7616:
7617: <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
7618: agent, and are therefore not covered in the algorithm above.</p>
7619:
7620: <p class="note">It is possible that the output of this algorithm, if
7621: parsed with an <a href="#html-parser">HTML parser</a>, will not return the
7622: original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
7623: element to which a <code title="">Comment</code> node has been
7624: appended is serialized and the output is then reparsed, the comment
7625: will end up being displayed in the text field. Similarly, if, as a
7626: result of DOM manipulation, an element contains a comment that
7627: contains the literal string "<code title="">--></code>", then
7628: when the result of serializing the element is parsed, the comment
7629: will be truncated at that point and the rest of the comment will be
7630: interpreted as markup. More examples would be making a
7631: <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
7632: "<code></script></code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
7633: contains a <code><a href="semantics.html#the-ul-element">ul</a></code> element (as the <code><a href="semantics.html#the-ul-element">ul</a></code> element's
7634: <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
7635: tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
7636:
7637:
7638: <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3>
7639:
7640: <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
7641: algorithm</dfn>. The algorithm optionally takes as input an
7642: <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
7643: parser, as well as <var title="">input</var>, a string to parse, and
7644: returns a list of zero or more nodes.</p>
7645:
7646: <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
7647: in the parser section are parts that only occur if the parser was
7648: created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
7649: with such markings for informational purposes only; such markings
7650: have no normative weight. If it is possible for a condition
7651: described as a <a href="#fragment-case">fragment case</a> to occur even when the
7652: parser wasn't created for the purposes of handling this algorithm,
7653: then that is an error in the specification.</p>
7654:
7655: <ol><li>
7656:
7657: <p>Create a new <code>Document</code> node, and mark it as being
7658: an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
7659:
7660: </li>
7661:
7662: <li>
7663:
7664: <p>If there is a <var title="">context</var> element, and the
7665: <code>Document</code> of the <var title="">context</var> element
7666: is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
7667: be in <a href="dom.html#quirks-mode">quirks mode</a>. Otherwise, if there is a <var title="">context</var> element, and the <code>Document</code> of
7668: the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
7669: mode</a>, then let the <code>Document</code> be in
7670: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
7671: <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
7672:
7673: </li>
7674:
7675: <li>
7676:
7677: <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
7678: the just created <code>Document</code> node.</p>
7679:
7680: </li>
7681:
7682: <li>
7683:
7684: <p>If there is a <var title="">context</var> element, run these
7685: substeps:</p>
7686:
7687: <ol><li>
7688:
7689: <p>Set the <a href="#html-parser">HTML parser</a>'s <a href="#tokenization">tokenization</a>
7690: stage's <a href="#content-model-flag">content model flag</a> according to the <var title="">context</var> element, as follows:</p>
7691:
1.159 mike 7692: <dl class="switch"><dt>If it is a <code><a href="semantics.html#the-title-element-0">title</a></code> or <code><a href="forms.html#the-textarea-element">textarea</a></code>
1.1 mike 7693: element</dt>
7694:
7695: <dd>Set the <a href="#content-model-flag">content model flag</a> to
7696: the RCDATA state.</dd>
7697:
7698:
7699: <dt>If it is a <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="semantics.html#script">script</a></code>,
1.159 mike 7700: <code><a href="obsolete.html#xmp">xmp</a></code>, <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>, or
1.5 mike 7701: <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1 mike 7702:
7703: <dd>Set the <a href="#content-model-flag">content model flag</a> to
1.91 mike 7704: the RAWTEXT state.</dd>
1.1 mike 7705:
7706:
7707: <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
7708:
7709: <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, set the
1.91 mike 7710: <a href="#content-model-flag">content model flag</a> to the RAWTEXT
1.1 mike 7711: state. Otherwise, set the <a href="#content-model-flag">content model flag</a> to the
7712: PCDATA state.</dd>
7713:
7714:
1.42 mike 7715: <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1 mike 7716:
7717: <dd>Set the <a href="#content-model-flag">content model flag</a> to
7718: PLAINTEXT.</dd>
7719:
7720:
7721: <dt>Otherwise</dt>
7722:
7723: <dd>Leave the <a href="#content-model-flag">content model flag</a> in the PCDATA
7724: state.</dd>
7725:
7726: </dl></li>
7727:
7728: <li>
7729:
1.159 mike 7730: <p>Let <var title="">root</var> be a new <code><a href="semantics.html#the-html-element-0">html</a></code> element
1.1 mike 7731: with no attributes.</p>
7732:
7733: </li>
7734:
7735: <li>
7736:
7737: <p>Append the element <var title="">root</var> to the
7738: <code>Document</code> node created above.</p>
7739:
7740: </li>
7741:
7742: <li>
7743:
7744: <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
7745: it contains just the single element <var title="">root</var>.</p>
7746:
7747: </li>
7748:
7749: <li>
7750:
7751: <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
7752: parser's insertion mode appropriately</a>.</p>
7753:
7754: <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
7755:
7756: </li>
7757:
7758: <li>
7759:
7760: <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
7761: to the nearest node to the <var title="">context</var> element
7762: that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
7763: ancestor chain, and including the element itself, if it is a
7764: <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
7765: <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
7766:
7767: </li>
7768:
7769: </ol></li>
7770:
7771: <li>
7772:
7773: <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
7774: parser</a> just created the <var title="">input</var>. The
7775: encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
7776: <i>irrelevant</i>.</p>
7777:
7778: </li>
7779:
7780: <li>
7781:
7782: <p>Start the parser and let it run until it has consumed all the
7783: characters just inserted into the input stream.</p>
7784:
7785: </li>
7786:
7787: <li>
7788:
7789: <p>If there is a <var title="">context</var> element, return the
7790: child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
7791: order</a>.</p>
7792:
7793: <p>Otherwise, return the children of the <code>Document</code>
7794: object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
7795:
7796: </li>
7797:
1.123 mike 7798: </ol></div></body></html>
Webmaster