Annotation of html5/spec/syntax.html, revision 1.538
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; }
1.475 mike 30: table tbody th { text-align: left; }
1.1 mike 31: table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
32: blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
33:
34: .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
35: .matrix, .matrix td { border: none; text-align: right; }
36: .matrix { margin-left: 2em; }
37: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
38: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
39: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
40:
41: .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
42: img.extra { float: right; }
43: pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
44: pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
45: pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
46: pre.css:first-line { color: #AAAA50; }
47: dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #EEFFEE; }
48: hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
49: dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
50: dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
51: dl.domintro dd p { margin: 0.5em 0; }
52: dl.switch { padding-left: 2em; }
53: dl.switch > dt { text-indent: -1.5em; }
54: dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
55: dl.triple { padding: 0 0 0 1em; }
56: dl.triple dt, dl.triple dd { margin: 0; display: inline }
57: dl.triple dt:after { content: ':'; }
58: dl.triple dd:after { content: '\A'; white-space: pre; }
59: .diff-old { text-decoration: line-through; color: silver; background: transparent; }
60: .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
61: a .diff-new { border-bottom: 1px blue solid; }
62:
63: h2 { page-break-before: always; }
64: h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
65: h1 + h2, hr + h2.no-toc { page-break-before: auto; }
66:
67: p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
68:
69: div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
70: div.head p { margin: 0; }
71: div.head h1 { margin: 0; }
72: div.head .logo { float: right; margin: 0 1em; }
73: div.head .logo img { border: none } /* remove border from top image */
74: div.head dl { margin: 1em 0; }
75: p.copyright { font-size: x-small; font-style: oblique; margin: 0; }
76:
77: body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
78: body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
79: body > .toc > li > * { margin-bottom: 0.5em; }
80: body > .toc > li > * > li > * { margin-bottom: 0.25em; }
81: .toc, .toc li { list-style: none; }
82:
83: .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
84: .brief li { margin: 0; padding: 0; }
85: .brief li p { margin: 0; padding: 0; }
86:
87: .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
88: .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
89: .category-list li { display: inline; }
90: .category-list li:not(:last-child)::after { content: ', '; }
91: .category-list li > span, .category-list li > a { text-transform: lowercase; }
92: .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
93:
94: .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
95: .XXX > :first-child { margin-top: 0; }
96: p .XXX { line-height: 3em; }
1.159 mike 97: .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
98: .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
99: .annotation :link, .annotation :visited { color: inherit; }
100: .annotation :link:hover, .annotation :visited:hover { background: transparent; }
101: .annotation span { border: none ! important; }
1.1 mike 102: .note { color: green; background: transparent; font-family: sans-serif; }
103: .warning { color: red; background: transparent; }
104: .note, .warning { font-weight: bolder; font-style: italic; }
105: p.note, div.note { padding: 0.5em 2em; }
106: span.note { padding: 0 2em; }
107: .note p:first-child, .warning p:first-child { margin-top: 0; }
108: .note p:last-child, .warning p:last-child { margin-bottom: 0; }
109: .warning:before { font-style: normal; }
110: p.note:before { content: 'Note: '; }
111: p.warning:before { content: '\26A0 Warning! '; }
112:
113: .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
114: .bookkeeping { font-size: 0.8em; margin: 2em 0; }
115: .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
116:
117: h4 { position: relative; z-index: 3; }
118: h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
119: .element {
120: background: #EEEEFF;
121: color: black;
122: margin: 0 0 1em 0.15em;
123: padding: 0 1em 0.25em 0.75em;
124: border-left: solid #9999FF 0.25em;
125: position: relative;
126: z-index: 1;
127: }
128: .element:before {
129: position: absolute;
130: z-index: 2;
131: top: 0;
132: left: -1.15em;
133: height: 2em;
134: width: 0.9em;
135: background: #EEEEFF;
136: content: ' ';
137: border-style: none none solid solid;
138: border-color: #9999FF;
139: border-width: 0.25em;
140: }
141:
1.149 mike 142: .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
143: td > .example:only-child { margin: 0 0 0 0.1em; }
1.1 mike 144:
145: .tall-and-narrow {
146: font-size: 0.6em;
147: column-width: 25em;
148: column-gap: 1em;
149: -moz-column-width: 25em;
150: -moz-column-gap: 1em;
151: -webkit-column-width: 25em;
152: -webkit-column-gap: 1em;
153: }
154:
155: ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
156: ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
157: ul.domTree li li { list-style: none; }
158: 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; }
159: 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; }
160: ul.domTree span { font-style: italic; font-family: serif; }
161: ul.domTree .t1 code { color: purple; font-weight: bold; }
162: ul.domTree .t2 { font-style: normal; font-family: monospace; }
163: ul.domTree .t2 .name { color: black; font-weight: bold; }
164: ul.domTree .t2 .value { color: blue; font-weight: normal; }
165: ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
166: ul.domTree .t7 code, .domTree .t8 code { color: green; }
167: ul.domTree .t10 code { color: teal; }
168:
1.267 mike 169: </style><style type="text/css">
170:
1.292 mike 171: .applies thead th > * { display: block; }
172: .applies thead code { display: block; }
173: .applies tbody th { whitespace: nowrap; }
174: .applies td { text-align: center; }
175: .applies .yes { background: yellow; }
176:
1.267 mike 177: .matrix, .matrix td { border: none; text-align: right; }
178: .matrix { margin-left: 2em; }
179:
180: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
181: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
182: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
183:
184: #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
185: #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
186: #table-example-1 caption { padding-bottom: 0.5em; }
187: #table-example-1 thead, #table-example-1 tbody { border: none; }
188: #table-example-1 th, #table-example-1 td { border: solid thin; }
189: #table-example-1 th { font-weight: normal; }
190: #table-example-1 td { border-style: none solid; vertical-align: top; }
191: #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
192: #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
193: #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
194: #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
195: #table-example-1 tbody td:first-child::after { content: leader(". "); }
196: #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
197: #table-example-1 tbody td:first-child + td { width: 10em; }
198: #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
199: #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
200:
201: .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
202: .apple-table-examples * { font-family: "Times", serif; }
203: .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
204: .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
205: .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
206: .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
207: .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
208: .apple-table-examples td { text-align: right; vertical-align: top; }
209: .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
210: .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
211: .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
212: .apple-table-examples sup { line-height: 0; }
213:
1.235 mike 214: </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 215: <script src="link-fixup.js"></script>
216: <link href="comms.html" title="8 Communication" rel="prev">
217: <link href="spec.html#contents" title="Table of contents" rel="index">
1.1 mike 218: <link href="named-character-references.html" title="9.6 Named character references" rel="next">
1.16 mike 219: </head><body onload="fixBrokenLink(); fixBrokenLink()"><div class="head">
1.1 mike 220: <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 221: <h1>HTML5</h1>
1.1 mike 222: <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 223: </div><nav>
1.1 mike 224: <a href="comms.html">← 8 Communication</a> –
1.2 mike 225: <a href="spec.html#contents">Table of contents</a> –
1.1 mike 226: <a href="named-character-references.html">9.6 Named character references →</a>
1.538 ! mike 227: </nav><p>This is revision 1.3321.</p>
1.11 mike 228:
1.1 mike 229:
1.123 mike 230: <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 231: <code><a href="iana-considerations.html#text-html">text/html</a></code> resources. Rules for XML resources are
1.1 mike 232: discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.159 mike 233: 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 234:
235: <p><i>This section only applies to documents, authoring tools, and
236: markup generators. In particular, it does not apply to conformance
237: checkers; conformance checkers must use the requirements given in
238: the next section ("parsing HTML documents").</i></p>
239:
1.123 mike 240: </div><p>Documents must consist of the following parts, in the given
241: order:</p><ol><li>Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.</li>
1.1 mike 242:
243: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
244: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
245:
246: <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
247:
248: </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
249: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
250:
1.159 mike 251: <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 252:
253: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
254: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
255:
256: </ol><p>The various types of content mentioned above are described in the
1.123 mike 257: 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 258: declarations</a> are to be serialized, as discussed in the
1.123 mike 259: section on that topic.</p><div class="note">
1.1 mike 260:
1.159 mike 261: <p>Space characters before the root <code><a href="semantics.html#the-html-element-0">html</a></code> element, and
262: space characters at the start of the <code><a href="semantics.html#the-html-element-0">html</a></code> element and
263: before the <code><a href="semantics.html#the-head-element-0">head</a></code> element, will be dropped when the
1.1 mike 264: document is parsed; space characters <em>after</em> the root
1.159 mike 265: <code><a href="semantics.html#the-html-element-0">html</a></code> element will be parsed as if they were at the end
266: of the <code><a href="semantics.html#the-body-element-0">body</a></code> element. Thus, space characters around the
1.1 mike 267: root element do not round-trip.</p>
268:
269: <p>It is suggested that newlines be inserted after the DOCTYPE,
270: after any comments that are before the root element, after the
1.159 mike 271: <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
272: that are inside the <code><a href="semantics.html#the-html-element-0">html</a></code> element but before the
273: <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 274:
1.123 mike 275: </div><p>Many strings in the HTML syntax (e.g. the names of elements and
1.1 mike 276: their attributes) are case-insensitive, but only for characters in
277: the ranges U+0041 .. U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
278: LETTER Z) and U+0061 .. U+007A (LATIN SMALL LETTER A to LATIN SMALL
279: LETTER Z). For convenience, in this section this is just referred to
1.168 mike 280: 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 281: but required, header.</p><p class="note">DOCTYPEs are required for legacy reasons. When
1.1 mike 282: omitted, browsers tend to use a different rendering mode that is
283: incompatible with some specifications. Including the DOCTYPE in a
284: document ensures that the browser makes a best-effort attempt at
1.123 mike 285: following the relevant specifications.</p><p>A DOCTYPE must consist of the following characters, in this
286: order:</p><ol class="brief"><li>A U+003C LESS-THAN SIGN (<code><</code>) character.</li>
1.1 mike 287: <li>A U+0021 EXCLAMATION MARK (<code>!</code>) character.</li>
288: <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>
289: <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
290: <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>
291: <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> (defined below).</li>
292: <li>Zero or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
293: <li>A U+003E GREATER-THAN SIGN (<code>></code>) character.</li>
294: </ol><p class="note">In other words, <code><!DOCTYPE HTML></code>,
1.123 mike 295: case-insensitively.</p><p>For the purposes of HTML generators that cannot output HTML
1.1 mike 296: markup with the short DOCTYPE "<code title=""><!DOCTYPE
297: HTML></code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
298: into the DOCTYPE (in the position defined above). This string must
1.123 mike 299: 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 300: <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>
1.444 mike 301: <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.1 mike 302: <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
1.465 mike 303: <li>The literal string "<code><a href="infrastructure.html#about:legacy-compat">about:legacy-compat</a></code>".</li>
1.1 mike 304: <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>
305: </ol><p class="note">In other words, <code><!DOCTYPE HTML SYSTEM
306: "about:legacy-compat"></code> or <code><!DOCTYPE HTML SYSTEM
307: 'about:legacy-compat'></code>, case-insensitively except for the bit
1.123 mike 308: in quotes.</p><p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1 mike 309: the document is generated from a system that cannot output the
1.373 mike 310: 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>: <a href="#void-elements">void elements</a>,
311: <a href="#raw-text-elements">raw text elements</a>, <a href="#rcdata-elements">RCDATA elements</a>,
312: <a href="#foreign-elements">foreign elements</a>, and <a href="#normal-elements">normal elements</a>.</p><dl><dt><dfn id="void-elements">Void elements</dfn></dt>
1.1 mike 313:
314: <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 315: <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>,
316: <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 317: <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 318: <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 319:
1.373 mike 320: <dt><dfn id="raw-text-elements">Raw text elements</dfn></dt>
1.1 mike 321:
322: <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 323: noscript don't count as raw text for syntax purposes -->
1.1 mike 324:
1.373 mike 325: <dt><dfn id="rcdata-elements">RCDATA elements</dfn></dt>
1.1 mike 326:
1.159 mike 327: <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 328:
1.373 mike 329: <dt><dfn id="foreign-elements">Foreign elements</dfn></dt>
1.1 mike 330:
331: <dd>Elements from the <a href="#mathml-namespace">MathML namespace</a>
332: and the <a href="#svg-namespace">SVG namespace</a>.</dd>
333:
1.373 mike 334: <dt><dfn id="normal-elements">Normal elements</dfn></dt>
1.1 mike 335:
336: <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
337: elements.</dd>
338:
339: </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.373 mike 340: and end of elements in the markup. <a href="#raw-text-elements" title="raw text
341: elements">Raw text</a>, <a href="#rcdata-elements" title="RCDATA
342: elements">RCDATA</a>, and <a href="#normal-elements" title="normal
343: elements">normal</a> elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to indicate where they
344: begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> to
345: indicate where they end. The start and end tags of certain
346: <a href="#normal-elements">normal elements</a> can be <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>, as described
1.1 mike 347: later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
348: elements</a> only have a start tag; end tags must not be
1.373 mike 349: specified for <a href="#void-elements">void elements</a>. <a href="#foreign-elements">Foreign
350: elements</a> must either have a start tag and an end tag, or a
351: start tag that is marked as self-closing, in which case they must
352: not have an end tag.</p><p>The contents of the element must be placed between just after the
1.1 mike 353: start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
354: in certain cases</a>) and just before the end tag (which again,
355: <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
356: cases</a>). The exact allowed contents of each individual element
357: depends on the content model of that element, as described earlier
358: in this specification. Elements must not contain content that their
359: content model disallows. In addition to the restrictions placed on
360: the contents by those content models, however, the five types of
1.123 mike 361: 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 362: no end tag, no content can be put between the start tag and the end
1.373 mike 363: tag).</p><p><a href="#raw-text-elements">Raw text elements</a> can have <a href="#syntax-text" title="syntax-text">text</a>, though it has <a href="#cdata-rcdata-restrictions">restrictions</a> described
364: below.</p><p><a href="#rcdata-elements">RCDATA elements</a> can have <a href="#syntax-text" title="syntax-text">text</a> and <a href="#syntax-charref" title="syntax-charref">character references</a>, but the text
365: must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
1.1 mike 366: There are also <a href="#cdata-rcdata-restrictions">further
1.373 mike 367: restrictions</a> described below.</p><p><a href="#foreign-elements">Foreign elements</a> whose start tag is marked as
368: self-closing can't have any contents (since, again, as there's no
369: end tag, no content can be put between the start tag and the end
370: tag). <a href="#foreign-elements">Foreign elements</a> whose start tag is <em>not</em>
371: marked as self-closing can have <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
1.1 mike 372: contain the character U+003C LESS-THAN SIGN (<code><</code>) or
373: an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.374 mike 374: ampersand</a>.</p><div class="note">
375:
376: <p>The HTML syntax does not support namespace
377: declarations, even in <a href="#foreign-elements">foreign elements</a>.</p>
378:
379: <p>For instance, consider the following HTML fragment:</p>
380:
381: <pre><p>
382: <svg>
383: <metadata>
384: <!-- this is invalid -->
385: <cdr:license xmlns:cdr="http://www.example.com/cdr/metadata" name="MIT"/>
386: </metadata>
387: </svg>
388: </p></pre>
389:
390: <p>The innermost element, <code title="">cdr:license</code>, is
391: actually in the SVG namespace, as the "<code title="">xmlns:cdr</code>" attribute has no effect (unlike in
392: XML). In fact, as the comment in the fragment above says, the
393: fragment is actually non-conforming. This is because the SVG
394: specification does not define any elements called "<code title="">cdr:license</code>" in the SVG namespace.</p>
395:
396: </div><p><a href="#normal-elements">Normal elements</a> can have <a href="#syntax-text" title="syntax-text">text</a>, <a href="#syntax-charref" title="syntax-charref">character references</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
1.1 mike 397: contain the character U+003C LESS-THAN SIGN (<code><</code>) or
398: an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.373 mike 399: ampersand</a>. Some <a href="#normal-elements">normal elements</a> also have <a href="#element-restrictions">yet more restrictions</a> on what
1.1 mike 400: content they are allowed to hold, beyond the restrictions imposed by
401: the content model and those described in this paragraph. Those
1.123 mike 402: restrictions are described below.</p><p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1 mike 403: giving the element's name. HTML elements all have names that only
1.464 mike 404: use characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT
405: NINE (9), U+0061 LATIN SMALL LETTER A to U+007A LATIN SMALL LETTER
406: Z, and U+0041 LATIN CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER
407: Z. In the HTML syntax, tag names, even those for <a href="#foreign-elements">foreign
1.462 mike 408: elements</a>, may be written with any mix of lower- and uppercase
409: letters that, when converted to all-lowercase, matches the element's
410: 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 411: following format:</p><ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.1 mike 412: SIGN (<code><</code>).</li>
413:
414: <li>The next few characters of a start tag must be the element's
415: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
416:
417: <li>If there are to be any attributes in the next step, there must
418: first be one or more <a href="infrastructure.html#space-character" title="space character">space
419: characters</a>.</li>
420:
421: <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
422: below. Attributes may be separated from each other by one or more
423: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
424:
425: <li>After the attributes, there may be one or more <a href="infrastructure.html#space-character" title="space character">space characters</a>. (Some attributes
426: are required to be followed by a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes section</a> below.)</li>
427:
428: <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
1.373 mike 429: or if the element is a <a href="#foreign-elements" title="foreign elements">foreign
430: element</a>, then there may be a single U+002F SOLIDUS
431: (<code>/</code>) character. This character has no effect on
432: <a href="#void-elements">void elements</a>, but on <a href="#foreign-elements">foreign elements</a> it
433: marks the start tag as self-closing.</li>
1.1 mike 434:
435: <li>Finally, start tags must be closed by a U+003E GREATER-THAN
436: SIGN (<code>></code>) character.</li>
437:
1.123 mike 438: </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
439: following format:</p><ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.1 mike 440: SIGN (<code><</code>).</li>
441:
442: <li>The second character of an end tag must be a U+002F SOLIDUS
443: (<code>/</code>).</li>
444:
445: <li>The next few characters of an end tag must be the element's
446: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
447:
448: <li>After the tag name, there may be one or more <a href="infrastructure.html#space-character" title="space
449: character">space characters</a>.</li>
450:
451: <li>Finally, end tags must be closed by a U+003E GREATER-THAN
452: SIGN (<code>></code>) character.</li>
453:
1.123 mike 454: </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
455: 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 456: one or more characters other than the <a href="infrastructure.html#space-character" title="space
457: character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
458: MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
459: (>), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters,
460: the control characters, and any characters that are not defined by
1.462 mike 461: Unicode. In the HTML syntax, attribute names, even those for
462: <a href="#foreign-elements">foreign elements</a>, may be written with any mix of lower-
463: and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.123 mike 464: 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 465: 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 466: 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 467:
468: <dd>
469:
470: <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
471: name</a>.</p>
472:
473: <div class="example">
474:
475: <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
476: the empty attribute syntax:</p>
477:
478: <pre><input <em>disabled</em>></pre>
479:
480: </div>
481:
482: <p>If an attribute using the empty attribute syntax is to be
483: followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
484: character</a> separating the two.</p>
485:
486: </dd>
487:
1.2 mike 488: <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1 mike 489:
490: <dd>
491:
492: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
493: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
494: characters</a>, followed by a single U+003D EQUALS SIGN
495: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
496: character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
497: addition to the requirements given above for attribute values,
498: must not contain any literal <a href="infrastructure.html#space-character" title="space character">space
499: characters</a>, any U+0022 QUOTATION MARK (<code>"</code>)
500: characters, U+0027 APOSTROPHE (<code>'</code>) characters,
501: U+003D EQUALS SIGN (<code>=</code>) characters, U+003C LESS-THAN
1.463 mike 502: SIGN (<code><</code>) characters, U+003E GREATER-THAN SIGN
503: (<code>></code>) characters, or U+0060 GRAVE ACCENT (`)
504: characters, and must not be the empty string.</p>
505:
506: <!-- The ` character is in this list on a temporary basis, waiting
507: for IE to fix it's parsing bug whereby it treats ` as an
508: attribute value delimiter. Otherwise, escaping software that
509: tries to be clever and not use quotes when it doesn't need to
510: could be tricked by an attacker.
511:
512: Posit a site that allows the user to input text that is used
513: verbatim in two attributes, such that the user can set the
514: first attribute's value to:
515:
516: `
517:
518: ...and the second to:
519:
520: ` onload='...payload...' end=x
521:
522: ...with the assumption that the site is going to not quote
523: the first one, and quote the second one with double quotes:
524:
525: <body title=` class="` onload='...payload...' end=x">
526:
527: In IE, this is treated as:
528:
529: <body title=' class="'
530: onload='...payload...'
531: end='x"'>
532:
533: -->
534:
1.1 mike 535:
536: <div class="example">
537:
538: <p>In the following example, the <code title="attr-input-value"><a href="forms.html#attr-input-value">value</a></code> attribute is given
539: with the unquoted attribute value syntax:</p>
540:
541: <pre><input <em>value=yes</em>></pre>
542:
543: </div>
544:
545: <p>If an attribute using the unquoted attribute syntax is to be
1.101 mike 546: followed by another attribute or by the optional U+002F SOLIDUS
1.464 mike 547: 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 548: must be a <a href="infrastructure.html#space-character">space character</a> separating the two.</p>
549:
550: </dd>
551:
552: <dt>Single-quoted attribute value syntax</dt>
553:
554: <dd>
555:
556: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
557: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
558: characters</a>, followed by a single U+003D EQUALS SIGN
559: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
560: character">space characters</a>, followed by a single U+0027
561: APOSTROPHE (<code>'</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
562: addition to the requirements given above for attribute values,
563: must not contain any literal U+0027 APOSTROPHE (<code>'</code>)
564: characters, and finally followed by a second single U+0027
565: APOSTROPHE (<code>'</code>) character.</p>
566:
567: <div class="example">
568:
569: <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
570: single-quoted attribute value syntax:</p>
571:
572: <pre><input <em>type='checkbox'</em>></pre>
573:
574: </div>
575:
576: <p>If an attribute using the single-quoted attribute syntax is to
577: be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
578: character</a> separating the two.</p>
579:
580: </dd>
581:
582: <dt>Double-quoted attribute value syntax</dt>
583:
584: <dd>
585:
586: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
587: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
588: characters</a>, followed by a single U+003D EQUALS SIGN
589: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
590: character">space characters</a>, followed by a single U+0022
591: QUOTATION MARK (<code>"</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
592: addition to the requirements given above for attribute values,
593: must not contain any literal U+0022 QUOTATION MARK
594: (<code>"</code>) characters, and finally followed by a second
595: single U+0022 QUOTATION MARK (<code>"</code>) character.</p>
596:
597: <div class="example">
598:
599: <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
600: double-quoted attribute value syntax:</p>
601:
602: <pre><input <em>name="be evil"</em>></pre>
603:
604: </div>
605:
606: <p>If an attribute using the double-quoted attribute syntax is to
607: be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
608: character</a> separating the two.</p>
609:
610: </dd>
611:
612: </dl><p>There must never be two or more attributes on the same start tag
613: whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.462 mike 614: each other.</p><hr><p>When a <a href="#foreign-elements" title="foreign elements">foreign element</a> has
615: one of the namespaced attributes given by the local name and
616: namespace of the first and second cells of a row from the following
617: table, it must be written using the name given by the third cell
618: from the same row.</p><table><thead><tr><th> Local name </th><th> Namespace </th><th> Attribute name
619: </th></tr></thead><tbody><tr><td> <code title="">actuate</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:actuate</code>
620: </td></tr><tr><td> <code title="">arcrole</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:arcrole</code>
621: </td></tr><tr><td> <code title="">href</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:href</code>
622: </td></tr><tr><td> <code title="">role</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:role</code>
623: </td></tr><tr><td> <code title="">show</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:show</code>
624: </td></tr><tr><td> <code title="">title</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:title</code>
625: </td></tr><tr><td> <code title="">type</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:type</code>
626: </td></tr><tr><td> <code title="">base</code> </td><td> <a href="#xml-namespace">XML namespace</a> <!-- attr-xml-base --> </td><td> <code title="">xml:base</code>
627: </td></tr><tr><td> <code title="">lang</code> </td><td> <a href="#xml-namespace">XML namespace</a> </td><td> <code title="">xml:lang</code>
628: </td></tr><tr><td> <code title="">space</code> </td><td> <a href="#xml-namespace">XML namespace</a> </td><td> <code title="">xml:space</code>
629: </td></tr><tr><td> <code title="">xmlns</code> </td><td> <a href="#xmlns-namespace">XMLNS namespace</a> </td><td> <code title="">xmlns</code>
630: </td></tr><tr><td> <code title="">xlink</code> </td><td> <a href="#xmlns-namespace">XMLNS namespace</a> </td><td> <code title="">xmlns:xlink</code>
631: </td></tr></tbody></table><p>No other namespaced attribute can be expressed in the <a href="#syntax">the
632: HTML syntax</a>.</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 633: is not present; it is implied, but it is still there. An HTML
1.159 mike 634: document always has a root <code><a href="semantics.html#the-html-element-0">html</a></code> element, even if the
1.1 mike 635: string <code title=""><html></code> doesn't appear anywhere in
1.159 mike 636: 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
637: 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
638: tag</a> may be omitted if the <code><a href="semantics.html#the-html-element-0">html</a></code> element is not
639: 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 640: element is empty, or--> if the first thing inside the
1.159 mike 641: <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
642: tag</a> may be omitted if the <code><a href="semantics.html#the-head-element-0">head</a></code> element is not
643: 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
644: 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 645: 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 646: 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 647: <code><a href="semantics.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
648: tag is present, the parser makes <style> and <script> elements
649: between </head> and <body> end up in the <head> instead of implying
1.159 mike 650: 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
651: 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 652: 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 653: tag</a> may be omitted if the <code><a href="semantics.html#the-li-element">li</a></code> element is
654: immediately followed by another <code><a href="semantics.html#the-li-element">li</a></code> element or if there
1.422 mike 655: is no more content in the parent element.</p><!-- </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 656: tag</a> may be omitted if the <code><a href="semantics.html#the-dt-element">dt</a></code> element is
657: immediately followed by another <code><a href="semantics.html#the-dt-element">dt</a></code> element or a
1.123 mike 658: <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 659: tag</a> may be omitted if the <code><a href="semantics.html#the-dd-element">dd</a></code> element is
660: immediately followed by another <code><a href="semantics.html#the-dd-element">dd</a></code> element or a
661: <code><a href="semantics.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.123 mike 662: 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 663: tag</a> may be omitted if the <code><a href="semantics.html#the-p-element">p</a></code> element is
664: immediately followed by an <code><a href="semantics.html#the-address-element">address</a></code>,
665: <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 666: <!--v2DATAGRID <code>datagrid</code>,--> <code><a href="obsolete.html#dir">dir</a></code>,
1.306 mike 667: <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 668: <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>,
669: <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>,
670: <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>,
671: <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>,
672: <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 673: <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>,
674: element, or if there is no more content in the parent element and
1.123 mike 675: 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 676: tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element is
677: 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 678: 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 679: tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element is
680: 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 681: 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 682: <select>; commented out text below can handle the non-<select> case
1.123 mike 683: 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 684: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
685: <code>select</code> element and--> is immediately followed by
686: another <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
687: that are ancestors of the <code>optgroup</code> element, up to and
688: including the first ancestor element that is not an
689: <code>optgroup</code> element, have no more content--> there is no
1.123 mike 690: more content in the parent element.</p><!-- so e.g. the max number of </optgroup>s are omitted here:
1.1 mike 691: <select><optgroup></select>
692: <p id=x><optgroup></optgroup>x</p>
693: <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
694: <p><optgroup id=x><optgroup></optgroup>x</p>
695: <p><optgroup><optgroup id=x>x</p>
1.123 mike 696: --><!-- </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 697: tag</a> may be omitted if the <code><a href="forms.html#the-option-element">option</a></code> element is
698: immediately followed by another <code><a href="forms.html#the-option-element">option</a></code> element, or if
699: it is immediately followed by an <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or
1.123 mike 700: 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 701: first thing inside the <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is a
702: <code><a href="tabular-data.html#the-col-element">col</a></code> element, and if the element is not immediately
703: 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 704: 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 705: <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.123 mike 706: <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 707: tag</a> may be omitted if the <code><a href="tabular-data.html#the-thead-element">thead</a></code> element is
708: 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 709: 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 710: first thing inside the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is a
711: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, and if the element is not immediately
712: 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
713: <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
714: tag</a> has been omitted. (It can't be omitted if the element is
1.123 mike 715: 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 716: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is
717: 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 718: 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 719: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element is
720: immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, or if there is
1.123 mike 721: 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 722: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
723: immediately followed by another <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, or if there
1.123 mike 724: 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 725: tag</a> may be omitted if the <code><a href="tabular-data.html#the-td-element">td</a></code> element is
726: 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 727: 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 728: tag</a> may be omitted if the <code><a href="tabular-data.html#the-th-element">th</a></code> element is
729: 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 730: 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
731: 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
732: 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 733: elements, even though these elements are technically allowed inside
734: <code><a href="tabular-data.html#the-table-element">table</a></code> elements according to the content models
735: described in this specification. (If a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
736: 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 737: 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
738: placed immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
1.1 mike 739: 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>
740: elements. This does not affect the processing of the element. The
1.304 mike 741: otherwise optional <a href="#syntax-newlines" title="syntax-newlines">newline</a>
1.381 mike 742: <em>must</em> be included if the element's contents themselves start
743: with a <a href="#syntax-newlines" title="syntax-newlines">newline</a> (because
744: otherwise the leading newline in the contents would be treated like
745: the optional newline, and ignored).</p><div class="example">
1.1 mike 746: <p>The following two <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
747: <pre><pre>Hello</pre></pre>
748: <pre><pre><br>Hello</pre></pre>
1.373 mike 749: </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 <a href="#raw-text-elements" title="raw text elements">raw text</a> and
750: <a href="#rcdata-elements" title="RCDATA elements">RCDATAs</a> element must not
751: contain any occurrences of the string "<code title=""></</code>"
752: (U+003C LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that
1.1 mike 753: case-insensitively match the tag name of the element followed by one
754: of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM
1.304 mike 755: FEED (FF), U+000D CARRIAGE RETURN (CR), U+0020 SPACE, U+003E
756: GREATER-THAN SIGN (>), or U+002F SOLIDUS (/), unless that string is
757: part of an <a href="#syntax-escape" title="syntax-escape">escaping text
758: span</a>.</p><p>An <dfn id="syntax-escape" title="syntax-escape">escaping text span</dfn> is a span
1.1 mike 759: 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
760: not itself in an <a href="#syntax-escape" title="syntax-escape">escaping text
761: span</a>, and ends at the next <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span end</a>. There
762: cannot be any <a href="#syntax-charref" title="syntax-charref">character
763: references</a> inside an <a href="#syntax-escape" title="syntax-escape">escaping
764: text span</a> — sequences of characters that would look
765: like <a href="#syntax-charref" title="syntax-charref">character references</a> do not
1.123 mike 766: have special meaning.</p><p>An <dfn id="syntax-escape-start" title="syntax-escape-start">escaping text span
1.1 mike 767: start</dfn> is a part of <a href="#syntax-text" title="syntax-text">text</a> that
768: consists of the four character sequence "<code title=""><!--</code>" (U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
1.123 mike 769: 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 770: a part of <a href="#syntax-text" title="syntax-text">text</a> that consists of the
771: three character sequence "<code title="">--></code>" (U+002D
1.134 mike 772: 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 773: start</a> may share its U+002D HYPHEN-MINUS characters with its
774: corresponding <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span
1.373 mike 775: end</a>.</p><p>The text in <a href="#raw-text-elements">raw text elements</a> and <a href="#rcdata-elements">RCDATA
776: elements</a> must not have an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a> that is
777: not followed by an <a href="#syntax-escape-end" title="syntax-escape-end">escaping text
778: 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 779: attributes, and comments. Text must consist of Unicode characters.
780: Text must not contain U+0000 characters. Text must not contain
1.316 mike 781: permanently undefined Unicode characters (noncharacters). Text must
782: not contain control characters other than <a href="infrastructure.html#space-character" title="space
783: character">space characters</a>. Extra constraints are placed on
784: what is and what is not allowed in text based on where the text is
785: 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 786: represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A
787: LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR),
1.123 mike 788: 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 789: to escape characters that couldn't otherwise legally be included in
1.123 mike 790: <a href="#syntax-text" title="syntax-text">text</a>.</p><p>Character references must start with a U+0026 AMPERSAND
1.1 mike 791: (<code>&</code>). Following this, there are three possible kinds
1.123 mike 792: of character references:</p><dl><dt>Named character references</dt>
1.1 mike 793:
794: <dd>The ampersand must be followed by one of the names given in the
795: <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
796: case. The name must be one that is terminated by a U+003B SEMICOLON
1.464 mike 797: character (;).</dd>
1.1 mike 798:
799:
800: <dt>Decimal numeric character reference</dt>
801:
802: <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
803: (<code>#</code>) character, followed by one or more digits in the
1.464 mike 804: range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), representing
805: a base-ten integer that corresponds to a Unicode code point that is
1.378 mike 806: allowed according to the definition below. The digits must then be
1.464 mike 807: followed by a U+003B SEMICOLON character (;).</dd>
1.1 mike 808:
809:
810: <dt>Hexadecimal numeric character reference</dt>
811:
812: <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
813: (<code>#</code>) character, which must be followed by either a
1.464 mike 814: U+0078 LATIN SMALL LETTER X character (x) or a U+0058 LATIN CAPITAL
815: LETTER X character (X), which must then be followed by one or more
816: digits in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9),
817: U+0061 LATIN SMALL LETTER A to U+0066 LATIN SMALL LETTER F, and
818: U+0041 LATIN CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F,
819: representing a base-sixteen integer that corresponds to a Unicode
820: code point that is allowed according to the definition below. The
821: digits must then be followed by a U+003B SEMICOLON character
822: (;).</dd>
1.378 mike 823:
824: </dl><p>The numeric character reference forms described above are allowed
825: to reference any Unicode code point other than U+0000, permanently
826: undefined Unicode characters (noncharacters), and control characters
827: other than <a href="infrastructure.html#space-character" title="space character">space
828: characters</a>.</p><p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.464 mike 829: ampersand</dfn> is a U+0026 AMPERSAND character (&) that is
830: followed by some <a href="#syntax-text" title="syntax-text">text</a> other than a
831: <a href="infrastructure.html#space-character">space character</a>, a U+003C LESS-THAN SIGN character
832: (<), or another U+0026 AMPERSAND character
833: (<code>&</code>).</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 834: the character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
835: MARK, U+005B LEFT SQUARE BRACKET, U+0043 LATIN CAPITAL LETTER C,
836: U+0044 LATIN CAPITAL LETTER D, U+0041 LATIN CAPITAL LETTER A, U+0054
837: LATIN CAPITAL LETTER T, U+0041 LATIN CAPITAL LETTER A, U+005B LEFT
838: SQUARE BRACKET (<code title=""><![CDATA[</code>). Following this
839: sequence, the CDATA section may have <a href="#syntax-text" title="syntax-text">text</a>, with the additional restriction
840: that the text must not contain the three character sequence U+005D
841: RIGHT SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E
842: GREATER-THAN SIGN (<code title="">]]></code>). Finally, the CDATA
843: section must be ended by the three character sequence U+005D RIGHT
844: SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E GREATER-THAN
1.159 mike 845: 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 846: four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
847: MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title=""><!--</code>). Following this sequence, the comment may
848: have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
849: restriction that the text must not start with a single U+003E
1.464 mike 850: GREATER-THAN SIGN (>) character, nor start with a U+002D
851: HYPHEN-MINUS character (-) followed by a
852: U+003E GREATER-THAN SIGN (>) character, nor contain two
1.1 mike 853: consecutive U+002D HYPHEN-MINUS (<code title="">-</code>)
854: characters, nor end with a U+002D HYPHEN-MINUS (<code title="">-</code>) character. Finally, the comment must be ended by
855: the three character sequence U+002D HYPHEN-MINUS, U+002D
1.123 mike 856: HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--></code>).</p><div class="impl">
1.1 mike 857:
1.159 mike 858: <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 859:
860: <p><i>This section only applies to user agents, data mining tools,
861: and conformance checkers.</i></p>
862:
863: <p class="note">The rules for parsing XML documents into DOM trees
864: are covered by the next section, entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
865: syntax</a>".</p>
866:
867: <p>For <a href="dom.html#html-documents">HTML documents</a>, user agents must use the parsing
868: rules described in this section to generate the DOM trees. Together,
869: these rules define what is referred to as the <dfn id="html-parser">HTML
870: parser</dfn>.</p>
871:
872: <div class="note">
873:
874: <p>While the HTML syntax described in this specification bears a
875: close resemblance to SGML and XML, it is a separate language with
876: its own parsing rules.</p>
877:
1.183 mike 878: <p>Some earlier versions of HTML (in particular from HTML2 to
879: HTML4) were based on SGML and used SGML parsing rules. However, few
1.1 mike 880: (if any) web browsers ever implemented true SGML parsing for HTML
881: documents; the only user agents to strictly handle HTML as an SGML
882: application have historically been validators. The resulting
883: confusion — with validators claiming documents to have one
884: representation while widely deployed Web browsers interoperably
885: implemented a different representation — has wasted decades
886: of productivity. This version of HTML thus returns to a non-SGML
887: basis.</p>
888:
889: <p>Authors interested in using SGML tools in their authoring
890: pipeline are encouraged to use XML tools and the XML serialization
891: of HTML.</p>
892:
893: </div>
894:
895: <p>This specification defines the parsing rules for HTML documents,
896: whether they are syntactically correct or not. Certain points in the
897: parsing algorithm are said to be <dfn id="parse-error" title="parse error">parse
898: errors</dfn>. The error handling for parse errors is well-defined:
899: user agents must either act as described below when encountering
900: such problems, or must abort processing at the first error that they
901: encounter for which they do not wish to apply the rules described
902: below.</p>
903:
904: <p>Conformance checkers must report at least one parse error
905: condition to the user if one or more parse error conditions exist in
906: the document and must not report parse error conditions if none
907: exist in the document. Conformance checkers may report more than one
1.174 mike 908: parse error condition if more than one parse error condition exists
1.1 mike 909: in the document. Conformance checkers are not required to recover
910: from parse errors.</p>
911:
912: <p class="note">Parse errors are only errors with the
913: <em>syntax</em> of HTML. In addition to checking for parse errors,
914: conformance checkers will also verify that the document obeys all
915: the other conformance requirements described in this
916: specification.</p>
917:
918: <p>For the purposes of conformance checkers, if a resource is
919: determined to be in <a href="#syntax">the HTML syntax</a>, then it is an
920: <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
921:
1.266 mike 922: </div><div class="impl">
1.1 mike 923:
924: <h4 id="overview-of-the-parsing-model"><span class="secno">9.2.1 </span>Overview of the parsing model</h4>
925:
926: <p>The input to the HTML parsing process consists of a stream of
927: Unicode characters, which is passed through a
928: <a href="#tokenization">tokenization</a> stage followed by a <a href="#tree-construction">tree
929: construction</a> stage. The output is a <code>Document</code>
930: object.</p>
931:
932: <p class="note">Implementations that <a href="infrastructure.html#non-scripted">do not
933: support scripting</a> do not have to actually create a DOM
934: <code>Document</code> object, but the DOM tree in such cases is
935: still used as the model for the rest of the specification.</p>
936:
937: <p>In the common case, the data handled by the tokenization stage
1.159 mike 938: comes from the network, but <a href="embedded-content-0.html#dynamic-markup-insertion" title="dynamic markup
939: 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 940:
941: <p><img alt="" src="images/parsing-model-overview.png"></p>
942:
943: <p id="nestedParsing">There is only one set of states for the
944: tokenizer stage and the tree construction stage, but the tree
945: construction stage is reentrant, meaning that while the tree
946: construction stage is handling one token, the tokenizer might be
947: resumed, causing further tokens to be emitted and processed before
948: the first token's processing is complete.</p>
949:
950: <div class="example">
951:
952: <p>In the following example, the tree construction stage will be
953: called upon to handle a "p" start tag token while handling the
954: "script" start tag token:</p>
955:
956: <pre>...
957: <script>
958: document.write('<p>');
959: </script>
960: ...</pre>
961:
962: </div>
963:
964: <p>To handle these cases, parsers have a <dfn id="script-nesting-level">script nesting
965: level</dfn>, which must be initially set to zero, and a <dfn id="parser-pause-flag">parser
966: pause flag</dfn>, which must be initially set to false.</p>
967:
1.266 mike 968: </div><div class="impl">
1.1 mike 969:
970: <h4 id="the-input-stream"><span class="secno">9.2.2 </span>The <dfn>input stream</dfn></h4>
971:
972: <p>The stream of Unicode characters that comprises the input to the
973: tokenization stage will be initially seen by the user agent as a
974: stream of bytes (typically coming over the network or from the local
975: file system). The bytes encode the actual characters according to a
976: particular <em>character encoding</em>, which the user agent must
977: use to decode the bytes into characters.</p>
978:
979: <p class="note">For XML documents, the algorithm user agents must
980: use to determine the character encoding is given by the XML
1.104 mike 981: specification. This section does not apply to XML documents. <a href="references.html#refsXML">[XML]</a></p>
1.1 mike 982:
983:
1.168 mike 984: <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 985:
986: <p>In some cases, it might be impractical to unambiguously determine
987: the encoding before parsing the document. Because of this, this
988: specification provides for a two-pass mechanism with an optional
989: pre-scan. Implementations are allowed, as described below, to apply
990: a simplified parsing algorithm to whatever bytes they have available
991: before beginning to parse the document. Then, the real parser is
992: started, using a tentative encoding derived from this pre-parse and
993: other out-of-band metadata. If, while the document is being loaded,
994: the user agent discovers an encoding declaration that conflicts with
995: this information, then the parser can get reinvoked to perform a
996: parse of the document with the real encoding.</p>
997:
998: <p id="documentEncoding">User agents must use the following
999: algorithm (the <dfn id="encoding-sniffing-algorithm">encoding sniffing algorithm</dfn>) to determine
1000: the character encoding to use when decoding a document in the first
1001: pass. This algorithm takes as input any out-of-band metadata
1002: available to the user agent (e.g. the <a href="infrastructure.html#content-type" title="Content-Type">Content-Type metadata</a> of the document)
1003: and all the bytes available so far, and returns an encoding and a
1004: <dfn id="concept-encoding-confidence" title="concept-encoding-confidence">confidence</dfn>. The
1005: confidence is either <i>tentative</i>, <i>certain</i>, or
1006: <i>irrelevant</i>. The encoding used, and whether the confidence in
1007: that encoding is <i>tentative</i> or <i>certain</i>, is <a href="#meta-charset-during-parse">used during the parsing</a> to
1008: determine whether to <a href="#change-the-encoding">change the encoding</a>. If no
1009: encoding is necessary, e.g. because the parser is operating on a
1010: stream of Unicode characters and doesn't have to use an encoding at
1011: all, then the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
1012: <i>irrelevant</i>.</p>
1013:
1014: <ol><li><p>If the transport layer specifies an encoding, and it is
1015: supported, return that encoding with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1016: <i>certain</i>, and abort these steps.</p></li>
1017:
1018: <li><p>The user agent may wait for more bytes of the resource to be
1019: available, either in this step or at any later step in this
1020: algorithm. For instance, a user agent might wait 500ms or 512
1021: bytes, whichever came first. In general preparsing the source to
1022: find the encoding improves performance, as it reduces the need to
1023: throw away the data structures used when parsing upon finding the
1024: encoding information. However, if the user agent delays too long to
1025: obtain data to determine the encoding, then the cost of the delay
1026: could outweigh any performance improvements from the
1027: preparse.</p></li>
1028:
1029: <li><p>For each of the rows in the following table, starting with
1030: the first one and going down, if there are as many or more bytes
1031: available than the number of bytes in the first column, and the
1032: first bytes of the file match the bytes given in the first column,
1033: then return the encoding given in the cell in the second column of
1034: that row, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1035: <i>certain</i>, and abort these steps:</p>
1036:
1037: <!-- this table is present in several forms in this file; keep them in sync -->
1038: <table><thead><tr><th>Bytes in Hexadecimal
1039: </th><th>Encoding
1040: </th></tr></thead><tbody><!-- nobody uses this
1041: <tr>
1042: <td>00 00 FE FF
1043: <td>UTF-32BE
1044: <tr>
1045: <td>FF FE 00 00
1046: <td>UTF-32LE
1047: --><tr><td>FE FF
1048: </td><td>UTF-16BE
1049: </td></tr><tr><td>FF FE
1050: </td><td>UTF-16LE
1051: </td></tr><tr><td>EF BB BF
1052: </td><td>UTF-8
1053: <!-- nobody uses this
1054: <tr>
1055: <td>DD 73 66 73
1056: <td>UTF-EBCDIC
1057: -->
1058: </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
1059: (BOMs).</p></li>
1060:
1061: <li><p>Otherwise, the user agent will have to search for explicit
1062: character encoding information in the file itself. This should
1063: proceed as follows:
1064:
1065: </p><p>Let <var title="">position</var> be a pointer to a byte in the
1066: input stream, initially pointing at the first byte. If at any
1067: point during these substeps the user agent either runs out of
1068: bytes or decides that scanning further bytes would not be
1069: efficient, then skip to the next step of the overall character
1070: encoding detection algorithm. User agents may decide that scanning
1071: <em>any</em> bytes is not efficient, in which case these substeps
1072: are entirely skipped.</p>
1073:
1074: <p>Now, repeat the following "two" steps until the algorithm
1075: aborts (either because user agent aborts, as described above, or
1076: because a character encoding is found):</p>
1077:
1078: <ol><li><p>If <var title="">position</var> points to:</p>
1079:
1080: <dl class="switch"><dt>A sequence of bytes starting with: 0x3C 0x21 0x2D 0x2D (ASCII '<!--')</dt>
1081: <dd>
1082:
1083: <p>Advance the <var title="">position</var> pointer so that it
1084: points at the first 0x3E byte which is preceded by two 0x2D
1085: bytes (i.e. at the end of an ASCII '-->' sequence) and comes
1086: after the 0x3C byte that was found. (The two 0x2D bytes can be
1087: the same as the those in the '<!--' sequence.)</p>
1088:
1089: </dd>
1090:
1091: <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>
1092: <dd>
1093:
1094: <ol><li><p>Advance the <var title="">position</var> pointer so
1095: that it points at the next 0x09, 0x0A, 0x0C, 0x0D, 0x20, or
1096: 0x2F byte (the one in sequence of characters matched
1097: above).</p></li>
1098:
1099: <li><p><a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">Get
1100: an attribute</a> and its value. If no attribute was
1101: sniffed, then skip this inner set of steps, and jump to the
1102: second step in the overall "two step" algorithm.</p></li>
1103:
1104: <li><p>If the attribute's name is neither "<code title="">charset</code>" nor "<code title="">content</code>",
1105: then return to step 2 in these inner steps.</p></li>
1106:
1107: <li><p>If the attribute's name is "<code title="">charset</code>", let <var title="">charset</var> be
1108: the attribute's value, interpreted as a character
1109: encoding.</p></li>
1110:
1111: <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
1112: extracting an encoding from a Content-Type</a>, giving the
1113: attribute's value as the string to parse. If an encoding is
1114: returned, let <var title="">charset</var> be that
1115: encoding. Otherwise, return to step 2 in these inner
1116: steps.</p></li>
1117:
1118: <li><p>If <var title="">charset</var> is a UTF-16 encoding,
1119: change the value of <var title="">charset</var> to
1120: UTF-8.</p></li>
1121:
1122: <li><p>If <var title="">charset</var> is a supported
1123: character encoding, then return the given encoding, with
1124: <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1125: <i>tentative</i>, and abort all these steps.</p></li>
1126:
1127: <li><p>Otherwise, return to step 2 in these inner
1128: steps.</p></li>
1129:
1130: </ol></dd>
1131:
1.464 mike 1132: <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>
1.1 mike 1133: <dd>
1134:
1135: <ol><li><p>Advance the <var title="">position</var> pointer so
1136: that it points at the next 0x09 (ASCII TAB), 0x0A (ASCII LF),
1137: 0x0C (ASCII FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E
1.464 mike 1138: (ASCII >) byte.</p></li>
1.1 mike 1139:
1140: <li><p>Repeatedly <a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
1141: attribute</a> until no further attributes can be found,
1142: then jump to the second step in the overall "two step"
1143: algorithm.</p></li>
1144:
1145: </ol></dd>
1146:
1147: <dt>A sequence of bytes starting with: 0x3C 0x21 (ASCII '<!')</dt>
1148: <dt>A sequence of bytes starting with: 0x3C 0x2F (ASCII '</')</dt>
1149: <dt>A sequence of bytes starting with: 0x3C 0x3F (ASCII '<?')</dt>
1150: <dd>
1151:
1152: <p>Advance the <var title="">position</var> pointer so that it
1.464 mike 1153: points at the first 0x3E byte (ASCII >) that comes after the
1.1 mike 1154: 0x3C byte that was found.</p>
1155:
1156: </dd>
1157:
1158: <dt>Any other byte</dt>
1159: <dd>
1160:
1161: <p>Do nothing with that byte.</p>
1162:
1163: </dd>
1164:
1165: </dl></li>
1166:
1167: <li>Move <var title="">position</var> so it points at the next
1168: byte in the input stream, and return to the first step of this
1169: "two step" algorithm.</li>
1170:
1171: </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
1172: attribute</dfn>, it means doing this:</p>
1173:
1174: <ol><li><p>If the byte at <var title="">position</var> is one of 0x09
1175: (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII FF), 0x0D (ASCII CR),
1.464 mike 1176: 0x20 (ASCII space), or 0x2F (ASCII /) then advance <var title="">position</var> to the next byte and redo this
1.1 mike 1177: substep.</p></li>
1178:
1179: <li><p>If the byte at <var title="">position</var> is 0x3E (ASCII
1.464 mike 1180: >), then abort the "get an attribute" algorithm. There isn't
1.1 mike 1181: one.</p></li>
1182:
1183: <li><p>Otherwise, the byte at <var title="">position</var> is the
1184: start of the attribute name. Let <var title="">attribute
1185: name</var> and <var title="">attribute value</var> be the empty
1186: string.</p></li>
1187:
1188: <li><p><i>Attribute name</i>: Process the byte at <var title="">position</var> as follows:</p>
1189:
1.464 mike 1190: <dl class="switch"><dt>If it is 0x3D (ASCII =), and the <var title="">attribute
1.1 mike 1191: name</var> is longer than the empty string</dt>
1192:
1193: <dd>Advance <var title="">position</var> to the next byte and
1194: jump to the step below labeled <i>value</i>.</dd>
1195:
1196: <dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
1197: FF), 0x0D (ASCII CR), or 0x20 (ASCII space)</dt>
1198:
1199: <dd>Jump to the step below labeled <i>spaces</i>.</dd>
1200:
1.464 mike 1201: <dt>If it is 0x2F (ASCII /) or 0x3E (ASCII >)</dt>
1.1 mike 1202:
1203: <dd>Abort the "get an attribute" algorithm. The attribute's
1204: name is the value of <var title="">attribute name</var>, its
1205: value is the empty string.</dd>
1206:
1.464 mike 1207: <dt>If it is in the range 0x41 (ASCII A) to 0x5A (ASCII
1208: Z)</dt>
1.1 mike 1209:
1210: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1211: name</var> (where <var title="">b</var> is the value of the
1212: byte at <var title="">position</var>).</dd>
1213:
1214: <dt>Anything else</dt>
1215:
1216: <dd>Append the Unicode character with the same code point as the
1217: value of the byte at <var title="">position</var>) to <var title="">attribute name</var>. (It doesn't actually matter how
1218: bytes outside the ASCII range are handled here, since only
1219: ASCII characters can contribute to the detection of a character
1220: encoding.)</dd>
1221:
1222: </dl></li>
1223:
1224: <li><p>Advance <var title="">position</var> to the next byte and
1225: return to the previous step.</p></li>
1226:
1227: <li><p><i>Spaces</i>: If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
1228: LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
1229: advance <var title="">position</var> to the next byte, then,
1230: repeat this step.</p></li>
1231:
1232: <li><p>If the byte at <var title="">position</var> is
1.464 mike 1233: <em>not</em> 0x3D (ASCII =), abort the "get an attribute"
1.1 mike 1234: algorithm. The attribute's name is the value of <var title="">attribute name</var>, its value is the empty
1235: string.</p></li>
1236:
1237: <li><p>Advance <var title="">position</var> past the 0x3D (ASCII
1.464 mike 1238: =) byte.</p></li>
1.1 mike 1239:
1240: <li><p><i>Value:</i> If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
1241: LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
1242: advance <var title="">position</var> to the next byte, then,
1243: repeat this step.</p></li>
1244:
1245: <li><p>Process the byte at <var title="">position</var> as
1246: follows:</p>
1247:
1.464 mike 1248: <dl class="switch"><dt>If it is 0x22 (ASCII ") or 0x27 (ASCII ')</dt>
1.1 mike 1249:
1250: <dd>
1251:
1252: <ol><li>Let <var title="">b</var> be the value of the byte at
1253: <var title="">position</var>.</li>
1254:
1255: <li>Advance <var title="">position</var> to the next
1256: byte.</li>
1257:
1258: <li>If the value of the byte at <var title="">position</var>
1259: is the value of <var title="">b</var>, then advance <var title="">position</var> to the next byte and abort the "get
1260: an attribute" algorithm. The attribute's name is the value of
1261: <var title="">attribute name</var>, and its value is the
1262: value of <var title="">attribute value</var>.</li>
1263:
1.464 mike 1264: <li>Otherwise, if the value of the byte at <var title="">position</var> is in the range 0x41 (ASCII A) to
1265: 0x5A (ASCII Z), then append a Unicode character to <var title="">attribute value</var> whose code point is 0x20 more
1.1 mike 1266: than the value of the byte at <var title="">position</var>.</li>
1267:
1268: <li>Otherwise, append a Unicode character to <var title="">attribute value</var> whose code point is the same as
1269: the value of the byte at <var title="">position</var>.</li>
1270:
1271: <li>Return to the second step in these substeps.</li>
1272:
1273: </ol></dd>
1274:
1.464 mike 1275: <dt>If it is 0x3E (ASCII >)</dt>
1.1 mike 1276:
1277: <dd>Abort the "get an attribute" algorithm. The attribute's
1278: name is the value of <var title="">attribute name</var>, its
1279: value is the empty string.</dd>
1280:
1281:
1.464 mike 1282: <dt>If it is in the range 0x41 (ASCII A) to 0x5A (ASCII
1283: Z)</dt>
1.1 mike 1284:
1285: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1286: value</var> (where <var title="">b</var> is the value of the
1287: byte at <var title="">position</var>). Advance <var title="">position</var> to the next byte.</dd>
1288:
1289: <dt>Anything else</dt>
1290:
1291: <dd>Append the Unicode character with the same code point as the
1292: 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>
1293:
1294: </dl></li>
1295:
1296: <li><p>Process the byte at <var title="">position</var> as
1297: follows:</p>
1298:
1299: <dl class="switch"><dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
1300: FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E (ASCII
1.464 mike 1301: >)</dt>
1.1 mike 1302:
1303: <dd>Abort the "get an attribute" algorithm. The attribute's
1304: name is the value of <var title="">attribute name</var> and its
1305: value is the value of <var title="">attribute value</var>.</dd>
1306:
1.464 mike 1307: <dt>If it is in the range 0x41 (ASCII A) to 0x5A (ASCII
1308: Z)</dt>
1.1 mike 1309:
1310: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1311: value</var> (where <var title="">b</var> is the value of the
1312: byte at <var title="">position</var>).</dd>
1313:
1314: <dt>Anything else</dt>
1315:
1316: <dd>Append the Unicode character with the same code point as the
1317: value of the byte at <var title="">position</var>) to <var title="">attribute value</var>.</dd>
1318:
1319: </dl></li>
1320:
1321: <li><p>Advance <var title="">position</var> to the next byte and
1322: return to the previous step.</p></li>
1323:
1324: </ol><p>For the sake of interoperability, user agents should not use a
1325: pre-scan algorithm that returns different results than the one
1326: described above. (But, if you do, please at least let us know, so
1327: that we can improve this algorithm and benefit everyone...)</p>
1328:
1329: </li>
1330:
1331: <li><p>If the user agent has information on the likely encoding for
1332: this page, e.g. based on the encoding of the page when it was last
1333: visited, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1334: <i>tentative</i>, and abort these steps.</p></li>
1335:
1.322 mike 1336: <li>
1337:
1338: <p>The user agent may attempt to autodetect the character encoding
1339: from applying frequency analysis or other algorithms to the data
1340: stream. If autodetection succeeds in determining a character
1341: encoding, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1342: <i>tentative</i>, and abort these steps. <a href="references.html#refsUNIVCHARDET">[UNIVCHARDET]</a></p>
1343:
1344: <p class="note">The UTF-8 encoding has a highly detectable bit
1345: pattern. Documents that contain bytes with values greater than
1346: 0x7F which match the UTF-8 pattern are very likely to be UTF-8,
1347: while documents with byte sequences that do not match it are very
1348: likely not. User-agents are therefore encouraged to search for
1.485 mike 1349: this common encoding. <a href="references.html#refsPPUTF8">[PPUTF8]</a> <a href="references.html#refsUTF8DET">[UTF8DET]</a></p>
1.322 mike 1350:
1351: </li>
1.1 mike 1352:
1.501 mike 1353: <li>
1354:
1355: <p>Otherwise, return an implementation-defined or user-specified
1356: default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1357: <i>tentative</i>.</p>
1358:
1359: <p>In controlled environments or in environments where the
1360: encoding of documents can be prescribed (for example, for user
1361: agents intended for dedicated use in new networks), the
1362: comprehensive <code title="">UTF-8</code> encoding is
1363: suggested.</p>
1364:
1365: <p>In other environments, the default encoding is typically
1366: dependent on the user's locale (an approximation of the languages,
1367: and thus typically encodings, of the pages that the user is likely
1368: to frequent). The following table gives suggested defaults based
1.504 mike 1369: on the user's locale, for compatibility with legacy
1370: content. Locales are identified by BCP 47 language codes. <a href="references.html#refsBCP47">[BCP47]</a></p>
1.501 mike 1371:
1372: <!-- based on mozilla 1.9.1 localizations:
1373: http://mxr.mozilla.org/l10n-mozilla1.9.1/find?string=global%2Fintl.properties&tree=l10n-mozilla1.9.1&hint= -->
1374:
1.504 mike 1375: <table><thead><tr><th>Locale language
1.501 mike 1376: </th><th>Suggested default encoding
1377: </th></tr></thead><tbody><tr><td>ar
1378: </td><td>UTF-8
1379:
1380: </td></tr><tr><td>be
1381: </td><td>ISO-8859-5
1382:
1383: </td></tr><tr><td>bg
1384: </td><td>windows-1251
1385:
1386: </td></tr><tr><td>cs<!-- -CZ -->
1387: </td><td>ISO-8859-2
1388:
1389: </td></tr><tr><td>cy
1390: </td><td>UTF-8
1391:
1392: </td></tr><tr><td>fa<!-- -IR -->
1393: </td><td>UTF-8
1394:
1395: </td></tr><tr><td>he<!-- -IL -->
1396: </td><td>windows-1255
1397:
1398: </td></tr><tr><td>hr
1399: </td><td>UTF-8
1400:
1401: </td></tr><tr><td>hu<!-- -HU -->
1402: </td><td>ISO-8859-2
1403:
1404: </td></tr><tr><td>ja <!-- and ja-JP-mac -->
1405: </td><td>windows-31J <!-- Shift_JIS -->
1406:
1407: </td></tr><tr><td>kk
1408: </td><td>UTF-8
1409:
1410: </td></tr><tr><td>ko<!-- -KR -->
1411: </td><td>windows-949 <!-- EUC-KR -->
1412:
1413: </td></tr><tr><td>ku
1414: </td><td>windows-1254 <!-- ISO-8859-9 -->
1415:
1416: </td></tr><tr><td>lt
1417: </td><td>windows-1257
1418:
1419: </td></tr><tr><td>lv<!-- -LV -->
1420: </td><td>ISO-8859-13
1421:
1422: </td></tr><tr><td>mk<!-- -MK -->
1423: </td><td>UTF-8
1424:
1425: </td></tr><tr><td>or
1426: </td><td>UTF-8
1427:
1428: </td></tr><tr><td>pl<!-- -PL -->
1429: </td><td>ISO-8859-2
1430:
1431: </td></tr><tr><td>ro
1432: </td><td>UTF-8
1433:
1434: </td></tr><tr><td>ru
1435: </td><td>windows-1251
1436:
1437: </td></tr><tr><td>sk
1438: </td><td>windows-1250
1439:
1440: </td></tr><tr><td>sl
1441: </td><td>ISO-8859-2
1442:
1443: </td></tr><tr><td>sr
1444: </td><td>UTF-8
1445:
1446: </td></tr><tr><td>th
1447: </td><td>windows-874 <!-- TIS-620 -->
1448:
1449: </td></tr><tr><td>tr<!-- -TR -->
1450: </td><td>windows-1254 <!-- ISO-8859-9 -->
1451:
1.503 mike 1452: </td></tr><tr><td>uk
1.501 mike 1453: </td><td>windows-1251
1454:
1455: </td></tr><tr><td>vi
1456: </td><td>UTF-8
1457:
1458: </td></tr><tr><td>zh-CN
1459: </td><td>GB18030
1460:
1461: </td></tr><tr><td>zh-TW
1462: </td><td>Big5
1463:
1464: </td></tr><tr><td>All other locales
1465: </td><td>windows-1252
1466:
1467: </td></tr></tbody></table></li>
1.1 mike 1468:
1469: </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
1470: be set to the value returned from this algorithm, at the same time
1471: as the user agent uses the returned value to select the decoder to
1472: use for the input stream.</p>
1473:
1474:
1.237 mike 1475: <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 1476:
1.237 mike 1477: <p>User agents must at a minimum support the UTF-8 and Windows-1252
1478: encodings, but may support more.</p>
1479:
1480: <p class="note">It is not unusual for Web browsers to support dozens
1481: if not upwards of a hundred distinct character encodings.</p>
1482:
1.365 mike 1483: <p>User agents must support the <a href="infrastructure.html#preferred-mime-name">preferred MIME name</a> of
1484: every character encoding they support, and should support all the
1485: IANA-registered names and aliases of every character encoding they
1486: support. <a href="references.html#refsIANACHARSET">[IANACHARSET]</a></p>
1.237 mike 1487:
1488: <p>When comparing a string specifying a character encoding with the
1489: name or alias of a character encoding to determine if they are
1490: 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
1491: then perform the comparison in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1492: case-insensitive</a> manner.</p>
1493:
1494: <!-- this bit will be replaced by actual alias registrations in due course -->
1495:
1496: <p>In addition, user agents must support the aliases given in the
1497: following table for every character encoding they support, so that
1498: labels from the first column are treated as equivalent to the labels
1499: given in the corresponding cell from the second column on the same
1500: row.</p>
1501:
1502: <table><caption>Additional character encoding aliases</caption>
1503: <thead><tr><th> Alias </th><th> Corresponding encoding </th><th> References
1504: </th></tr></thead><tbody><tr><td> x-sjis </td><td> windows-31J </td><td>
1505: <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
1506: <a href="references.html#refsWIN31J">[WIN31J]</a>
1507: </td></tr><tr><td> windows-932 </td><td> windows-31J </td><td>
1508: <a href="references.html#refsWIN31J">[WIN31J]</a>
1509: </td></tr><tr><td> x-x-big5 </td><td> Big5 </td><td>
1510: <a href="references.html#refsBIG5">[BIG5]</a>
1511: </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
1512: first column of the following table to either convert content to
1513: Unicode characters or convert Unicode characters to bytes, it must
1514: instead use the encoding given in the cell in the second column of
1515: the same row. When a byte or sequence of bytes is treated
1516: differently due to this encoding aliasing, it is said to have been
1517: <dfn id="misinterpreted-for-compatibility">misinterpreted for compatibility</dfn>.</p>
1518:
1519: <table><caption>Character encoding overrides</caption>
1520: <thead><tr><th> Input encoding </th><th> Replacement encoding </th><th> References
1521: </th></tr></thead><tbody><!-- how about EUC-JP? --><tr><td> EUC-KR </td><td> windows-949 </td><td>
1522: <a href="references.html#refsEUCKR">[EUCKR]</a>
1523: <a href="references.html#refsWIN949">[WIN949]</a>
1524: </td></tr><tr><td> GB2312 </td><td> GBK </td><td>
1525: <a href="references.html#refsRFC1345">[RFC1345]</a>
1526: <a href="references.html#refsGBK">[GBK]</a>
1527: </td></tr><tr><td> GB_2312-80 </td><td> GBK </td><td>
1528: <a href="references.html#refsRFC1345">[RFC1345]</a>
1529: <a href="references.html#refsGBK">[GBK]</a>
1530: </td></tr><tr><td> ISO-8859-1 </td><td> windows-1252 </td><td>
1531: <a href="references.html#refsRFC1345">[RFC1345]</a>
1532: <a href="references.html#refsWIN1252">[WIN1252]</a>
1533: </td></tr><tr><td> ISO-8859-9 </td><td> windows-1254 </td><td>
1534: <a href="references.html#refsRFC1345">[RFC1345]</a>
1535: <a href="references.html#refsWIN1254">[WIN1254]</a>
1536: </td></tr><tr><td> ISO-8859-11 </td><td> windows-874 </td><td>
1537: <a href="references.html#refsISO885911">[ISO885911]</a>
1538: <a href="references.html#refsWIN874">[WIN874]</a>
1539: </td></tr><tr><td> KS_C_5601-1987 </td><td> windows-949 </td><td>
1540: <a href="references.html#refsRFC1345">[RFC1345]</a>
1541: <a href="references.html#refsWIN949">[WIN949]</a>
1542: </td></tr><tr><td> Shift_JIS </td><td> windows-31J </td><td>
1543: <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
1544: <a href="references.html#refsWIN31J">[WIN31J]</a>
1545: </td></tr><tr><td> TIS-620 </td><td> windows-874 </td><td>
1546: <a href="references.html#refsTIS620">[TIS620]</a>
1547: <a href="references.html#refsWIN874">[WIN874]</a>
1548: </td></tr><tr><td> US-ASCII </td><td> windows-1252 </td><td>
1549: <a href="references.html#refsRFC1345">[RFC1345]</a>
1550: <a href="references.html#refsWIN1252">[WIN1252]</a>
1551: </td></tr></tbody></table><p class="note">The requirement to treat certain encodings as other
1552: encodings according to the table above is a <a href="introduction.html#willful-violation">willful
1553: violation</a> of the W3C Character Model specification, motivated
1554: by a desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
1555:
1556: <p>When a user agent is to use the UTF-16 encoding but no BOM has
1557: been found, user agents must default to UTF-16LE.</p>
1558:
1559: <p class="note">The requirement to default UTF-16 to LE rather than
1560: BE is a <a href="introduction.html#willful-violation">willful violation</a> of RFC 2781, motivated by a
1561: desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
1562:
1563: <hr><p>User agents must not support the CESU-8, UTF-7, BOCU-1 and SCSU
1564: 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>
1565:
1566: <p>Support for encodings based on EBCDIC is not recommended. This
1567: encoding is rarely used for publicly-facing Web content.</p>
1568:
1569: <p>Support for UTF-32 is not recommended. This encoding is rarely
1570: used, and frequently implemented incorrectly.</p>
1571:
1572: <p class="note">This specification does not make any attempt to
1573: support EBCDIC-based encodings and UTF-32 in its algorithms; support
1574: and use of these encodings can thus lead to unexpected behavior in
1575: implementations of this specification.</p>
1576:
1577:
1578:
1579: <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.3 </span>Preprocessing the input stream</h5>
1.1 mike 1580:
1581: <p>Given an encoding, the bytes in the input stream must be
1582: converted to Unicode characters for the tokenizer, as described by
1583: the rules for that encoding, except that the leading U+FEFF BYTE
1584: ORDER MARK character, if any, must not be stripped by the encoding
1585: layer (it is stripped by the rule below).</p> <!-- this is to
1586: prevent two leading BOMs from being both stripped, once by the
1587: decoder, and once by the parser -->
1588:
1589: <p>Bytes or sequences of bytes in the original byte stream that
1.393 mike 1590: could not be converted to Unicode code points must be converted to
1591: U+FFFD REPLACEMENT CHARACTERs.</p>
1.1 mike 1592:
1593: <p class="note">Bytes or sequences of bytes in the original byte
1594: stream that did not conform to the encoding specification
1595: (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
1596: errors that conformance checkers are expected to report.</p>
1597:
1.438 mike 1598: <p>Any byte or sequence of bytes in the original byte stream that is
1599: <a href="#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
1.1 mike 1600: error</a>.</p>
1601:
1602: <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
1603: any are present.</p>
1604:
1.300 mike 1605: <p class="note">The requirement to strip a U+FEFF BYTE ORDER MARK
1606: character regardless of whether that character was used to determine
1607: the byte order is a <a href="introduction.html#willful-violation">willful violation</a> of Unicode,
1608: motivated by a desire to increase the resilience of user agents in
1609: the face of naïve transcoders.</p>
1610:
1.316 mike 1611: <p>All U+0000 NULL characters and code points in the range U+D800 to
1.315 mike 1612: U+DFFF<!-- surrogates not allowed e.g. in UTF-8, and we don't want
1613: them to suddenly turn into codepoints when they go through a UTF-16
1614: pipe --> in the input must be replaced by U+FFFD REPLACEMENT
1.316 mike 1615: CHARACTERs. Any occurrences of such characters and code points are
1616: <a href="#parse-error" title="parse error">parse errors</a>.</p>
1.1 mike 1617:
1618: <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
1619: <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
1620: CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
1.315 mike 1621: <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+FDD0
1622: to U+FDEF, and characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF,
1623: U+2FFFE, U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE,
1624: U+5FFFF, U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF,
1625: U+9FFFE, U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE,
1626: U+CFFFF, U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF,
1627: U+10FFFE, and U+10FFFF are <a href="#parse-error" title="parse error">parse
1.316 mike 1628: errors</a>. These are all control characters or permanently
1629: undefined Unicode characters (noncharacters).</p>
1.1 mike 1630:
1631: <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
1632: characters are treated specially. Any CR characters that are
1633: followed by LF characters must be removed, and any CR characters not
1634: followed by LF characters must be converted to LF characters. Thus,
1635: newlines in HTML DOMs are represented by LF characters, and there
1636: are never any CR characters in the input to the
1637: <a href="#tokenization">tokenization</a> stage.</p>
1638:
1639: <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
1640: input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
1641: the <i><a href="#next-input-character">next input character</a></i> is the first character in the
1642: input. The <dfn id="current-input-character">current input character</dfn> is the last character
1643: to have been <i><a href="#consumed">consumed</a></i>.</p>
1644:
1645: <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
1646: character or just before the end of the input stream) where content
1.159 mike 1647: 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 1648: inserted. The insertion point is relative to the position of the
1649: character immediately after it, it is not an absolute offset into
1650: the input stream. Initially, the insertion point is
1.10 mike 1651: undefined.</p>
1.1 mike 1652:
1653: <p>The "EOF" character in the tables below is a conceptual character
1654: representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
1.159 mike 1655: is a <a href="embedded-content-0.html#script-created-parser">script-created parser</a>, then the end of the
1.1 mike 1656: <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
1.159 mike 1657: 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 1658: consumed. Otherwise, the "EOF" character is not a real character in
1659: the stream, but rather the lack of any further characters.</p>
1660:
1661:
1.237 mike 1662: <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.4 </span>Changing the encoding while parsing</h5>
1.1 mike 1663:
1664: <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
1665: encoding</dfn>, it must run the following steps. This might happen
1666: if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
1667: failed to find an encoding, or if it found an encoding that was not
1668: the actual encoding of the file.</p>
1669:
1670: <ol><li>If the new encoding is identical or equivalent to the encoding
1671: that is already being used to interpret the input stream, then set
1672: the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1673: <i>certain</i> and abort these steps. This happens when the
1674: encoding information found in the file matches what the
1675: <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
1676: encoding, and in the second pass through the parser if the first
1677: pass found that the encoding sniffing algorithm described in the
1678: earlier section failed to find the right encoding.</li>
1679:
1680: <li>If the encoding that is already being used to interpret the
1681: input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1682: <i>certain</i> and abort these steps. The new encoding is ignored;
1683: if it was anything but the same encoding, then it would be clearly
1684: incorrect.</li>
1685:
1686: <li>If the new encoding is a UTF-16 encoding, change it to
1687: UTF-8.</li>
1688:
1689: <li>If all the bytes up to the last byte converted by the current
1690: decoder have the same Unicode interpretations in both the current
1691: encoding and the new encoding, and if the user agent supports
1692: changing the converter on the fly, then the user agent may change
1693: to the new converter for the encoding on the fly. Set the
1694: <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
1695: convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1696: <i>certain</i>, and abort these steps.</li>
1697:
1698: <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
1699: <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
1700: browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
1701: sniffing algorithm</a> and instead just set the encoding to the
1702: new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1703: <i>certain</i>. Whenever possible, this should be done without
1704: actually contacting the network layer (the bytes should be
1705: re-parsed from memory), even if, e.g., the document is marked as
1706: not being cacheable. If this is not possible and contacting the
1707: network layer would involve repeating a request that uses a method
1708: other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
1709: equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1710: <i>certain</i> and ignore the new encoding. The resource will be
1711: misinterpreted. User agents may notify the user of the situation,
1712: to aid in application development.</li>
1713:
1.266 mike 1714: </ol></div><div class="impl">
1715:
1716: <h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4>
1.1 mike 1717:
1718: <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5>
1719:
1720: <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
1721: the primary operation of the tree construction stage.</p>
1722:
1723: <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
1724: "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
1725: "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
1726: "<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 1727: "<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 1728: "<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>",
1729: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
1730: "<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
1731: table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
1732: foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
1733: body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
1734: frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
1735: frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
1736: after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
1737: frameset</a>" during the course of the parsing, as described in
1738: the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
1739: how tokens are processed and whether CDATA sections are
1740: supported.</p>
1741:
1742: <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
1743: head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
1744: body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
1745: table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
1746: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
1747: "<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
1748: that the other modes defer to them at various times. When the
1749: algorithm below says that the user agent is to do something
1750: "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
1751: mode", where <var title="">m</var> is one of these modes, the user
1752: agent must use the rules described under the <var title="">m</var>
1753: <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
1754: <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>
1755: to a new value.</p>
1756:
1757: <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.91 mike 1758: 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 1759: <dfn id="original-insertion-mode">original insertion mode</dfn> is also set. This is the
1760: insertion mode to which the tree construction stage will return.</p>
1761:
1762: <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
1763: mode: in foreign content">in foreign content</a>", the
1764: <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
1765: is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
1766: foreign content">in foreign content</a>" mode to handle HTML
1767: (i.e. not foreign) content.</p>
1768:
1769: <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
1770: mode appropriately</dfn>, it means the UA must follow these
1771: steps:</p>
1772:
1773: <ol><li>Let <var title="">last</var> be false.</li>
1774:
1775: <li>Let <var title="">node</var> be the last node in the
1776: <a href="#stack-of-open-elements">stack of open elements</a>.</li>
1777:
1778: <li>If <var title="">node</var> is the first node in the stack of
1779: open elements, then set <var title="">last</var> to true and set
1780: <var title="">node</var> to the <var title="">context</var>
1781: element. (<a href="#fragment-case">fragment case</a>)</li>
1782:
1783: <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
1784: 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
1785: steps. (<a href="#fragment-case">fragment case</a>)</li>
1786:
1787: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
1788: <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
1789: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
1790: mode: in cell">in cell</a>" and abort these steps.</li>
1791:
1792: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
1793: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
1794: mode: in row">in row</a>" and abort these steps.</li>
1795:
1796: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
1797: <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
1798: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
1799: table body">in table body</a>" and abort these steps.</li>
1800:
1801: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
1802: 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
1803: these steps.</li>
1804:
1805: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
1806: 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
1807: abort these steps. (<a href="#fragment-case">fragment case</a>)</li>
1808:
1809: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
1810: 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
1811: steps.</li>
1812:
1813: <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
1814: namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then switch the
1815: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
1816: foreign content">in foreign content</a>", let the
1817: <a href="#secondary-insertion-mode">secondary insertion mode</a> be "<a href="#parsing-main-inbody" title="insertion
1818: mode: in body">in body</a>", and abort these steps.</li>
1819:
1.159 mike 1820: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element-0">head</a></code> element,
1.1 mike 1821: 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
1822: these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- This is only
1823: here for now in case people think that the spec accidentally
1824: omitted it and try to "fix" it. Note that noscript-in-head is also
1825: handled this way. This is all intentional. The only thing it
1826: doesn't handle is the scripting-disabled fragment parsing case for
1827: a <head> element containing a <noscript> which itself contains
1828: something other than a <link> or a <style> element; you'd expect
1829: that to break out of the <noscript> but it doesn't. This is an edge
1830: case that doesn't affect the spec, since the algorithm for fragment
1831: parsing is only used for innerHTML/outerHTML/insertAdjacentHTML(),
1.333 mike 1832: where we know scripting is enabled. -->
1.1 mike 1833:
1.159 mike 1834: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element-0">body</a></code> element,
1.1 mike 1835: 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
1836: steps.</li>
1837:
1.5 mike 1838: <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.1 mike 1839: 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
1840: these steps. (<a href="#fragment-case">fragment case</a>)</li>
1841:
1.159 mike 1842: <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element-0">html</a></code> element,
1.333 mike 1843: then <!--: if the <span><code title="">head</code> element
1844: pointer</span> is null,--> switch the <a href="#insertion-mode">insertion mode</a>
1845: to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before
1846: head</a>"<!--, otherwise, switch the <span>insertion mode</span>
1847: to "<span title="insertion mode: after head">after head</span>".-->
1848: Then, <!-- in either case, --> abort these steps. (<a href="#fragment-case">fragment
1849: case</a>)</li> <!-- if the head element pointer can ever be
1850: non-null when we're going through these steps, we'll need to
1851: uncomment out the commented-out bits -->
1.1 mike 1852:
1853: <li>If <var title="">last</var> is true, then switch the
1854: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
1855: body">in body</a>" and abort these steps. (<a href="#fragment-case">fragment
1856: case</a>)</li>
1857:
1858: <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
1859: elements</a>.</li>
1860:
1861: <li>Return to step 3.</li>
1862:
1863: </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5>
1864:
1865: <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
1866: stack grows downwards; the topmost node on the stack is the first
1867: one added to the stack, and the bottommost node of the stack is the
1868: most recently added node in the stack (notwithstanding when the
1869: stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
1870:
1871: <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
1872: html</a>" <a href="#insertion-mode">insertion mode</a> creates the
1.159 mike 1873: <code><a href="semantics.html#the-html-element-0">html</a></code> root element node, which is then added to the
1.1 mike 1874: stack.</p>
1875:
1876: <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
1.159 mike 1877: elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1 mike 1878: element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
1879: parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
1880: case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
1881: html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
1882:
1.159 mike 1883: <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 1884: node of the stack. It never gets popped off the stack.</p>
1885:
1886: <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
1887: stack.</p>
1888:
1889: <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
1890: element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
1891: 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
1892: open elements</a> (<a href="#fragment-case">fragment case</a>), then the
1893: <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
1.159 mike 1894: of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code> element).</p>
1.1 mike 1895:
1896: <p>Elements in the stack fall into the following categories:</p>
1897:
1898: <dl><dt><dfn id="special">Special</dfn></dt>
1899:
1900: <dd><p>The following HTML elements have varying levels of special
1901: 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>,
1902: <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 1903: <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.159 mike 1904: <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 1905: <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 1906: <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
1.422 mike 1907: <code><a href="semantics.html#the-dd-element">dd</a></code>, <code><a href="interactive-elements.html#the-details-element">details</a></code>, <code><a href="obsolete.html#dir">dir</a></code>,
1908: <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="semantics.html#the-dt-element">dt</a></code>,
1909: <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>, <code><a href="forms.html#the-fieldset-element">fieldset</a></code>, <code><a href="text-level-semantics.html#the-figure-element">figure</a></code>,
1910: <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="obsolete.html#frame">frame</a></code>,
1911: <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>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h2</a></code>,
1912: <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>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h6</a></code>,
1913: <code><a href="semantics.html#the-head-element-0">head</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>, <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>,
1914: <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>, <!-- <code>image</code>,
1915: (commented out because this isn't an element that can end up on the
1916: stack, so it doesn't matter) --> <code><a href="text-level-semantics.html#the-img-element">img</a></code>,
1917: <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="obsolete.html#isindex-0">isindex</a></code>, <code><a href="semantics.html#the-li-element">li</a></code>,
1918: <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="obsolete.html#listing">listing</a></code>, <code><a href="interactive-elements.html#menus">menu</a></code>,
1919: <code><a href="semantics.html#meta">meta</a></code>, <code><a href="semantics.html#the-nav-element">nav</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>,
1920: <code><a href="obsolete.html#noframes">noframes</a></code>, <code><a href="semantics.html#the-noscript-element">noscript</a></code>, <code><a href="semantics.html#the-ol-element">ol</a></code>,
1921: <code><a href="semantics.html#the-p-element">p</a></code>, <code><a href="text-level-semantics.html#the-param-element">param</a></code>, <code><a href="obsolete.html#plaintext">plaintext</a></code>,
1922: <code><a href="semantics.html#the-pre-element">pre</a></code>, <code><a href="semantics.html#script">script</a></code>, <code><a href="semantics.html#the-section-element">section</a></code>,
1923: <code><a href="forms.html#the-select-element">select</a></code>, <code><a href="obsolete.html#spacer">spacer</a></code>, <code><a href="semantics.html#the-style-element">style</a></code>,
1924: <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="forms.html#the-textarea-element">textarea</a></code>, <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>,
1925: <code><a href="tabular-data.html#the-thead-element">thead</a></code>, <code><a href="semantics.html#the-title-element-0">title</a></code>, <code><a href="tabular-data.html#the-tr-element">tr</a></code>,
1926: <code><a href="semantics.html#the-ul-element">ul</a></code>, <code>wbr</code>, and <code><a href="obsolete.html#xmp">xmp</a></code>.</p></dd>
1.1 mike 1927:
1928: <dt><dfn id="scoping">Scoping</dfn></dt>
1929: <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
1930: an element in scope">scopes</a> for various parts of the
1.5 mike 1931: 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 1932: <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>,
1933: <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 1934: <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
1935:
1936: <dt><dfn id="formatting">Formatting</dfn></dt>
1937: <dd><p>The following HTML elements are those that end up in the
1938: <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 1939: <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>,
1940: <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>,
1941: <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>,
1942: <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
1943: <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1 mike 1944:
1945: <dt><dfn id="phrasing">Phrasing</dfn></dt>
1946: <dd><p>All other elements found while parsing an HTML
1947: document.</p></dd>
1948:
1.234 mike 1949: </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
1950: specific scope</dfn> consisting of a list of element types <var title="">list</var> when the following algorithm terminates in a
1951: match state:</p>
1.1 mike 1952:
1953: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
1954: node</a> (the bottommost node of the stack).</p></li>
1955:
1956: <li><p>If <var title="">node</var> is the target node, terminate in
1957: a match state.</p></li>
1958:
1.234 mike 1959: <li><p>Otherwise, if <var title="">node</var> is one of the element
1960: types in <var title="">list</var>, terminate in a failure
1961: state.</p></li>
1.1 mike 1962:
1963: <li><p>Otherwise, set <var title="">node</var> to the previous
1964: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
1965: 2. (This will never fail, since the loop will always terminate in
1966: the previous step if the top of the stack — an
1.159 mike 1967: <code><a href="semantics.html#the-html-element-0">html</a></code> element — is reached.)</p></li>
1.1 mike 1968:
1.234 mike 1969: </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
1970: it <a href="#has-an-element-in-the-specific-scope">has an element in the specific scope</a> consisting
1971: of the following element types:</p>
1972:
1973: <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
1974: <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
1975: <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.) -->
1976: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
1977: <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
1978: <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
1979: <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
1980: <li><code><a href="obsolete.html#the-marquee-element">marquee</a></code> in the HTML namespace</li>
1981: <li><code><a href="text-level-semantics.html#the-object-element">object</a></code> in the HTML namespace</li>
1982: <li><code title="">foreignObject</code> in the SVG namespace</li>
1983: </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
1984: item scope</dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
1985: scope</a> consisting of the following element types:</p>
1986:
1987: <ul class="brief"><li>All the element types listed above for the <i><a href="#has-an-element-in-scope">has an element
1988: in scope</a></i> algorithm.</li>
1989: <li><code><a href="semantics.html#the-ol-element">ol</a></code> in the HTML namespace</li>
1990: <li><code><a href="semantics.html#the-ul-element">ul</a></code> in the HTML namespace</li>
1991: </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
1992: scope</em></dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
1993: scope</a> consisting of the following element types:</p>
1994:
1995: <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.) -->
1996: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
1997: </ul><p>Nothing happens if at any time any of the elements in the
1.1 mike 1998: <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
1999: or removed from, the <code>Document</code> tree. In particular, the
2000: stack is not changed in this situation. This can cause, amongst
2001: other strange effects, content to be appended to nodes that are no
2002: longer in the DOM.</p>
2003:
2004: <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
2005: the stack is manipulated in a random-access fashion.</p>
2006:
2007:
2008: <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5>
2009:
2010: <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
2011: empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
2012:
2013: <p>The list contains elements in the <a href="#formatting">formatting</a>
2014: category, and scope markers. The scope markers are inserted when
1.159 mike 2015: 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 2016: elements, marquees, table cells, and table captions, and are used to
1.5 mike 2017: prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.159 mike 2018: elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code> elements, marquees, and
1.1 mike 2019: tables.</p>
2020:
2021: <p class="note">The scope markers are unrelated to the concept of an
2022: element being <a href="#has-an-element-in-scope" title="has an element in scope">in
2023: scope</a>.</p>
2024:
2025: <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
2026: elements</a> is associated with the token for which it was
2027: created, so that further elements can be created for that token if
2028: necessary.</p>
2029:
2030: <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
2031: active formatting elements</dfn>, the UA must perform the following
2032: steps:</p>
2033:
2034: <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
2035: elements</a>, then there is nothing to reconstruct; stop this
2036: algorithm.</li>
2037:
2038: <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
2039: active formatting elements</a> is a marker, or if it is an
2040: element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
2041: there is nothing to reconstruct; stop this algorithm.</li>
2042:
2043: <li>Let <var title="">entry</var> be the last (most recently added)
2044: element in the <a href="#list-of-active-formatting-elements">list of active formatting
2045: elements</a>.</li>
2046:
2047: <li>If there are no entries before <var title="">entry</var> in the
2048: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
2049: 8.</li>
2050:
2051: <li>Let <var title="">entry</var> be the entry one earlier than
2052: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
2053: elements</a>.</li>
2054:
2055: <li>If <var title="">entry</var> is neither a marker nor an element
2056: that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
2057: 4.</li>
2058:
2059: <li>Let <var title="">entry</var> be the element one later than
2060: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
2061: elements</a>.</li>
2062:
2063: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
2064: element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
2065:
2066: <li>Append <var title="">new element</var> to the <a href="#current-node">current
2067: node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
2068: elements</a> so that it is the new <a href="#current-node">current
2069: node</a>.</li>
2070:
2071: <li>Replace the entry for <var title="">entry</var> in the list
2072: with an entry for <var title="">new element</var>.</li>
2073:
2074: <li>If the entry for <var title="">new element</var> in the
2075: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
2076: entry in the list, return to step 7.</li>
2077:
2078: </ol><p>This has the effect of reopening all the formatting elements that
2079: were opened in the current body, cell, or caption (whichever is
2080: youngest) that haven't been explicitly closed.</p>
2081:
2082: <p class="note">The way this specification is written, the
2083: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
2084: elements in chronological order with the least recently added
2085: element first and the most recently added element last (except for
2086: while steps 8 to 11 of the above algorithm are being executed, of
2087: course).</p>
2088:
2089: <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
2090: active formatting elements up to the last marker</dfn>, the UA must
2091: perform the following steps:</p>
2092:
2093: <ol><li>Let <var title="">entry</var> be the last (most recently added)
2094: entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
2095:
2096: <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
2097: formatting elements</a>.</li>
2098:
2099: <li>If <var title="">entry</var> was a marker, then stop the
2100: algorithm at this point. The list has been cleared up to the last
2101: marker.</li>
2102:
2103: <li>Go to step 1.</li>
2104:
2105: </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5>
2106:
2107: <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
2108: pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
2109: pointer</dfn> are both null.</p>
2110:
1.159 mike 2111: <p>Once a <code><a href="semantics.html#the-head-element-0">head</a></code> element has been parsed (whether
1.1 mike 2112: implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
2113: element pointer</a> gets set to point to this node.</p>
2114:
2115: <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
2116: points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
2117: whose end tag has not yet been seen. It is used to make form
2118: controls associate with forms in the face of dramatically bad
2119: markup, for historical reasons.</p>
2120:
2121:
2122: <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5>
2123:
2124: <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
2125: <code>Document</code> with which the parser is associated when the
2126: parser was created, and "disabled" otherwise.</p>
2127:
2128: <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
2129: when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
2130: parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
2131: don't execute in that case.</p>
2132:
2133: <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
2134: created. It is set to "not ok" after certain tokens are seen.</p>
2135:
1.266 mike 2136: </div><div class="impl">
1.1 mike 2137:
1.159 mike 2138: <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 2139:
2140: <p>Implementations must act as if they used the following state
2141: machine to tokenize HTML. The state machine must start in the
2142: <a href="#data-state">data state</a>. Most states consume a single character,
2143: which may have various side-effects, and either switches the state
2144: machine to a new state to <em>reconsume</em> the same character, or
2145: switches it to a new state (to consume the next character), or
2146: repeats the same state (to consume the next character). Some states
2147: have more complicated behavior and can consume several characters
2148: before switching to another state.</p>
2149:
2150: <p>The exact behavior of certain states depends on a <dfn id="content-model-flag">content
2151: model flag</dfn> that is set after certain tokens are emitted. The
1.91 mike 2152: 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
2153: state. In the RCDATA and RAWTEXT states, a further <dfn id="escape-flag">escape
1.1 mike 2154: flag</dfn> is used to control the behavior of the tokenizer. It is
2155: either true or false, and initially must be set to the false
2156: state. The <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
2157: elements</a> also affects tokenization.</p>
2158:
2159: <p>The output of the tokenization step is a series of zero or more
2160: of the following tokens: DOCTYPE, start tag, end tag, comment,
2161: character, end-of-file. DOCTYPE tokens have a name, a public
2162: identifier, a system identifier, and a <i>force-quirks
2163: flag</i>. When a DOCTYPE token is created, its name, public
2164: identifier, and system identifier must be marked as missing (which
2165: is a distinct state from the empty string), and the <i>force-quirks
2166: flag</i> must be set to <i>off</i> (its other state is
2167: <i>on</i>). Start and end tag tokens have a tag name, a
2168: <i>self-closing flag</i>, and a list of attributes, each of which
2169: has a name and a value. When a start or end tag token is created,
2170: its <i>self-closing flag</i> must be unset (its other state is that
2171: it be set), and its attributes list must be empty. Comment and
2172: character tokens have data.</p>
2173:
2174: <p>When a token is emitted, it must immediately be handled by the
2175: <a href="#tree-construction">tree construction</a> stage. The tree construction stage
2176: can affect the state of the <a href="#content-model-flag">content model flag</a>, and can
2177: insert additional characters into the stream. (For example, the
2178: <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
1.159 mike 2179: using the <a href="embedded-content-0.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
1.1 mike 2180: characters into the stream being tokenized.)</p>
2181:
2182: <p>When a start tag token is emitted with its <i>self-closing
2183: flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
2184: self-closing flag">acknowledged</dfn> when it is processed by the
2185: tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
2186:
2187: <p>When an end tag token is emitted, the <a href="#content-model-flag">content model
2188: flag</a> must be switched to the PCDATA state.</p>
2189:
2190: <p>When an end tag token is emitted with attributes, that is a
2191: <a href="#parse-error">parse error</a>.</p>
2192:
2193: <p>When an end tag token is emitted with its <i>self-closing
2194: flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
2195:
2196: <p>Before each step of the tokenizer, the user agent must first
2197: check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
2198: tokenizer must abort the processing of any nested invocations of the
1.479 mike 2199: tokenizer, yielding control back to the caller.</p>
1.1 mike 2200:
2201: <p>The tokenizer state machine consists of the states defined in the
2202: following subsections.</p>
2203:
1.333 mike 2204: <!-- Order of the lists below is supposed to be non-error then
2205: error, by unicode, then EOF, ending with "anything else" -->
1.1 mike 2206:
2207: <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5>
2208:
2209: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2210:
2211: <dl class="switch"><dt>U+0026 AMPERSAND (&)</dt>
2212: <dd>When the <a href="#content-model-flag">content model flag</a> is set to one of the
2213: PCDATA or RCDATA states and the <a href="#escape-flag">escape flag</a> is
1.299 mike 2214: false: switch to the <a href="#character-reference-in-data-state">character reference in data
1.56 mike 2215: state</a>.</dd>
2216: <dd>Otherwise: treat it as per the "anything else" entry
2217: below.</dd>
1.1 mike 2218:
2219: <dt>U+002D HYPHEN-MINUS (-)</dt>
2220: <dd>
2221:
2222: <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 2223: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1 mike 2224: is false, and there are at least three characters before this
2225: one in the input stream, and the last four characters in the
2226: input stream, including this one, are U+003C LESS-THAN SIGN,
2227: U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, and U+002D
2228: HYPHEN-MINUS ("<!--"), then set the <a href="#escape-flag">escape flag</a>
2229: to true.</p>
2230:
2231: <p>In any case, emit the input character as a character
2232: token. Stay in the <a href="#data-state">data state</a>.</p>
2233:
2234: </dd>
2235:
2236: <dt>U+003C LESS-THAN SIGN (<)</dt>
2237: <dd>When the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
2238: state: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
2239: <dd>When the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 2240: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1 mike 2241: is false: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
2242: <dd>Otherwise: treat it as per the "anything else" entry
2243: below.</dd>
2244:
2245: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2246: <dd>
2247:
2248: <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 2249: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape
1.1 mike 2250: flag</a> is true, and the last three characters in the input
2251: stream including this one are U+002D HYPHEN-MINUS, U+002D
2252: HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("-->"), set the
2253: <a href="#escape-flag">escape flag</a> to false.</p> <!-- no need to check
2254: that there are enough characters, since you can only run into
2255: this if the flag is true in the first place, which requires four
2256: characters. -->
2257:
2258: <p>In any case, emit the input character as a character
2259: token. Stay in the <a href="#data-state">data state</a>.</p>
2260:
2261: </dd>
2262:
2263: <dt>EOF</dt>
2264: <dd>Emit an end-of-file token.</dd>
2265:
2266: <dt>Anything else</dt>
2267: <dd>Emit the input character as a character token. Stay in the
2268: <a href="#data-state">data state</a>.</dd>
2269:
1.299 mike 2270: </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 2271:
2272: <p><i>(This cannot happen if the <a href="#content-model-flag">content model flag</a>
1.91 mike 2273: is set to the RAWTEXT state.)</i></p>
1.1 mike 2274:
2275: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
2276: <a href="#additional-allowed-character">additional allowed character</a>.</p>
2277:
2278: <p>If nothing is returned, emit a U+0026 AMPERSAND character
2279: token.</p>
2280:
2281: <p>Otherwise, emit the character token that was returned.</p>
2282:
2283: <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
2284:
2285:
2286: <h5 id="tag-open-state"><span class="secno">9.2.4.3 </span><dfn>Tag open state</dfn></h5>
2287:
2288: <p>The behavior of this state depends on the <a href="#content-model-flag">content model
2289: flag</a>.</p>
2290:
2291: <dl><dt>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA
1.91 mike 2292: or RAWTEXT states</dt>
1.1 mike 2293:
2294: <dd>
2295:
2296: <p>Consume the <a href="#next-input-character">next input character</a>. If it is a
1.464 mike 2297: U+002F SOLIDUS character (/), switch to the <a href="#close-tag-open-state">close tag open
1.1 mike 2298: state</a>. Otherwise, emit a U+003C LESS-THAN SIGN character
2299: token and reconsume the <a href="#current-input-character">current input character</a> in the
2300: <a href="#data-state">data state</a>.</p>
2301:
2302: </dd>
2303:
2304: <dt>If the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
2305: state</dt>
2306:
2307: <dd>
2308:
2309: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2310:
2311: <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
2312: <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
2313:
2314: <dt>U+002F SOLIDUS (/)</dt>
2315: <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
2316:
2317: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2318: <dd>Create a new start tag token, set its tag name to the
2319: lowercase version of the input character (add 0x0020 to the
2320: character's code point), then switch to the <a href="#tag-name-state">tag name
2321: state</a>. (Don't emit the token yet; further details will
2322: be filled in before it is emitted.)</dd>
2323:
2324: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2325: <dd>Create a new start tag token, set its tag name to the input
2326: character, then switch to the <a href="#tag-name-state">tag name
2327: state</a>. (Don't emit the token yet; further details will
2328: be filled in before it is emitted.)</dd>
2329:
2330: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2331: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2332: character token and a U+003E GREATER-THAN SIGN character
2333: token. Switch to the <a href="#data-state">data state</a>.</dd>
2334:
2335: <dt>U+003F QUESTION MARK (?)</dt>
2336: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2337: comment state</a>.</dd>
2338:
2339: <dt>Anything else</dt>
2340: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2341: character token and reconsume the <a href="#current-input-character">current input character</a> in the
2342: <a href="#data-state">data state</a>.</dd>
2343:
2344: </dl></dd>
2345:
2346: </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.4 </span><dfn>Close tag open state</dfn></h5>
2347:
2348: <p>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA or
1.91 mike 2349: RAWTEXT states but no start tag token has ever been emitted by this
1.1 mike 2350: instance of the tokenizer (<a href="#fragment-case">fragment case</a>), or, if the
1.91 mike 2351: <a href="#content-model-flag">content model flag</a> is set to the RCDATA or RAWTEXT states
1.1 mike 2352: and the next few characters do not match the tag name of the last
2353: start tag token emitted (compared in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2354: case-insensitive</a> manner), or if they do but they are not
2355: immediately followed by one of the following characters:</p>
2356:
2357: <ul class="brief"><li>U+0009 CHARACTER TABULATION</li>
2358: <li>U+000A LINE FEED (LF)</li>
2359: <li>U+000C FORM FEED (FF)</li>
2360: <!--<li>U+000D CARRIAGE RETURN (CR)</li>-->
2361: <li>U+0020 SPACE</li>
2362: <li>U+003E GREATER-THAN SIGN (>)</li>
2363: <li>U+002F SOLIDUS (/)</li>
2364: <li>EOF</li>
2365: </ul><p>...then emit a U+003C LESS-THAN SIGN character token, a U+002F
2366: SOLIDUS character token, and switch to the <a href="#data-state">data state</a>
2367: to process the <a href="#next-input-character">next input character</a>.</p>
2368:
2369: <p>Otherwise, if the <a href="#content-model-flag">content model flag</a> is set to the
2370: PCDATA state, or if the next few characters <em>do</em> match that tag
2371: name, consume the <a href="#next-input-character">next input character</a>:</p>
2372:
2373: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2374: <dd>Create a new end tag token, set its tag name to the lowercase
2375: version of the input character (add 0x0020 to the character's
2376: code point), then switch to the <a href="#tag-name-state">tag name
2377: state</a>. (Don't emit the token yet; further details will be
2378: filled in before it is emitted.)</dd>
2379:
2380: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2381: <dd>Create a new end tag token, set its tag name to the input
2382: character, then switch to the <a href="#tag-name-state">tag name state</a>. (Don't
2383: emit the token yet; further details will be filled in before it
2384: is emitted.)</dd>
2385:
2386: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2387: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
2388: state</a>.</dd>
2389:
2390: <dt>EOF</dt>
2391: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2392: character token and a U+002F SOLIDUS character token. Reconsume
2393: the EOF character in the <a href="#data-state">data state</a>.</dd>
2394:
2395: <dt>Anything else</dt>
2396: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2397: comment state</a>.</dd>
2398:
2399: </dl><h5 id="tag-name-state"><span class="secno">9.2.4.5 </span><dfn>Tag name state</dfn></h5>
2400:
2401: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2402:
2403: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2404: <dt>U+000A LINE FEED (LF)</dt>
2405: <dt>U+000C FORM FEED (FF)</dt>
2406: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2407: <dt>U+0020 SPACE</dt>
2408: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2409:
2410: <dt>U+002F SOLIDUS (/)</dt>
2411: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2412:
2413: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2414: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2415: state</a>.</dd>
2416:
2417: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2418: <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
2419: (add 0x0020 to the character's code point) to the current tag
2420: token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
2421:
2422: <dt>EOF</dt>
2423: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2424: <a href="#data-state">data state</a>.</dd>
2425:
2426: <dt>Anything else</dt>
2427: <dd>Append the <a href="#current-input-character">current input character</a> to the current tag token's
2428: tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
2429:
2430: </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.6 </span><dfn>Before attribute name state</dfn></h5>
2431:
2432: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2433:
2434: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2435: <dt>U+000A LINE FEED (LF)</dt>
2436: <dt>U+000C FORM FEED (FF)</dt>
2437: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2438: <dt>U+0020 SPACE</dt>
2439: <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2440:
2441: <dt>U+002F SOLIDUS (/)</dt>
2442: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2443:
2444: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2445: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2446: state</a>.</dd>
2447:
2448: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2449: <dd>Start a new attribute in the current tag token. Set that
2450: attribute's name to the lowercase version of the <a href="#current-input-character">current input
2451: character</a> (add 0x0020 to the character's code point), and its
2452: value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
2453: state</a>.</dd>
2454:
2455: <dt>U+0022 QUOTATION MARK (")</dt>
2456: <dt>U+0027 APOSTROPHE (')</dt>
2457: <dt>U+003C LESS-THAN SIGN (<)</dt>
2458: <dt>U+003D EQUALS SIGN (=)</dt>
2459: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2460: entry below.</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>Start a new attribute in the current tag token. Set that
2468: attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
2469: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2470: state</a>.</dd>
2471:
2472: </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.7 </span><dfn>Attribute name state</dfn></h5>
2473:
2474: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2475:
2476: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2477: <dt>U+000A LINE FEED (LF)</dt>
2478: <dt>U+000C FORM FEED (FF)</dt>
2479: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2480: <dt>U+0020 SPACE</dt>
2481: <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
2482:
2483: <dt>U+002F SOLIDUS (/)</dt>
2484: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2485:
2486: <dt>U+003D EQUALS SIGN (=)</dt>
2487: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2488:
2489: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2490: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2491: state</a>.</dd>
2492:
2493: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2494: <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
2495: (add 0x0020 to the character's code point) to the current
2496: attribute's name. Stay in the <a href="#attribute-name-state">attribute name
2497: state</a>.</dd>
2498:
2499: <dt>U+0022 QUOTATION MARK (")</dt>
2500: <dt>U+0027 APOSTROPHE (')</dt>
2501: <dt>U+003C LESS-THAN SIGN (<)</dt>
2502: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2503: entry below.</dd>
2504:
2505: <dt>EOF</dt>
2506: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2507: <a href="#data-state">data state</a>.</dd>
2508:
2509: <dt>Anything else</dt>
2510: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2511: name. Stay in the <a href="#attribute-name-state">attribute name state</a>.</dd>
2512:
2513: </dl><p>When the user agent leaves the attribute name state (and before
2514: emitting the tag token, if appropriate), the complete attribute's
2515: name must be compared to the other attributes on the same token;
2516: if there is already an attribute on the token with the exact same
2517: name, then this is a <a href="#parse-error">parse error</a> and the new
2518: attribute must be dropped, along with the value that gets
2519: associated with it (if any).</p>
2520:
2521:
2522: <h5 id="after-attribute-name-state"><span class="secno">9.2.4.8 </span><dfn>After attribute name state</dfn></h5>
2523:
2524: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2525:
2526: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2527: <dt>U+000A LINE FEED (LF)</dt>
2528: <dt>U+000C FORM FEED (FF)</dt>
2529: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2530: <dt>U+0020 SPACE</dt>
2531: <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
2532:
2533: <dt>U+002F SOLIDUS (/)</dt>
2534: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2535:
2536: <dt>U+003D EQUALS SIGN (=)</dt>
2537: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2538:
2539: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2540: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2541: state</a>.</dd>
2542:
2543: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2544: <dd>Start a new attribute in the current tag token. Set that
2545: attribute's name to the lowercase version of the <a href="#current-input-character">current input character</a>
2546: (add 0x0020 to the character's code point), and its value to
2547: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2548: state</a>.</dd>
2549:
2550: <dt>U+0022 QUOTATION MARK (")</dt>
2551: <dt>U+0027 APOSTROPHE (')</dt>
2552: <dt>U+003C LESS-THAN SIGN (<)</dt>
2553: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2554: entry below.</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>Start a new attribute in the current tag token. Set that
2562: attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
2563: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2564: state</a>.</dd>
2565:
2566: </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.9 </span><dfn>Before attribute value state</dfn></h5>
2567:
2568: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2569:
2570: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2571: <dt>U+000A LINE FEED (LF)</dt>
2572: <dt>U+000C FORM FEED (FF)</dt>
2573: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2574: <dt>U+0020 SPACE</dt>
2575: <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2576:
2577: <dt>U+0022 QUOTATION MARK (")</dt>
2578: <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
2579:
2580: <dt>U+0026 AMPERSAND (&)</dt>
2581: <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
2582: and reconsume this input character.</dd>
2583:
2584: <dt>U+0027 APOSTROPHE (')</dt>
2585: <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
2586:
2587: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2588: <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
2589: the <a href="#data-state">data state</a>.</dd>
2590:
2591: <dt>U+003C LESS-THAN SIGN (<)</dt>
2592: <dt>U+003D EQUALS SIGN (=)</dt>
1.463 mike 2593: <dt>U+0060 GRAVE ACCENT (`)</dt>
1.1 mike 2594: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2595: entry below.</dd>
2596:
2597: <dt>EOF</dt>
2598: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2599: <a href="#data-state">data state</a>.</dd>
2600:
2601: <dt>Anything else</dt>
2602: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2603: attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
2604: state</a>.</dd>
2605:
2606: </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.10 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
2607:
2608: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2609:
2610: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
2611: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
2612: state</a>.</dd>
2613:
2614: <dt>U+0026 AMPERSAND (&)</dt>
2615: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
2616: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2617: being U+0022 QUOTATION MARK (").</dd>
2618:
2619: <dt>EOF</dt>
2620: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2621: <a href="#data-state">data state</a>.</dd>
2622:
2623: <dt>Anything else</dt>
2624: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2625: value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted)
2626: state</a>.</dd>
2627:
2628: </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.11 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
2629:
2630: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2631:
2632: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
2633: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
2634: state</a>.</dd>
2635:
2636: <dt>U+0026 AMPERSAND (&)</dt>
2637: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
2638: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2639: being U+0027 APOSTROPHE (').</dd>
2640:
2641: <dt>EOF</dt>
2642: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2643: <a href="#data-state">data state</a>.</dd>
2644:
2645: <dt>Anything else</dt>
2646: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2647: value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted)
2648: state</a>.</dd>
2649:
2650: </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.12 </span><dfn>Attribute value (unquoted) state</dfn></h5>
2651:
2652: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2653:
2654: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2655: <dt>U+000A LINE FEED (LF)</dt>
2656: <dt>U+000C FORM FEED (FF)</dt>
2657: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2658: <dt>U+0020 SPACE</dt>
2659: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2660:
2661: <dt>U+0026 AMPERSAND (&)</dt>
2662: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
1.299 mike 2663: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2664: being U+003E GREATER-THAN SIGN (>).</dd>
1.1 mike 2665:
2666: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2667: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2668: state</a>.</dd>
2669:
2670: <dt>U+0022 QUOTATION MARK (")</dt>
2671: <dt>U+0027 APOSTROPHE (')</dt>
2672: <dt>U+003C LESS-THAN SIGN (<)</dt>
2673: <dt>U+003D EQUALS SIGN (=)</dt>
1.463 mike 2674: <dt>U+0060 GRAVE ACCENT (`)</dt>
1.1 mike 2675: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2676: entry below.</dd>
2677:
2678: <dt>EOF</dt>
2679: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2680: <a href="#data-state">data state</a>.</dd>
2681:
2682: <dt>Anything else</dt>
2683: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2684: value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
2685: state</a>.</dd>
2686:
2687: </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>
2688:
2689: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
2690:
2691: <p>If nothing is returned, append a U+0026 AMPERSAND character to
2692: the current attribute's value.</p>
2693:
2694: <p>Otherwise, append the returned character token to the current
2695: attribute's value.</p>
2696:
2697: <p>Finally, switch back to the attribute value state that you were
2698: in when were switched into this state.</p>
2699:
2700:
2701: <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.14 </span><dfn>After attribute value (quoted) state</dfn></h5>
2702:
2703: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2704:
2705: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2706: <dt>U+000A LINE FEED (LF)</dt>
2707: <dt>U+000C FORM FEED (FF)</dt>
2708: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2709: <dt>U+0020 SPACE</dt>
2710: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2711:
2712: <dt>U+002F SOLIDUS (/)</dt>
2713: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2714:
2715: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2716: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2717: state</a>.</dd>
2718:
2719: <dt>EOF</dt>
2720: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2721: <a href="#data-state">data state</a>.</dd>
2722:
2723: <dt>Anything else</dt>
2724: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
2725: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2726:
2727: </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.15 </span><dfn>Self-closing start tag state</dfn></h5>
2728:
2729: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2730:
2731: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2732: <dd>Set the <i>self-closing flag</i> of the current tag
2733: token. Emit the current tag token. Switch to the <a href="#data-state">data
2734: state</a>.</dd>
2735:
2736: <dt>EOF</dt>
2737: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2738: <a href="#data-state">data state</a>.</dd>
2739:
2740: <dt>Anything else</dt>
2741: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
2742: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2743:
2744: </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.16 </span><dfn>Bogus comment state</dfn></h5>
2745:
2746: <p><i>(This can only happen if the <a href="#content-model-flag">content model
2747: flag</a> is set to the PCDATA state.)</i></p>
2748:
2749: <p>Consume every character up to and including the first U+003E
2750: GREATER-THAN SIGN character (>) or the end of the file (EOF),
2751: whichever comes first. Emit a comment token whose data is the
2752: concatenation of all the characters starting from and including
2753: the character that caused the state machine to switch into the
2754: bogus comment state, up to and including the character immediately
2755: before the last consumed character (i.e. up to the character just
2756: before the U+003E or EOF character). (If the comment was started
2757: by the end of the file (EOF), the token is empty.)</p>
2758:
2759: <p>Switch to the <a href="#data-state">data state</a>.</p>
2760:
2761: <p>If the end of the file was reached, reconsume the EOF
2762: character.</p>
2763:
2764:
2765: <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.17 </span><dfn>Markup declaration open state</dfn></h5>
2766:
2767: <p><i>(This can only happen if the <a href="#content-model-flag">content model
2768: flag</a> is set to the PCDATA state.)</i></p>
2769:
2770: <p>If the next two characters are both U+002D HYPHEN-MINUS (-)
2771: characters, consume those two characters, create a comment token
2772: whose data is the empty string, and switch to the <a href="#comment-start-state">comment
2773: start state</a>.</p>
2774:
2775: <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2776: case-insensitive</a> match for the word "DOCTYPE", then consume
2777: those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
2778:
2779: <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
2780: content</a>" and the <a href="#current-node">current node</a> is not an element
2781: in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
2782: an <span>ASCII case-sensitive</span> match for the string "[CDATA["
2783: (the five uppercase letters "CDATA" with a U+005B LEFT SQUARE
2784: BRACKET character before and after), then consume those characters
1.91 mike 2785: and switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1 mike 2786:
2787: <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
2788: <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
2789: consumed, if any, is the first character that will be in the
2790: comment.</p>
2791:
2792:
2793: <h5 id="comment-start-state"><span class="secno">9.2.4.18 </span><dfn>Comment start state</dfn></h5>
2794:
2795: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2796:
2797: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2798: <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
2799:
2800: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2801: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
2802: <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
2803: -->
2804:
2805: <dt>EOF</dt>
2806: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2807: the EOF character in the <a href="#data-state">data state</a>.</dd>
2808:
2809: <dt>Anything else</dt>
2810: <dd>Append the input character to the comment token's
2811: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
2812:
2813: </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.19 </span><dfn>Comment start dash state</dfn></h5>
2814:
2815: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2816:
2817: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2818: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
2819:
2820: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2821: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
2822: the <a href="#data-state">data state</a>.</dd>
2823:
2824: <dt>EOF</dt>
2825: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2826: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2827: in comment end state -->
2828:
2829: <dt>Anything else</dt>
1.464 mike 2830: <dd>Append a U+002D HYPHEN-MINUS character (-) and the input
1.1 mike 2831: character to the comment token's data. Switch to the
2832: <a href="#comment-state">comment state</a>.</dd>
2833:
2834: </dl><h5 id="comment-state"><span class="secno">9.2.4.20 </span><dfn id="comment">Comment state</dfn></h5>
2835:
2836: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2837:
2838: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2839: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
2840:
2841: <dt>EOF</dt>
2842: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2843: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2844: in comment end state -->
2845:
2846: <dt>Anything else</dt>
2847: <dd>Append the input character to the comment token's data. Stay
2848: in the <a href="#comment-state">comment state</a>.</dd>
2849:
2850: </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.21 </span><dfn>Comment end dash state</dfn></h5>
2851:
2852: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2853:
2854: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2855: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
2856:
2857: <dt>EOF</dt>
2858: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2859: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2860: in comment end state -->
2861:
2862: <dt>Anything else</dt>
1.464 mike 2863: <dd>Append a U+002D HYPHEN-MINUS character (-) and the input
1.1 mike 2864: character to the comment token's data. Switch to the
2865: <a href="#comment-state">comment state</a>.</dd>
2866:
2867: </dl><h5 id="comment-end-state"><span class="secno">9.2.4.22 </span><dfn>Comment end state</dfn></h5>
2868:
2869: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2870:
2871: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2872: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2873: state</a>.</dd>
2874:
2875: <dt>U+0009 CHARACTER TABULATION</dt>
2876: <dt>U+000A LINE FEED (LF)</dt>
2877: <dt>U+000C FORM FEED (FF)</dt>
2878: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2879: <dt>U+0020 SPACE</dt>
2880: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
2881: characters and the input character to the comment token's
2882: data. Switch to the <a href="#comment-end-space-state">comment end space state</a>.</dd>
2883:
2884: <dt>U+0021 EXCLAMATION MARK (!)</dt>
2885: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
2886: state</a>.</dd>
2887:
1.333 mike 2888: <dt>U+002D HYPHEN-MINUS (-)</dt>
2889: <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
1.464 mike 2890: character (-) to the comment token's data. Stay in the
1.333 mike 2891: <a href="#comment-end-state">comment end state</a>.</dd>
2892:
1.1 mike 2893: <dt>EOF</dt>
2894: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2895: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
2896: security reasons: otherwise, hostile user could put a <script> in
2897: a comment e.g. in a blog comment and then DOS the server so that
2898: the end tag isn't read, and then the commented <script> tag would
2899: be treated as live code -->
2900:
2901: <dt>Anything else</dt>
2902: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
2903: characters and the input character to the comment token's
2904: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
2905:
2906: </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.23 </span><dfn>Comment end bang state</dfn></h5>
2907:
2908: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2909:
1.333 mike 2910: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
1.1 mike 2911: <dd>Append two U+002D HYPHEN-MINUS (-) characters and a U+0021
1.464 mike 2912: EXCLAMATION MARK character (!) to the comment token's data. Switch
1.1 mike 2913: to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
2914:
1.333 mike 2915: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2916: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2917: state</a>.</dd>
2918:
1.1 mike 2919: <dt>EOF</dt>
2920: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2921: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
2922: comment in comment end state -->
2923:
2924: <dt>Anything else</dt>
2925: <dd>Append two U+002D HYPHEN-MINUS (-) characters, a U+0021
1.464 mike 2926: EXCLAMATION MARK character (!), and the input character to the
1.1 mike 2927: comment token's data. Switch to the <a href="#comment-state">comment
2928: state</a>.</dd>
2929:
2930: </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.24 </span><dfn>Comment end space state</dfn></h5>
2931:
2932: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2933:
1.333 mike 2934: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
1.1 mike 2935: <dt>U+000A LINE FEED (LF)</dt>
2936: <dt>U+000C FORM FEED (FF)</dt>
2937: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2938: <dt>U+0020 SPACE</dt>
2939: <dd>Append the input character to the comment token's data. Stay in
2940: the <a href="#comment-end-space-state">comment end space state</a>.</dd>
2941:
1.333 mike 2942: <dt>U+002D HYPHEN-MINUS (-)</dt>
2943: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
2944:
2945: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2946: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2947: state</a>.</dd>
2948:
1.1 mike 2949: <dt>EOF</dt>
2950: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2951: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
2952: comment in comment end state -->
2953:
2954: <dt>Anything else</dt>
2955: <dd>Append the input character to the comment token's data. Switch
2956: to the <a href="#comment-state">comment state</a>.</dd>
2957:
2958: </dl><h5 id="doctype-state"><span class="secno">9.2.4.25 </span><dfn>DOCTYPE state</dfn></h5>
2959:
2960: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2961:
2962: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2963: <dt>U+000A LINE FEED (LF)</dt>
2964: <dt>U+000C FORM FEED (FF)</dt>
2965: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2966: <dt>U+0020 SPACE</dt>
2967: <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2968:
2969: <dt>EOF</dt>
2970: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2971: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
2972: the EOF character in the <a href="#data-state">data state</a>.</dd>
2973:
2974: <dt>Anything else</dt>
2975: <dd><a href="#parse-error">Parse error</a>. Reconsume the current
2976: character in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2977:
2978: </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.26 </span><dfn>Before DOCTYPE name state</dfn></h5>
2979:
2980: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2981:
2982: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2983: <dt>U+000A LINE FEED (LF)</dt>
2984: <dt>U+000C FORM FEED (FF)</dt>
2985: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2986: <dt>U+0020 SPACE</dt>
2987: <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2988:
2989: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2990: <dd>Create a new DOCTYPE token. Set the token's name to the
2991: lowercase version of the input character (add 0x0020 to the
2992: character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
2993: state</a>.</dd>
2994:
1.333 mike 2995: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2996: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2997: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
2998: the <a href="#data-state">data state</a>.</dd>
2999:
1.1 mike 3000: <dt>EOF</dt>
3001: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
3002: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
3003: the EOF character in the <a href="#data-state">data state</a>.</dd>
3004:
3005: <dt>Anything else</dt>
3006: <dd>Create a new DOCTYPE token. Set the token's name to the
3007: <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
3008: state</a>.</dd>
3009:
3010: </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.27 </span><dfn>DOCTYPE name state</dfn></h5>
3011:
3012: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3013:
3014: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3015: <dt>U+000A LINE FEED (LF)</dt>
3016: <dt>U+000C FORM FEED (FF)</dt>
3017: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3018: <dt>U+0020 SPACE</dt>
3019: <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
3020:
3021: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3022: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3023: state</a>.</dd>
3024:
3025: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
3026: <dd>Append the lowercase version of the input character (add 0x0020
3027: to the character's code point) to the current DOCTYPE token's
3028: name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
3029:
3030: <dt>EOF</dt>
3031: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3032: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3033: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3034:
3035: <dt>Anything else</dt>
3036: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3037: token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
3038:
3039: </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.28 </span><dfn>After DOCTYPE name state</dfn></h5>
3040:
3041: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3042:
3043: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3044: <dt>U+000A LINE FEED (LF)</dt>
3045: <dt>U+000C FORM FEED (FF)</dt>
3046: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3047: <dt>U+0020 SPACE</dt>
3048: <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
3049:
3050: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3051: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3052: state</a>.</dd>
3053:
3054: <dt>EOF</dt>
3055: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3056: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3057: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3058:
3059: <dt>Anything else</dt>
3060: <dd>
3061:
3062: <p>If the six characters starting from the <a href="#current-input-character">current input
3063: character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
3064: for the word "PUBLIC", then consume those characters and switch to
1.444 mike 3065: the <a href="#after-doctype-public-keyword-state">after DOCTYPE public keyword state</a>.</p>
1.1 mike 3066:
3067: <p>Otherwise, if the six characters starting from the
3068: <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
3069: case-insensitive</a> match for the word "SYSTEM", then consume
1.444 mike 3070: those characters and switch to the <a href="#after-doctype-system-keyword-state">after DOCTYPE system
3071: keyword state</a>.</p>
1.1 mike 3072:
3073: <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
3074: DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
3075: the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
3076:
3077: </dd>
3078:
1.444 mike 3079: </dl><h5 id="after-doctype-public-keyword-state"><span class="secno">9.2.4.29 </span><dfn>After DOCTYPE public keyword state</dfn></h5>
3080:
3081: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3082:
3083: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3084: <dt>U+000A LINE FEED (LF)</dt>
3085: <dt>U+000C FORM FEED (FF)</dt>
3086: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3087: <dt>U+0020 SPACE</dt>
3088: <dd>Switch to the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier
3089: state</a>.</dd>
3090:
3091: <dt>EOF</dt>
3092: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3093: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3094: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3095:
3096: <dt>Anything else</dt>
3097: <dd><a href="#parse-error">Parse error</a>. Reconsume the current character in
3098: the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
3099:
3100: </dl><h5 id="before-doctype-public-identifier-state"><span class="secno">9.2.4.30 </span><dfn>Before DOCTYPE public identifier state</dfn></h5>
1.1 mike 3101:
3102: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3103:
3104: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3105: <dt>U+000A LINE FEED (LF)</dt>
3106: <dt>U+000C FORM FEED (FF)</dt>
3107: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3108: <dt>U+0020 SPACE</dt>
3109: <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
3110:
3111: <dt>U+0022 QUOTATION MARK (")</dt>
3112: <dd>Set the DOCTYPE token's public identifier to the empty string
3113: (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
3114: (double-quoted) state</a>.</dd>
3115:
3116: <dt>U+0027 APOSTROPHE (')</dt>
3117: <dd>Set the DOCTYPE token's public identifier to the empty string
3118: (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
3119: (single-quoted) state</a>.</dd>
3120:
3121: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3122: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3123: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3124: token. Switch to the <a href="#data-state">data state</a>.</dd>
3125:
3126: <dt>EOF</dt>
3127: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3128: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3129: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3130:
3131: <dt>Anything else</dt>
3132: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3133: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3134: DOCTYPE state</a>.</dd>
3135:
1.444 mike 3136: </dl><h5 id="doctype-public-identifier-double-quoted-state"><span class="secno">9.2.4.31 </span><dfn>DOCTYPE public identifier (double-quoted) state</dfn></h5>
1.1 mike 3137:
3138: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3139:
3140: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
3141: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
3142:
3143: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3144: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3145: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3146: token. Switch to the <a href="#data-state">data state</a>.</dd>
3147:
3148: <dt>EOF</dt>
3149: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3150: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3151: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3152:
3153: <dt>Anything else</dt>
3154: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3155: token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
3156: identifier (double-quoted) state</a>.</dd>
3157:
1.444 mike 3158: </dl><h5 id="doctype-public-identifier-single-quoted-state"><span class="secno">9.2.4.32 </span><dfn>DOCTYPE public identifier (single-quoted) state</dfn></h5>
1.1 mike 3159:
3160: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3161:
3162: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
3163: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
3164:
3165: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3166: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3167: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3168: token. Switch to the <a href="#data-state">data state</a>.</dd>
3169:
3170: <dt>EOF</dt>
3171: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3172: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3173: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3174:
3175: <dt>Anything else</dt>
3176: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3177: token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
3178: identifier (single-quoted) state</a>.</dd>
3179:
1.444 mike 3180: </dl><h5 id="after-doctype-public-identifier-state"><span class="secno">9.2.4.33 </span><dfn>After DOCTYPE public identifier state</dfn></h5>
1.1 mike 3181:
3182: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3183:
3184: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3185: <dt>U+000A LINE FEED (LF)</dt>
3186: <dt>U+000C FORM FEED (FF)</dt>
3187: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3188: <dt>U+0020 SPACE</dt>
1.444 mike 3189: <dd>Switch to the <a href="#between-doctype-public-and-system-identifiers-state">between DOCTYPE public and system identifiers state</a>.</dd>
3190:
3191: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3192: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3193: state</a>.</dd>
3194:
3195: <dt>U+0022 QUOTATION MARK (")</dt>
3196: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
3197: identifier to the empty string (not missing), then switch to the
3198: <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier (double-quoted) state</a>.</dd>
3199:
3200: <dt>U+0027 APOSTROPHE (')</dt>
3201: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
3202: identifier to the empty string (not missing), then switch to the
3203: <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier (single-quoted) state</a>.</dd>
3204:
3205: <dt>EOF</dt>
3206: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3207: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3208: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3209:
3210: <dt>Anything else</dt>
3211: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3212: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3213: DOCTYPE state</a>.</dd>
3214:
3215: </dl><h5 id="between-doctype-public-and-system-identifiers-state"><span class="secno">9.2.4.34 </span><dfn>Between DOCTYPE public and system identifiers state</dfn></h5>
3216:
3217: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3218:
3219: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3220: <dt>U+000A LINE FEED (LF)</dt>
3221: <dt>U+000C FORM FEED (FF)</dt>
3222: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3223: <dt>U+0020 SPACE</dt>
3224: <dd>Stay in the <a href="#between-doctype-public-and-system-identifiers-state">between DOCTYPE public and system identifiers state</a>.</dd>
3225:
3226: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3227: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3228: state</a>.</dd>
1.1 mike 3229:
3230: <dt>U+0022 QUOTATION MARK (")</dt>
3231: <dd>Set the DOCTYPE token's system identifier to the empty string
3232: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
3233: (double-quoted) state</a>.</dd>
3234:
3235: <dt>U+0027 APOSTROPHE (')</dt>
3236: <dd>Set the DOCTYPE token's system identifier to the empty string
3237: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
3238: (single-quoted) state</a>.</dd>
3239:
3240: <dt>EOF</dt>
3241: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3242: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3243: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3244:
3245: <dt>Anything else</dt>
3246: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3247: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3248: DOCTYPE state</a>.</dd>
3249:
1.444 mike 3250: </dl><h5 id="after-doctype-system-keyword-state"><span class="secno">9.2.4.35 </span><dfn>After DOCTYPE system keyword state</dfn></h5>
3251:
3252: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3253:
3254: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3255: <dt>U+000A LINE FEED (LF)</dt>
3256: <dt>U+000C FORM FEED (FF)</dt>
3257: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3258: <dt>U+0020 SPACE</dt>
3259: <dd>Switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier
3260: state</a>.</dd>
3261:
3262: <dt>EOF</dt>
3263: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3264: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3265: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3266:
3267: <dt>Anything else</dt>
3268: <dd><a href="#parse-error">Parse error</a>. Reconsume the current character in
3269: the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
3270:
3271: </dl><h5 id="before-doctype-system-identifier-state"><span class="secno">9.2.4.36 </span><dfn>Before DOCTYPE system identifier state</dfn></h5>
1.1 mike 3272:
3273: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3274:
3275: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3276: <dt>U+000A LINE FEED (LF)</dt>
3277: <dt>U+000C FORM FEED (FF)</dt>
3278: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3279: <dt>U+0020 SPACE</dt>
3280: <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
3281:
3282: <dt>U+0022 QUOTATION MARK (")</dt>
3283: <dd>Set the DOCTYPE token's system identifier to the empty string
3284: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
3285: (double-quoted) state</a>.</dd>
3286:
3287: <dt>U+0027 APOSTROPHE (')</dt>
3288: <dd>Set the DOCTYPE token's system identifier to the empty string
3289: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
3290: (single-quoted) state</a>.</dd>
3291:
3292: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3293: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3294: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3295: token. Switch to the <a href="#data-state">data state</a>.</dd>
3296:
3297: <dt>EOF</dt>
3298: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3299: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3300: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3301:
3302: <dt>Anything else</dt>
3303: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3304: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3305: DOCTYPE state</a>.</dd>
3306:
1.444 mike 3307: </dl><h5 id="doctype-system-identifier-double-quoted-state"><span class="secno">9.2.4.37 </span><dfn>DOCTYPE system identifier (double-quoted) state</dfn></h5>
1.1 mike 3308:
3309: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3310:
3311: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
3312: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
3313:
3314: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3315: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3316: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3317: token. Switch to the <a href="#data-state">data state</a>.</dd>
3318:
3319: <dt>EOF</dt>
3320: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3321: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3322: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3323:
3324: <dt>Anything else</dt>
3325: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3326: token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
3327: identifier (double-quoted) state</a>.</dd>
3328:
1.444 mike 3329: </dl><h5 id="doctype-system-identifier-single-quoted-state"><span class="secno">9.2.4.38 </span><dfn>DOCTYPE system identifier (single-quoted) state</dfn></h5>
1.1 mike 3330:
3331: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3332:
3333: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
3334: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
3335:
3336: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3337: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3338: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3339: token. Switch to the <a href="#data-state">data state</a>.</dd>
3340:
3341: <dt>EOF</dt>
3342: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3343: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3344: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3345:
3346: <dt>Anything else</dt>
3347: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3348: token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
3349: identifier (single-quoted) state</a>.</dd>
3350:
1.444 mike 3351: </dl><h5 id="after-doctype-system-identifier-state"><span class="secno">9.2.4.39 </span><dfn>After DOCTYPE system identifier state</dfn></h5>
1.1 mike 3352:
3353: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3354:
3355: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3356: <dt>U+000A LINE FEED (LF)</dt>
3357: <dt>U+000C FORM FEED (FF)</dt>
3358: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3359: <dt>U+0020 SPACE</dt>
3360: <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
3361:
3362: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3363: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3364: state</a>.</dd>
3365:
3366: <dt>EOF</dt>
3367: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3368: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3369: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3370:
3371: <dt>Anything else</dt>
3372: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
3373: state</a>. (This does <em>not</em> set the DOCTYPE token's
3374: <i>force-quirks flag</i> to <i>on</i>.)</dd>
3375:
1.444 mike 3376: </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.40 </span><dfn>Bogus DOCTYPE state</dfn></h5>
1.1 mike 3377:
3378: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3379:
3380: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
3381: <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
3382: state</a>.</dd>
3383:
3384: <dt>EOF</dt>
3385: <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
3386: <a href="#data-state">data state</a>.</dd>
3387:
3388: <dt>Anything else</dt>
3389: <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
3390:
1.444 mike 3391: </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.41 </span><dfn>CDATA section state</dfn></h5>
1.1 mike 3392:
3393: <p><i>(This can only happen if the <a href="#content-model-flag">content model
1.91 mike 3394: flag</a> is set to the PCDATA state.)</i></p>
1.1 mike 3395:
3396: <p>Consume every character up to the next occurrence of the three
3397: character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
3398: BRACKET U+003E GREATER-THAN SIGN (<code title="">]]></code>), or the
3399: end of the file (EOF), whichever comes first. Emit a series of
3400: character tokens consisting of all the characters consumed except
3401: the matching three character sequence at the end (if one was found
3402: before the end of the file).</p>
3403:
3404: <p>Switch to the <a href="#data-state">data state</a>.</p>
3405:
3406: <p>If the end of the file was reached, reconsume the EOF
3407: character.</p>
3408:
3409:
3410:
1.444 mike 3411: <h5 id="tokenizing-character-references"><span class="secno">9.2.4.42 </span>Tokenizing character references</h5>
1.1 mike 3412:
3413: <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
3414: reference</dfn>. This definition is used when parsing character
1.299 mike 3415: references <a href="#character-reference-in-data-state" title="character reference in data state">in
1.1 mike 3416: text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
3417: state">in attributes</a>.</p>
3418:
3419: <p>The behavior depends on the identity of the next character (the
3420: one immediately after the U+0026 AMPERSAND character):</p>
3421:
3422: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3423: <dt>U+000A LINE FEED (LF)</dt>
3424: <dt>U+000C FORM FEED (FF)</dt>
3425: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3426: <dt>U+0020 SPACE</dt>
3427: <dt>U+003C LESS-THAN SIGN</dt>
3428: <dt>U+0026 AMPERSAND</dt>
3429: <dt>EOF</dt>
3430: <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
3431:
3432: <dd>Not a character reference. No characters are consumed, and
3433: nothing is returned. (This is not an error, either.)</dd>
3434:
3435:
3436: <dt>U+0023 NUMBER SIGN (#)</dt>
3437:
3438: <dd>
3439:
3440: <p>Consume the U+0023 NUMBER SIGN.</p>
3441:
3442: <p>The behavior further depends on the character after the U+0023
3443: NUMBER SIGN:</p>
3444:
3445: <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
3446: <dt>U+0058 LATIN CAPITAL LETTER X</dt>
3447:
3448: <dd>
3449:
3450: <p>Consume the X.</p>
3451:
3452: <p>Follow the steps below, but using the range of characters
1.464 mike 3453: U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), U+0061 LATIN
3454: SMALL LETTER A to U+0066 LATIN SMALL LETTER F, and U+0041 LATIN
3455: CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F (in other
3456: words, 0-9, A-F, a-f).</p>
1.1 mike 3457:
3458: <p>When it comes to interpreting the number, interpret it as a
3459: hexadecimal number.</p>
3460:
3461: </dd>
3462:
3463:
3464: <dt>Anything else</dt>
3465:
3466: <dd>
3467:
3468: <p>Follow the steps below, but using the range of characters
1.464 mike 3469: U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9).</p>
1.1 mike 3470:
3471: <p>When it comes to interpreting the number, interpret it as a
3472: decimal number.</p>
3473:
3474: </dd>
3475:
3476: </dl><p>Consume as many characters as match the range of characters
3477: given above.</p>
3478:
3479: <p>If no characters match the range, then don't consume any
3480: characters (and unconsume the U+0023 NUMBER SIGN character and, if
3481: appropriate, the X character). This is a <a href="#parse-error">parse
3482: error</a>; nothing is returned.</p>
3483:
3484: <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
3485: that too. If it isn't, there is a <a href="#parse-error">parse
3486: error</a>.</p>
3487:
3488: <p>If one or more characters match the range, then take them all
3489: and interpret the string of characters as a number (either
3490: hexadecimal or decimal as appropriate).</p>
3491:
3492: <p>If that number is one of the numbers in the first column of the
3493: following table, then this is a <a href="#parse-error">parse error</a>. Find the
3494: row with that number in the first column, and return a character
3495: token for the Unicode character given in the second column of that
3496: row.</p>
3497:
3498: <table><thead><tr><th>Number </th><th colspan="2">Unicode character
3499: </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
3500: </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
1.464 mike 3501: </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN (€)
1.1 mike 3502: </td></tr><tr><td>0x81 </td><td>U+0081 </td><td><control>
1.464 mike 3503: </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK (‚)
3504: </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK (ƒ)
3505: </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK („)
3506: </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS (…)
3507: </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER (†)
3508: </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER (‡)
3509: </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT (ˆ)
3510: </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN (‰)
3511: </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON (Š)
3512: </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK (‹)
3513: </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE (Œ)
1.1 mike 3514: </td></tr><tr><td>0x8D </td><td>U+008D </td><td><control>
1.464 mike 3515: </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON (Ž)
1.1 mike 3516: </td></tr><tr><td>0x8F </td><td>U+008F </td><td><control>
3517: </td></tr><tr><td>0x90 </td><td>U+0090 </td><td><control>
1.464 mike 3518: </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK (‘)
3519: </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK (’)
3520: </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK (“)
3521: </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK (”)
3522: </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET (•)
3523: </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH (–)
3524: </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH (—)
3525: </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE (˜)
3526: </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN (™)
3527: </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON (š)
3528: </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK (›)
3529: </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE (œ)
1.1 mike 3530: </td></tr><tr><td>0x9D </td><td>U+009D </td><td><control>
1.464 mike 3531: </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON (ž)
3532: </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS (Ÿ)
1.315 mike 3533: </td></tr></tbody></table><p>Otherwise, if the number is in the range 0xD800 to 0xDFFF<!--
3534: surrogates not allowed; see the comment in the "preprocessing the
3535: input stream" section for details --> or is greater than 0x10FFFF,
3536: then this is a <a href="#parse-error">parse error</a>. Return a U+FFFD
3537: REPLACEMENT CHARACTER.</p>
1.18 mike 3538:
3539: <p>Otherwise, return a character token for the Unicode character
1.1 mike 3540: whose code point is that number.
3541:
3542: <!-- this is the same as the equivalent list in the input stream
3543: section -->
3544: If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
3545: allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
3546: allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
1.315 mike 3547: 0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xFDD0 to
3548: 0xFDEF, or is one of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF,
3549: 0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE,
3550: 0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF,
3551: 0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE,
3552: 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF,
3553: 0x10FFFE, or 0x10FFFF, then this is a <a href="#parse-error">parse
3554: error</a>.</p>
1.1 mike 3555:
3556: </dd>
3557:
3558:
3559: <dt>Anything else</dt>
3560:
3561: <dd>
3562:
3563: <p>Consume the maximum number of characters possible, with the
3564: consumed characters matching one of the identifiers in the first
3565: column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
3566: <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
3567:
3568: <p>If no match can be made, then this is a <a href="#parse-error">parse
3569: error</a>. No characters are consumed, and nothing is
3570: returned.</p>
3571:
3572: <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>
3573:
3574: <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
3575: attribute</a>, and the last character matched is not a U+003B
1.464 mike 3576: SEMICOLON character (<code title="">;</code>), and the next
3577: character is in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT
3578: NINE (9), U+0041 LATIN CAPITAL LETTER A to U+005A LATIN CAPITAL
3579: LETTER Z, or U+0061 LATIN SMALL LETTER A to U+007A LATIN SMALL
3580: LETTER Z, then, for historical reasons, all the characters that
3581: were matched after the U+0026 AMPERSAND character (&) must be
3582: unconsumed, and nothing is returned.</p>
1.1 mike 3583:
3584: <p>Otherwise, return a character token for the character
3585: corresponding to the character reference name (as given by the
3586: second column of the <a href="named-character-references.html#named-character-references">named character references</a>
3587: table).</p>
3588:
3589: <div class="example">
3590:
3591: <p>If the markup contains <code title="">I'm &notit; I tell
3592: you</code>, the character reference is parsed as "not", as in,
3593: <code title="">I'm ¬it; I tell you</code>. But if the markup
3594: was <code title="">I'm &notin; I tell you</code>, the
3595: character reference would be parsed as "notin;", resulting in
3596: <code title="">I'm ∉ I tell you</code>.</p>
3597:
3598: </div>
3599:
3600: </dd>
3601:
1.266 mike 3602: </dl></div><div class="impl">
3603:
1.363 mike 3604: <!-- v2: One thing that this doesn't define is handling deeply
3605: nested documents. There are compatibility requirements around that:
3606: you can't throw away the elements altogether, consider Tux made only
3607: with opening <font> elements, one per character. Seems that the best
3608: thing to do is to close some formatting elements from the middle of
3609: the stack when you hit a limit, or something. -->
3610:
1.266 mike 3611: <h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4>
1.1 mike 3612:
3613: <p>The input to the tree construction stage is a sequence of tokens
3614: from the <a href="#tokenization">tokenization</a> stage. The tree construction
3615: stage is associated with a DOM <code>Document</code> object when a
3616: parser is created. The "output" of this stage consists of
3617: dynamically modifying or extending that document's DOM tree.</p>
3618:
3619: <p>This specification does not define when an interactive user agent
3620: has to render the <code>Document</code> so that it is available to
3621: the user, or when it has to begin accepting user input.</p>
3622:
3623: <p>As each token is emitted from the tokenizer, the user agent must
3624: process the token according to the rules given in the section
3625: corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
3626:
3627: <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
3628: character</dfn> into a node, if that node has a child immediately
3629: before where the character is to be inserted, and that child is a
3630: <code>Text</code> node, and that <code>Text</code> node was the last
3631: node that the parser inserted into the document, then the character
3632: must be appended to that <code>Text</code> node; otherwise, a new
3633: <code>Text</code> node whose data is just that character must be
3634: inserted in the appropriate place.</p>
3635:
3636: <div class="example">
3637:
3638: <p>Here are some sample inputs to the parser and the corresponding
3639: number of text nodes that they result in, assuming a user agent
3640: that executes scripts.</p>
3641:
3642: <table><thead><tr><th>Input </th><th>Number of text nodes
3643: </th></tr></thead><tbody><tr><td><pre>A<script>
3644: var script = document.getElementsByTagName('script')[0];
3645: document.body.removeChild(script);
3646: </script>B</pre>
3647: </td><td>Two adjacent text nodes in the document, containing "A" and "B".
3648: </td></tr><tr><td><pre>A<script>
3649: var text = document.createTextNode('B');
3650: document.body.appendChild(text);
3651: </script>C</pre>
3652: </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
3653: </td></tr><tr><td><pre>A<script>
3654: var text = document.getElementsByTagName('script')[0].firstChild;
3655: text.data = 'B';
3656: document.body.appendChild(text);
3657: </script>B</pre>
3658: </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
3659: </td></tr><tr><td><pre>A<table>B<tr>C</tr>C</table></pre>
3660: </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>.)
3661: </td></tr><tr><td><pre>A<table><tr> B</tr> B</table></pre>
3662: </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>.)
3663: </td></tr><tr><td><pre>A<table><tr> B</tr> </em>C</table></pre>
3664: </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.)
3665: </td></tr></tbody></table></div>
3666:
3667: <p id="mutation-during-parsing">DOM mutation events must not fire
3668: for changes caused by the UA parsing the document. (Conceptually,
3669: the parser is not mutating the DOM, it is constructing it.) This
1.159 mike 3670: 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 3671:
3672: <p class="note">Not all of the tag names mentioned below are
3673: conformant tag names in this specification; many are included to
3674: handle legacy content. They still form part of the algorithm that
3675: implementations are required to implement to claim conformance.</p>
3676:
3677: <p class="note">The algorithm described below places no limit on the
3678: depth of the DOM tree generated, or on the length of tag names,
3679: attribute names, attribute values, text nodes, etc. While
3680: implementors are encouraged to avoid arbitrary limits, it is
3681: recognized that <a href="infrastructure.html#hardwareLimitations">practical
1.445 mike 3682: concerns</a> will likely force user agents to impose nesting depth
3683: constraints.</p>
1.1 mike 3684:
3685:
3686: <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5>
3687:
3688: <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
3689: element for the token">create an element for a token</dfn> in a
3690: particular namespace, the UA must create a node implementing the
3691: interface appropriate for the element type corresponding to the tag
3692: name of the token in the given namespace (as given in the
3693: specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
3694: element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
3695: defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
3696: the tag name being the name of that element, with the node being in
3697: the given namespace, and with the attributes on the node being those
3698: given in the given token.</p>
3699:
3700: <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
1.426 mike 3701: namespace</a> that is not defined in this specification (or
3702: <a href="infrastructure.html#other-applicable-specifications">other applicable specifications</a>) is
1.44 mike 3703: <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1 mike 3704: interface is not defined by that namespace's specification must use
3705: the interface <code>Element</code>.</p>
3706:
3707: <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
3708: created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
3709: invoked once the attributes are set. (This initializes the element's
3710: <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
3711: attributes.)</p>
3712:
3713: <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
3714: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
3715: for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
3716: append this node to the <a href="#current-node">current node</a>, and push it onto
3717: the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
3718: <a href="#current-node">current node</a>.</p>
3719:
3720: <p>The steps below may also require that the UA insert an HTML
3721: element in a particular place, in which case the UA must follow the
3722: same steps except that it must insert or append the new node in the
3723: location specified instead of appending it to the <a href="#current-node">current
3724: node</a>. (This happens in particular during the parsing of
3725: tables with invalid content.)</p>
3726:
3727: <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
3728: algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
3729: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
3730: 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
3731: <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
3732: created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
3733: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
3734: inserting it wherever it is to be inserted.</p>
3735:
3736: <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
3737: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
3738: for the token</a> in the given namespace, and then append this
3739: node to the <a href="#current-node">current node</a>, and push it onto the
3740: <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
3741: <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>
3742: whose value is not exactly the same as the element's namespace, that
3743: is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
3744: element has an <code title="">xmlns:xlink</code> attribute in the
3745: <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
3746: Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
3747:
3748: <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
3749: attributes</dfn> for a token, then, if the token has an attribute
3750: named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
3751:
3752: <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
3753: attributes</dfn> for a token, then, for each attribute on the token
3754: whose attribute name is one of the ones in the first column of the
3755: following table, change the attribute's name to the name given in
3756: the corresponding cell in the second column. (This fixes the case of
3757: SVG attributes that are not all lowercase.)</p>
3758:
3759: <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
3760: </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
3761: </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
3762: </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
3763: </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
3764: </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
3765: </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
3766: </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
3767: </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
3768: </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
3769: </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
3770: </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
3771: </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
3772: </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
3773: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
3774: </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
3775: </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
3776: </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
3777: </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
3778: </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
3779: </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
3780: </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
3781: </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
3782: </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
3783: </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
3784: </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
3785: </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
3786: </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
3787: </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
3788: </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
3789: </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
3790: </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
3791: </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
3792: </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
3793: </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
3794: </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
3795: </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
3796: </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
3797: </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
3798: </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
3799: </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
3800: </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
3801: </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
3802: </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
3803: </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
3804: </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
3805: </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
3806: </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
3807: </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
3808: </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
3809: </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
3810: </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
3811: </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
3812: </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
3813: </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
3814: </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
3815: </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
3816: </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
3817: </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
3818: </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
3819: </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
3820: </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
3821: </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
3822: </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
3823: foreign attributes</dfn> for a token, then, if any of the attributes
3824: on the token match the strings given in the first column of the
3825: following table, let the attribute be a namespaced attribute, with
3826: the prefix being the string given in the corresponding cell in the
3827: second column, the local name being the string given in the
3828: corresponding cell in the third column, and the namespace being the
3829: namespace given in the corresponding cell in the fourth
3830: column. (This fixes the use of namespaced attributes, in particular
3831: <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
3832: the <span>XML namespace</span></a>.)</p>
3833:
3834: <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
3835: </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>
3836: </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>
3837: </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>
3838: </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>
3839: </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>
3840: </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>
3841: </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>
3842: </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 -->
3843: </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>
3844: </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>
3845: </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>
3846: </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 3847: </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 3848: <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
3849: following steps. These algorithms are always invoked in response to
3850: a start tag token.</p>
3851:
3852: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
3853:
1.91 mike 3854: <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
3855: text element parsing algorithm</a>, switch the tokenizer's
3856: <a href="#content-model-flag">content model flag</a> to the RAWTEXT state; otherwise the
1.1 mike 3857: algorithm invoked was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing
3858: algorithm</a>, switch the tokenizer's <a href="#content-model-flag">content model
3859: flag</a> to the RCDATA state.</p></li>
3860:
3861: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
3862: <a href="#insertion-mode">insertion mode</a>.</p>
3863:
1.91 mike 3864: </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
3865: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 3866:
3867: </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>
3868:
3869: <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
3870: tags</dfn>, then, while the <a href="#current-node">current node</a> is a
1.422 mike 3871: <code><a href="semantics.html#the-dd-element">dd</a></code> element, a <code><a href="semantics.html#the-dt-element">dt</a></code> element, an
1.1 mike 3872: <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
3873: <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
3874: <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
3875: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
3876: elements</a>.</p>
3877:
3878: <p>If a step requires the UA to generate implied end tags but lists
3879: an element to exclude from the process, then the UA must perform the
3880: above steps as if that element was not in the above list.</p>
3881:
3882:
3883: <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5>
3884:
3885: <p>Foster parenting happens when content is misnested in tables.</p>
3886:
3887: <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
3888: parent">foster parented</dfn>, the node <var title="">node</var>
3889: must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
3890:
3891: <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
3892: 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
3893: elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
3894: such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
3895: the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
3896: case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
3897: element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
1.159 mike 3898: <code><a href="semantics.html#the-html-element-0">html</a></code> element). Otherwise, if there is a
1.1 mike 3899: <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
3900: elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
3901: <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
3902: node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
3903: the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
3904: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
3905:
3906: <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
3907: 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
3908: elements</a>, then <var title="">node</var> must be inserted
3909: immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
3910: the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
3911: element</a></i>; otherwise, <var title="">node</var> must be
3912: <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
3913:
3914:
3915:
3916: <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>
3917:
3918: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
3919: mode: initial">initial</a>", tokens must be handled as follows:</p>
3920:
3921: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
3922: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3923: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3924: <dd>
3925: <p>Ignore the token.</p>
3926: </dd>
3927:
3928: <dt>A comment token</dt>
3929: <dd>
3930: <p>Append a <code>Comment</code> node to the <code>Document</code>
3931: object with the <code title="">data</code> attribute set to the
3932: data given in the comment token.</p>
3933: </dd>
3934:
3935: <dt>A DOCTYPE token</dt>
3936: <dd>
3937:
3938: <p>If the DOCTYPE token's name is not a
3939: <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
3940: missing, or the token's system identifier is neither missing nor a
3941: <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
1.465 mike 3942: "<code><a href="infrastructure.html#about:legacy-compat">about:legacy-compat</a></code>", and none of the sets of
1.1 mike 3943: conditions in the following list are matched, then there is a
3944: <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
3945: following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
3946: permitted DOCTYPE</dfn>.</p>
3947:
3948: <ul><!-- only things that trigger no-quirks mode and were valid in
3949: 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 3950: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3951: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD HTML 4.0//EN</code>", and the
3952: token's system identifier is either missing or the
3953: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
3954:
3955: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3956: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3957: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD HTML 4.01//EN</code>", and the
3958: token's system identifier is either missing or the
3959: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
3960:
3961: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3962: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3963: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD XHTML 1.0 Strict//EN</code>",
3964: and the token's system identifier is the
3965: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
3966:
3967: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3968: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3969: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD XHTML 1.1//EN</code>", and the
3970: token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
3971: string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
3972:
3973: </ul><p>Conformance checkers may, based on the values (including
3974: presence or lack thereof) of the DOCTYPE token's name, public
3975: identifier, or system identifier, switch to a conformance checking
3976: mode for another language (e.g. based on the DOCTYPE token a
3977: conformance checker could recognize that the document is an
1.183 mike 3978: HTML4-era document, and defer to an HTML4 conformance
1.1 mike 3979: checker.)</p>
3980:
3981: <p>Append a <code>DocumentType</code> node to the
3982: <code>Document</code> node, with the <code title="">name</code>
3983: attribute set to the name given in the DOCTYPE token, or the empty
3984: string if the name was missing; the <code title="">publicId</code>
3985: attribute set to the public identifier given in the DOCTYPE token,
3986: or the empty string if the public identifier was missing; the
3987: <code title="">systemId</code> attribute set to the system
3988: identifier given in the DOCTYPE token, or the empty string if the
3989: system identifier was missing; and the other attributes specific
3990: to <code>DocumentType</code> objects set to null and empty lists
3991: as appropriate. Associate the <code>DocumentType</code> node with
3992: the <code>Document</code> object so that it is returned as the
3993: value of the <code title="">doctype</code> attribute of the
3994: <code>Document</code> object.</p>
3995:
3996: <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
3997: one of the conditions in the following list, then set the
3998: <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
3999:
4000: <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
4001: <li> The name is set to anything other than "<code title="">HTML</code>". </li>
4002: <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
4003: <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
4004: <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
4005: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
4006: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
4007: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
4008: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
4009: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
4010: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
4011: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
4012: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
4013: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
4014: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
4015: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
4016: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
4017: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
4018: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
4019: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
4020: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
4021: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
4022: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
4023: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
4024: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
4025: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
4026: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
4027: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
4028: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
4029: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
4030: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
4031: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
4032: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
4033: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
4034: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
4035: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
4036: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
4037: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
4038: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
4039: <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
4040: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
4041: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
4042: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
4043: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
4044: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
4045: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
4046: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
4047: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
4048: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
4049: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
4050: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
4051: <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
4052: <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
4053: <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
4054: <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
4055: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
4056: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
4057: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
4058: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
4059: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
4060: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
4061: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
4062: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
4063: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
4064: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
4065: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
4066: <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
4067: <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
4068: <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
4069: <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
4070: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
4071: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
4072: <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
4073: <li> The public identifier is set to: "<code title="">HTML</code>" </li>
4074: <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
4075: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
4076: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
4077: </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
4078: in the following list, then set the <code>Document</code> to
4079: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
4080:
4081: <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
4082: <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
4083: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
4084: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
4085: </ul><p>The name, system identifier, and public identifier strings must
4086: be compared to the values given in the lists above in an
4087: <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
4088: whose value is the empty string is not considered missing for the
4089: purposes of the conditions above.</p>
4090:
4091: <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>
4092:
4093: </dd>
4094:
4095: <dt>Anything else</dt>
4096: <dd>
4097:
4098: <p><a href="#parse-error">Parse error</a>.</p>
4099:
4100: <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
4101:
4102: <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
4103: reprocess the current token.</p>
4104:
4105: </dd>
4106:
4107: </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>
4108:
4109: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
4110: mode: before html">before html</a>", tokens must be handled as follows:</p>
4111:
4112: <dl class="switch"><dt>A DOCTYPE token</dt>
4113: <dd>
4114: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4115: </dd>
4116:
4117: <dt>A comment token</dt>
4118: <dd>
4119: <p>Append a <code>Comment</code> node to the <code>Document</code>
4120: object with the <code title="">data</code> attribute set to the
4121: data given in the comment token.</p>
4122: </dd>
4123:
4124: <dt>A character token that is one of U+0009 CHARACTER
4125: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4126: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4127: <dd>
4128: <p>Ignore the token.</p>
4129: </dd>
4130:
4131: <dt>A start tag whose tag name is "html"</dt>
4132: <dd>
4133:
4134: <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
4135: namespace</a>. Append it to the <code>Document</code>
4136: object. Put this element in the <a href="#stack-of-open-elements">stack of open
4137: elements</a>.</p>
4138:
4139: <p id="parser-appcache">If the <code>Document</code> is being
4140: loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
4141: <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
4142: has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
4143: then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
4144: attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
4145: 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 4146: algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
4147: any <a href="infrastructure.html#url-fragment" title="url-fragment"><fragment></a> component
4148: removed; otherwise, if there is no such attribute or resolving it
4149: fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
4150: cache selection algorithm</a> with no manifest. The algorithm
4151: must be passed the <code>Document</code> object.</p>
1.1 mike 4152:
4153: <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>
4154:
4155: </dd>
4156:
1.334 mike 4157: <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
4158: <dd>
4159: <p>Act as described in the "anything else" entry below.</p>
4160: </dd>
4161:
4162: <dt>Any other end tag</dt>
4163: <dd>
4164: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4165: </dd>
4166:
1.1 mike 4167: <dt>Anything else</dt>
4168: <dd>
4169:
1.159 mike 4170: <p>Create an <code><a href="semantics.html#the-html-element-0">html</a></code> element. Append it to the
1.1 mike 4171: <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
4172: of open elements</a>.</p>
4173:
4174: <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
4175: context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
4176: algorithm</a> with no manifest, passing it the
4177: <code>Document</code> object.</p>
4178:
4179: <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
4180: reprocess the current token.</p>
4181:
4182: </dd>
4183:
4184: </dl><p>The root element can end up being removed from the
4185: <code>Document</code> object, e.g. by scripts; nothing in particular
4186: happens in such cases, content continues being appended to the nodes
4187: as described in the next section.</p>
4188:
4189:
4190: <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>
4191:
4192: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
4193: mode: before head">before head</a>", tokens must be handled as follows:</p>
4194:
4195: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4196: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4197: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4198: <dd>
4199: <p>Ignore the token.</p> <!-- :-( -->
4200: </dd>
4201:
4202: <dt>A comment token</dt>
4203: <dd>
4204: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4205: node</a> with the <code title="">data</code> attribute set to
4206: the data given in the comment token.</p>
4207: </dd>
4208:
4209: <dt>A DOCTYPE token</dt>
4210: <dd>
4211: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4212: </dd>
4213:
4214: <dt>A start tag whose tag name is "html"</dt>
4215: <dd>
4216: <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
4217: mode</a>.</p>
4218: </dd>
4219:
4220: <dt>A start tag whose tag name is "head"</dt>
4221: <dd>
4222:
4223: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4224:
4225: <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
1.159 mike 4226: to the newly created <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 4227:
4228: <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>
4229:
4230: </dd>
4231:
4232: <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
4233: <dd>
4234:
4235: <p>Act as if a start tag token with the tag name "head" and no
4236: attributes had been seen, then reprocess the current token.</p>
4237:
4238: </dd>
4239:
4240: <dt>Any other end tag</dt>
4241: <dd>
4242:
4243: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4244:
4245: </dd>
4246:
4247: <dt>Anything else</dt>
4248: <dd>
4249:
4250: <p>Act as if a start tag token with the tag name "head" and no
4251: attributes had been seen, then reprocess the current
4252: token.</p>
4253:
4254: </dd>
4255:
4256: </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>
4257:
4258: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
4259: mode: in head">in head</a>", tokens must be handled as follows:</p>
4260:
4261: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4262: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4263: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4264: <dd>
4265: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
4266: the <a href="#current-node">current node</a>.</p>
4267: </dd>
4268:
4269: <dt>A comment token</dt>
4270: <dd>
4271: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4272: node</a> with the <code title="">data</code> attribute set to
4273: the data given in the comment token.</p>
4274: </dd>
4275:
4276: <dt>A DOCTYPE token</dt>
4277: <dd>
4278: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4279: </dd>
4280:
4281: <dt>A start tag whose tag name is "html"</dt>
4282: <dd>
4283: <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
4284: mode</a>.</p>
4285: </dd>
4286:
4287: <dt>A start tag whose tag name is one of: "base", "command",
4288: "link"</dt>
4289: <dd>
4290:
4291: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4292: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4293: elements</a>.</p>
4294:
4295: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4296: token's <i>self-closing flag</i></a>, if it is set.</p>
4297:
4298: </dd>
4299:
4300: <dt>A start tag whose tag name is "meta"</dt>
4301: <dd>
4302:
4303: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4304: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4305: elements</a>.</p>
4306:
4307: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4308: token's <i>self-closing flag</i></a>, if it is set.</p>
4309:
4310: <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
4311: value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
4312: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
4313: encoding</a> to the encoding given by the value of the
4314: <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
4315:
4316: <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
4317: applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
4318: Content-Type</a> to its value returns a supported encoding
4319: <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
4320: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
4321: encoding</a> to the encoding <var title="">encoding</var>.</p>
4322:
4323: </dd>
4324:
4325: <dt>A start tag whose tag name is "title"</dt>
4326: <dd>
4327: <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
4328: </dd>
4329:
4330: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
4331: <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
4332: <dd>
1.91 mike 4333: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 4334: </dd>
4335:
4336: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
4337: <dd>
4338:
4339: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4340:
4341: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
4342: noscript</a>".</p>
4343:
4344: </dd>
4345:
4346: <dt id="scriptTag">A start tag whose tag name is "script"</dt>
4347: <dd>
4348:
4349: <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
4350: <a href="#html-namespace-0">HTML namespace</a>.</p></li>
4351:
4352: <li>
4353:
4354: <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
4355:
4356: <p class="note">This ensures that, if the script is external,
1.159 mike 4357: any <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>
1.1 mike 4358: calls in the script will execute in-line, instead of blowing the
4359: document away, as would happen in most other cases. It also
4360: prevents the script from executing until the end tag is
4361: seen.</p>
4362:
4363: </li>
4364:
4365: <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
4366: fragment parsing algorithm</a>, then mark the
1.484 mike 4367: <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-started">"already
4368: started"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
1.1 mike 4369:
4370: <li><p>Append the new element to the <a href="#current-node">current node</a>
4371: and push it onto the <a href="#stack-of-open-elements">stack of open
4372: elements</a>.</p></li>
4373:
4374: <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
1.91 mike 4375: the RAWTEXT state.</p></li>
1.1 mike 4376:
4377: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
4378: <a href="#insertion-mode">insertion mode</a>.</p>
4379:
1.91 mike 4380: </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
4381: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 4382:
4383: </ol></dd>
4384:
4385: <dt>An end tag whose tag name is "head"</dt>
4386: <dd>
4387:
4388: <p>Pop the <a href="#current-node">current node</a> (which will be the
1.159 mike 4389: <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 4390: elements</a>.</p>
4391:
4392: <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>
4393:
4394: </dd>
4395:
4396: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
4397: <dd>
4398: <p>Act as described in the "anything else" entry below.</p>
4399: </dd>
4400:
4401: <dt>A start tag whose tag name is "head"</dt>
4402: <dt>Any other end tag</dt>
4403: <dd>
4404: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4405: </dd>
4406:
4407: <dt>Anything else</dt>
4408: <dd>
4409:
4410: <!-- can't get here with an EOF and a fragment case -->
4411:
4412: <p>Act as if an end tag token with the tag name "head" had
4413: been seen, and reprocess the current token.</p>
4414:
4415: </dd>
4416:
4417: </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>
4418:
4419: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
4420: mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
4421:
4422: <dl class="switch"><dt>A DOCTYPE token</dt>
4423: <dd>
4424: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4425: </dd>
4426:
4427: <dt>A start tag whose tag name is "html"</dt>
4428: <dd>
4429: <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
4430: mode</a>.</p>
4431: </dd>
4432:
4433: <dt>An end tag whose tag name is "noscript"</dt>
4434: <dd>
4435:
4436: <p>Pop the <a href="#current-node">current node</a> (which will be a
4437: <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
4438: elements</a>; the new <a href="#current-node">current node</a> will be a
1.159 mike 4439: <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 4440:
4441: <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>
4442:
4443: </dd>
4444:
4445: <dt>A character token that is one of U+0009 CHARACTER
4446: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4447: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4448: <dt>A comment token</dt>
4449: <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
4450: <dd>
4451: <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
4452: mode</a>.</p>
4453: </dd>
4454:
4455: <dt>An end tag whose tag name is "br"</dt>
4456: <dd>
4457: <p>Act as described in the "anything else" entry below.</p>
4458: </dd>
4459:
4460: <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
4461: <dt>Any other end tag</dt>
4462: <dd>
4463: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4464: </dd>
4465:
4466: <dt>Anything else</dt>
4467: <dd>
4468:
4469: <!-- can't get here with an EOF and a fragment case -->
4470:
4471: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
4472: name "noscript" had been seen and reprocess the current
4473: token.</p>
4474:
4475: </dd>
4476:
4477: </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>
4478:
4479: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
4480: mode: after head">after head</a>", tokens must be handled as follows:</p>
4481:
4482: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4483: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4484: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4485: <dd>
4486: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
4487: the <a href="#current-node">current node</a>.</p>
4488: </dd>
4489:
4490: <dt>A comment token</dt>
4491: <dd>
4492: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4493: node</a> with the <code title="">data</code> attribute set to
4494: the data given in the comment token.</p>
4495: </dd>
4496:
4497: <dt>A DOCTYPE token</dt>
4498: <dd>
4499: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4500: </dd>
4501:
4502: <dt>A start tag whose tag name is "html"</dt>
4503: <dd>
4504: <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
4505: mode</a>.</p>
4506: </dd>
4507:
4508: <dt>A start tag whose tag name is "body"</dt>
4509: <dd>
4510:
4511: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4512:
4513: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4514:
4515: <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>
4516:
4517: </dd>
4518:
4519: <dt>A start tag whose tag name is "frameset"</dt>
4520: <dd>
4521:
4522: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4523:
4524: <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>
4525:
4526: </dd>
4527:
4528: <dt>A start tag token whose tag name is one of: "base", "link",
4529: "meta", "noframes", "script", "style", "title"</dt>
4530: <dd>
4531:
4532: <p><a href="#parse-error">Parse error</a>.</p>
4533:
4534: <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
4535: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
4536:
4537: <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
4538: mode</a>.</p>
4539:
4540: <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
4541: of open elements</a>.</p>
4542:
4543: <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
4544: pointer</a> cannot be null at this point.</p>
4545:
4546: </dd>
4547:
4548: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
4549: <dd>
4550: <p>Act as described in the "anything else" entry below.</p>
4551: </dd>
4552:
4553: <dt>A start tag whose tag name is "head"</dt>
4554: <dt>Any other end tag</dt>
4555: <dd>
4556: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4557: </dd>
4558:
4559: <dt>Anything else</dt>
4560: <dd>
4561: <p>Act as if a start tag token with the tag name "body" and no
4562: attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
4563: flag</a> back to "ok", and then reprocess the current
4564: token.</p>
4565: </dd>
4566:
4567: </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>
4568:
4569: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
4570: mode: in body">in body</a>", tokens must be handled as follows:</p>
4571:
4572: <dl class="switch"><dt>A character token</dt>
4573: <dd>
4574:
4575: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4576: any.</p>
4577:
4578: <p><a href="#insert-a-character" title="insert a character">Insert the token's
4579: character</a> into the <a href="#current-node">current node</a>.</p>
4580:
4581: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
4582: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
4583: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
4584: flag</a> to "not ok".</p>
4585:
4586: </dd>
4587:
4588: <dt>A comment token</dt>
4589: <dd>
4590: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4591: node</a> with the <code title="">data</code> attribute set to
4592: the data given in the comment token.</p>
4593: </dd>
4594:
4595: <dt>A DOCTYPE token</dt>
4596: <dd>
4597: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4598: </dd>
4599:
4600: <dt>A start tag whose tag name is "html"</dt>
4601: <dd>
4602: <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
4603: check to see if the attribute is already present on the top
4604: element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
4605: add the attribute and its corresponding value to that element.</p>
4606: </dd>
4607:
4608: <dt>A start tag token whose tag name is one of: "base", "command",
4609: "link", "meta", "noframes", "script", "style", "title"</dt>
4610: <dd>
4611: <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
4612: mode</a>.</p>
4613: </dd>
4614:
4615: <dt>A start tag whose tag name is "body"</dt>
4616: <dd>
4617:
4618: <p><a href="#parse-error">Parse error</a>.</p>
4619:
4620: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159 mike 4621: elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1 mike 4622: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
4623: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
4624:
4625: <p>Otherwise, for each attribute on the token, check to see if
1.159 mike 4626: the attribute is already present on the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 4627: element (the second element) on the <a href="#stack-of-open-elements">stack of open
4628: elements</a>. If it is not, add the attribute and its
4629: corresponding value to that element.</p>
4630:
4631: </dd>
4632:
4633: <dt>A start tag whose tag name is "frameset"</dt>
4634: <dd>
4635:
4636: <p><a href="#parse-error">Parse error</a>.</p>
4637:
4638: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159 mike 4639: elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1 mike 4640: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
4641: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
4642:
4643: <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
4644: the token.</p>
4645:
4646: <p>Otherwise, run the following steps:</p>
4647:
4648: <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
4649: elements</a> from its parent node, if it has one.</p></li>
4650:
4651: <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
4652: open elements</a>, from the <a href="#current-node">current node</a> up to,
1.159 mike 4653: but not including, the root <code><a href="semantics.html#the-html-element-0">html</a></code> element.</p>
1.1 mike 4654:
4655: </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
4656: token.</p></li>
4657:
4658: <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>
4659:
4660: </li></ol></dd>
4661:
4662: <dt>An end-of-file token</dt>
4663: <dd>
4664:
4665: <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
1.422 mike 4666: that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a <code><a href="semantics.html#the-dt-element">dt</a></code>
4667: element, an <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 4668: <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
4669: <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
4670: <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 4671: <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 4672: this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
1.422 mike 4673: fragment cases) -->
1.1 mike 4674:
4675: <p><a href="#stop-parsing">Stop parsing</a>.</p>
4676:
4677: </dd>
4678:
4679: <dt>An end tag whose tag name is "body"</dt>
4680: <dd>
4681:
4682: <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
4683: in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
4684: token.</p>
4685:
4686: <!-- if we get here, the insertion mode here is forcibly "in
4687: body". -->
4688:
4689: <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
1.422 mike 4690: elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
1.1 mike 4691: <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
4692: <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
4693: <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
4694: <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
4695: <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
4696: <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 4697: <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
4698: <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 4699: error</a>.</p> <!-- (some of those are fragment cases, e.g. for
4700: <tbody> you'd have hit the first paragraph since the <body>
1.422 mike 4701: wouldn't be in scope, unless it was a fragment case) -->
1.1 mike 4702:
4703: <!-- If we ever change the frameset-ok flag to an insertion mode,
4704: then we'd have to somehow keep track of its state when we switch
4705: to after-body. -->
4706:
4707: <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>
4708:
4709: </dd>
4710:
4711: <dt>An end tag whose tag name is "html"</dt>
4712: <dd>
4713:
4714: <p>Act as if an end tag with tag name "body" had been seen,
4715: then, if that token wasn't ignored, reprocess the current
4716: token.</p>
4717:
4718: <p class="note">The fake end tag token here can only be
4719: ignored in the <a href="#fragment-case">fragment case</a>.</p>
4720:
4721: </dd>
4722:
4723: <!-- start tags for non-phrasing flow content elements -->
4724:
4725: <!-- the normal ones -->
4726: <dt>A start tag whose tag name is one of: "address", "article",
1.86 mike 4727: "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305 mike 4728: "details", "dir", "div", "dl", "fieldset", "figure", "footer",
4729: "header", "hgroup", "menu", "nav", "ol", "p", "section", "ul"</dt>
1.1 mike 4730: <dd>
4731:
4732: <!-- As of May 2008 this doesn't match any browser exactly, but is
4733: as close to what IE does as I can get without doing the non-tree
4734: DOM nonsense, and thus should actually afford better compatibility
4735: when implemented by the other browsers. -->
4736:
4737: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4738: an element in scope">has a <code>p</code> element in
4739: scope</a>, then act as if an end tag with the tag name
4740: "p" had been seen.</p>
4741:
4742: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4743:
4744: </dd>
4745:
4746: <!-- as normal, but close h1-h6 if it's the current node -->
4747: <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
4748: "h5", "h6"</dt>
4749: <dd>
4750:
4751: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4752: an element in scope">has a <code>p</code> element in
4753: scope</a>, then act as if an end tag with the tag name
4754: "p" had been seen.</p>
4755:
4756: <p>If the <a href="#current-node">current node</a> is an element whose tag name
4757: is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
4758: <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
4759: the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
4760: <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
4761:
4762: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4763:
4764: </dd>
4765:
4766: <!-- as normal, but drops leading newline -->
4767: <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
4768: <dd>
4769:
4770: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4771: an element in scope">has a <code>p</code> element in
4772: scope</a>, then act as if an end tag with the tag name
4773: "p" had been seen.</p>
4774:
4775: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4776:
4777: <p>If the next token is a U+000A LINE FEED (LF) character
4778: token, then ignore that token and move on to the next
4779: one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
4780: ignored as an authoring convenience.)</p>
4781:
4782: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4783:
4784: </dd>
4785:
4786: <!-- as normal, but interacts with the form element pointer -->
4787: <dt>A start tag whose tag name is "form"</dt>
4788: <dd>
4789:
4790: <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
4791: pointer</a> is not null, then this is a <a href="#parse-error">parse
4792: error</a>; ignore the token.</p>
4793:
4794: <p>Otherwise:</p>
4795:
4796: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4797: an element in scope">has a <code>p</code> element in
4798: scope</a>, then act as if an end tag with the tag name
4799: "p" had been seen.</p>
4800:
4801: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
4802: <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
4803: point to the element created.</p>
4804:
4805: </dd>
4806:
4807: <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
4808: <dt>A start tag whose tag name is "li"</dt>
4809: <dd>
4810:
4811: <p>Run the following algorithm:</p>
4812:
4813: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
4814:
4815: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
4816: node</a> (the bottommost node of the stack).</p></li>
4817:
4818: <li><p>If <var title="">node</var> is an <code><a href="semantics.html#the-li-element">li</a></code> element,
4819: then act as if an end tag with the tag name "li" had
4820: been seen, then jump to the last step.</p></li>
4821:
4822: <li><p><i>Loop</i>: If <var title="">node</var> is not in the
4823: <a href="#formatting">formatting</a> category, and is not in the
4824: <a href="#phrasing">phrasing</a> category, and is not an
1.306 mike 4825: <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 4826: element, then jump to the last step.</p></li> <!-- an element
4827: <foo> is in this list if the following markup:
4828:
4829: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
4830:
4831: ...results in the second <li> not being (in any way) a descendant
4832: of the first <li>, or if <foo> is a formatting element that gets
4833: reopened later. -->
4834:
4835: <li><p>Otherwise, set <var title="">node</var> to the previous
4836: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
4837: the step labeled <i>loop</i>.</p></li>
4838:
4839: <li>
4840:
4841: <p>This is the last step.</p>
4842:
4843: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4844: an element in scope">has a <code>p</code> element in
4845: scope</a>, then act as if an end tag with the tag name
4846: "p" had been seen.</p>
4847:
4848: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
4849: token.</p>
4850:
4851: </li>
4852:
4853: </ol></dd>
4854:
4855: <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases -->
1.422 mike 4856: <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
1.1 mike 4857: <dd>
4858:
4859: <p>Run the following algorithm:</p>
4860:
4861: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
4862:
4863: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
4864: node</a> (the bottommost node of the stack).</p></li>
4865:
4866: <li><p><i>Loop</i>: If <var title="">node</var> is a
1.422 mike 4867: <code><a href="semantics.html#the-dd-element">dd</a></code> or <code><a href="semantics.html#the-dt-element">dt</a></code> element, then act as if an end
4868: tag with the same tag name as <var title="">node</var> had been
4869: seen, then jump to the last step.</p></li>
1.1 mike 4870:
4871: <li><p>If <var title="">node</var> is not in the
4872: <a href="#formatting">formatting</a> category, and is not in the
4873: <a href="#phrasing">phrasing</a> category, and is not an
1.306 mike 4874: <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 4875: element, then jump to the last step.</p></li> <!-- an element
4876: <foo> is in this list if the following markup:
4877:
4878: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
4879:
4880: ...results in the second <dt> not being (in any way) a descendant
4881: of the first <dt>, or if <foo> is a formatting element that gets
4882: reopened later. -->
4883:
4884: <li><p>Otherwise, set <var title="">node</var> to the previous
4885: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
4886: the step labeled <i>loop</i>.</p></li>
4887:
4888: <li>
4889:
4890: <p>This is the last step.</p>
4891:
4892: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4893: an element in scope">has a <code>p</code> element in
4894: scope</a>, then act as if an end tag with the tag name
4895: "p" had been seen.</p>
4896:
4897: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
4898: token.</p>
4899:
4900: </li>
4901:
4902: </ol></dd>
4903:
4904: <!-- same as normal, but effectively ends parsing -->
4905: <dt>A start tag whose tag name is "plaintext"</dt>
4906: <dd>
4907:
4908: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4909: an element in scope">has a <code>p</code> element in
4910: scope</a>, then act as if an end tag with the tag name
4911: "p" had been seen.</p>
4912:
4913: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4914:
4915: <p>Switch the <a href="#content-model-flag">content model flag</a> to the PLAINTEXT
4916: state.</p>
4917:
4918: <p class="note">Once a start tag with the tag name "plaintext"
4919: has been seen, that will be the last token ever seen other
4920: than character tokens (and the end-of-file token), because
4921: there is no way to switch the <a href="#content-model-flag">content model flag</a>
4922: out of the PLAINTEXT state.</p>
4923:
4924: </dd>
4925:
4926: <!-- end tags for non-phrasing flow content elements -->
4927:
4928: <!-- the normal ones -->
4929: <dt>An end tag whose tag name is one of: "address", "article",
1.86 mike 4930: "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305 mike 4931: "details", "dir", "div", "dl", "fieldset", "figure", "footer",
4932: "header", "hgroup", "listing", "menu", "nav", "ol", "pre",
4933: "section", "ul"</dt>
1.1 mike 4934: <dd>
4935:
4936: <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>
4937: with the same tag name as that of the token, then this is a
4938: <a href="#parse-error">parse error</a>; ignore the token.</p>
4939:
4940: <p>Otherwise, run these steps:</p>
4941:
4942: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4943:
4944: <li><p>If the <a href="#current-node">current node</a> is not an element with
4945: the same tag name as that of the token, then this is a
4946: <a href="#parse-error">parse error</a>.</p></li>
4947:
4948: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4949: until an element with the same tag name as the token has been
4950: popped from the stack.</p></li>
4951:
4952: </ol></dd>
4953:
4954: <!-- removes the form element pointer instead of the matching node -->
4955: <dt>An end tag whose tag name is "form"</dt>
4956: <dd>
4957:
4958: <p>Let <var title="">node</var> be the element that the
4959: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
4960: to.</p>
4961:
4962: <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
4963: to null.</p>
4964:
4965: <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
4966: elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
4967: scope">have <var title="">node</var> in scope</a>, then this is
4968: a <a href="#parse-error">parse error</a>; ignore the token.</p>
4969:
4970: <p>Otherwise, run these steps:</p>
4971:
4972: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4973:
4974: <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
4975: error</a>.</p></li>
4976:
4977: <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
4978: open elements</a>.</p></li>
4979:
4980: </ol></dd>
4981:
4982: <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
4983: <dt>An end tag whose tag name is "p"</dt>
4984: <dd>
4985:
4986: <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>
4987: with the same tag name as that of the token, then this is a
4988: <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
4989: "p" had been seen, then reprocess the current token.</p>
4990:
4991: <p>Otherwise, run these steps:</p>
4992:
4993: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
4994: for elements with the same tag name as the token.</p></li>
4995:
4996: <li><p>If the <a href="#current-node">current node</a> is not an element with
4997: the same tag name as that of the token, then this is a
4998: <a href="#parse-error">parse error</a>.</p></li>
4999:
5000: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5001: until an element with the same tag name as the token has been
5002: popped from the stack.</p></li>
5003:
5004: </ol></dd>
5005:
1.234 mike 5006: <!-- as normal, but needs care as the elements have optional tags, and are further scoped by <ol>/<ul> -->
5007: <dt>An end tag whose tag name is "li"</dt>
5008: <dd>
5009:
5010: <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
5011: item scope</a> with the same tag name as that of the token,
5012: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
5013:
5014: <p>Otherwise, run these steps:</p>
5015:
5016: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
5017: for elements with the same tag name as the token.</p></li>
5018:
5019: <li><p>If the <a href="#current-node">current node</a> is not an element with
5020: the same tag name as that of the token, then this is a
5021: <a href="#parse-error">parse error</a>.</p></li>
5022:
5023: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5024: until an element with the same tag name as the token has been
5025: popped from the stack.</p></li>
5026:
5027: </ol></dd>
5028:
1.1 mike 5029: <!-- as normal, but needs care as the elements have optional tags -->
1.422 mike 5030: <dt>An end tag whose tag name is one of: "dd", "dt"</dt>
1.1 mike 5031: <dd>
5032:
5033: <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>
5034: with the same tag name as that of the token, then this is a
5035: <a href="#parse-error">parse error</a>; ignore the token.</p>
5036:
5037: <p>Otherwise, run these steps:</p>
5038:
5039: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
5040: for elements with the same tag name as the token.</p></li>
5041:
5042: <li><p>If the <a href="#current-node">current node</a> is not an element with
5043: the same tag name as that of the token, then this is a
5044: <a href="#parse-error">parse error</a>.</p></li>
5045:
5046: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5047: until an element with the same tag name as the token has been
5048: popped from the stack.</p></li>
5049:
5050: </ol></dd>
5051:
5052: <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
5053: <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
5054: <dd>
5055:
5056: <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>
5057: whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
5058: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
5059:
5060: <p>Otherwise, run these steps:</p>
5061:
5062: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5063:
5064: <li><p>If the <a href="#current-node">current node</a> is not an element with
5065: the same tag name as that of the token, then this is a
5066: <a href="#parse-error">parse error</a>.</p></li>
5067:
5068: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5069: until an element whose tag name is one of "h1", "h2", "h3", "h4",
5070: "h5", or "h6" has been popped from the stack.</p></li>
5071:
5072: </ol></dd>
5073:
5074: <dt>An end tag whose tag name is "sarcasm"</dt>
5075: <dd>
5076: <p>Take a deep breath, then act as described in the "any other end
5077: tag" entry below.</p>
5078: </dd>
5079:
5080: <!-- ADOPTION AGENCY ELEMENTS
5081: Mozilla-only: bdo blink del ins sub sup q
5082: Safari-only: code dfn kbd nobr samp var wbr
5083: Both: a b big em font i s small strike strong tt u -->
5084:
5085: <dt>A start tag whose tag name is "a"</dt>
5086: <dd>
5087:
5088: <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
5089: contains an element whose tag name is "a" between the end of
5090: the list and the last marker on the list (or the start of the
5091: list if there is no marker on the list), then this is a
5092: <a href="#parse-error">parse error</a>; act as if an end tag with the tag
5093: name "a" had been seen, then remove that element from the
5094: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
5095: <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
5096: already remove it (it might not have if the element is not
5097: <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
5098: scope</a>).</p>
5099:
5100: <p class="example">In the non-conforming stream
5101: <code><a href="a">a<table><a href="b">b</table>x</code>,
5102: the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
5103: the second one, and the "x" character would be inside a link
5104: to "b", not to "a". This is despite the fact that the outer
5105: <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
5106: regular <code></a></code> end tag at the start of the table
5107: wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
5108:
5109: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5110: any.</p>
5111:
5112: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
5113: element to the <a href="#list-of-active-formatting-elements">list of active formatting
5114: elements</a>.</p>
5115:
5116: </dd>
5117:
5118: <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
5119: "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
5120: <dd>
5121:
5122: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5123: any.</p>
5124:
5125: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
5126: element to the <a href="#list-of-active-formatting-elements">list of active formatting
5127: elements</a>.</p>
5128:
5129: </dd>
5130:
5131: <dt>A start tag whose tag name is "nobr"</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>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5138: element in scope">has a <code>nobr</code> element in scope</a>,
5139: then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
5140: the tag name "nobr" had been seen, then once again
5141: <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
5142: any.</p>
5143:
5144: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
5145: element to the <a href="#list-of-active-formatting-elements">list of active formatting
5146: elements</a>.</p>
5147:
5148: </dd>
5149:
5150: <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
5151: "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
5152: "strike", "strong", "tt", "u"</dt>
5153: <dd>
5154:
5155: <p>Follow these steps:</p>
5156:
5157: <ol><li>
5158:
5159: <p>Let the <var title="">formatting element</var> be the
5160: last element in the <a href="#list-of-active-formatting-elements">list of active formatting
5161: elements</a> that:</p>
5162:
5163: <ul><li>is between the end of the list and the last scope
5164: marker in the list, if any, or the start of the list
5165: otherwise, and</li>
5166:
5167: <li>has the same tag name as the token.</li>
5168:
5169: </ul><p>If there is no such node, or, if that node is also in the
5170: <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
5171: <a href="#parse-error">parse error</a>; ignore the token, and abort these
5172: steps.</p>
5173:
5174: <p>Otherwise, if there is such a node, but that node is not
5175: in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
5176: <a href="#parse-error">parse error</a>; remove the element from the list,
5177: and abort these steps.</p>
5178:
5179: <p>Otherwise, there is a <var title="">formatting
5180: element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
5181: open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
5182: element in scope">in scope</a>. If the element is not the
5183: <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
5184: error</a>. In any case, proceed with the algorithm as
5185: written in the following steps.</p>
5186:
5187: </li>
5188:
5189: <li><p>Let the <var title="">furthest block</var> be the
5190: topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
5191: is lower in the stack than the <var title="">formatting
5192: element</var>, and is not an element in the
5193: <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
5194: categories. There might not be one.</p></li>
5195:
5196: <li><p>If there is no <var title="">furthest block</var>,
5197: then the UA must skip the subsequent steps and instead just
5198: pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
5199: elements</a>, from the <a href="#current-node">current node</a> up to and
5200: including the <var title="">formatting element</var>, and
5201: remove the <var title="">formatting element</var> from the
5202: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
5203:
5204: <li><p>Let the <var title="">common ancestor</var> be the element
5205: immediately above the <var title="">formatting element</var> in the
5206: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
5207:
5208: <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
5209: formatting elements</a> relative to the elements on either
5210: side of it in the list.</p></li>
5211:
5212: <li>
5213:
5214: <p>Let <var title="">node</var> and <var title="">last node</var> be the
5215: <var title="">furthest block</var>. Follow these steps:</p>
5216:
5217: <ol><li>Let <var title="">node</var> be the element immediately
5218: above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
1.436 mike 5219: elements</a>, or if <var title="">node</var> is no longer in
5220: the <a href="#stack-of-open-elements">stack of open elements</a> (e.g. because it got
5221: removed by the next step), the element that was immediately
5222: above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
5223: elements</a> before <var title="">node</var> was
5224: removed.</li>
1.1 mike 5225:
5226: <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
5227: active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
5228: elements</a> and then go back to step 1.</li>
5229:
5230: <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
5231: in the overall algorithm.</li>
5232:
5233: <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
5234: bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
5235: elements</a>.</li>
5236:
5237: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
5238: element <var title="">node</var> was created, replace the entry
5239: for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
5240: formatting elements</a> with an entry for the new element,
5241: replace the entry for <var title="">node</var> in the
5242: <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
5243: element, and let <var title="">node</var> be the new
5244: element.</li>
5245:
5246: <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
5247: parent node if any.</li>
5248:
5249: <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
5250:
5251: <li>Return to step 1 of this inner set of steps.</li>
5252:
5253: </ol></li>
5254:
5255: <li>
5256:
5257: <p>If the <var title="">common ancestor</var> node is a
5258: <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>,
5259: <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,
5260: <a href="#foster-parent">foster parent</a> whatever <var title="">last
5261: node</var> ended up being in the previous step, first removing
5262: it from its previous parent node if any.</p>
5263:
5264: <p>Otherwise, append whatever <var title="">last node</var>
5265: ended up being in the previous step to the <var title="">common
5266: ancestor</var> node, first removing it from its previous parent
5267: node if any.</p>
5268:
5269: </li>
5270:
5271: <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
5272: <var title="">formatting element</var> was created.</p></li>
5273:
5274: <li><p>Take all of the child nodes of the <var title="">furthest
5275: block</var> and append them to the element created in the last
5276: step.</p></li>
5277:
5278: <li><p>Append that new element to the <var title="">furthest
5279: block</var>.</p></li>
5280:
5281: <li><p>Remove the <var title="">formatting element</var> from the
5282: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
5283: new element into the <a href="#list-of-active-formatting-elements">list of active formatting
5284: elements</a> at the position of the aforementioned
5285: bookmark.</p></li>
5286:
5287: <li><p>Remove the <var title="">formatting element</var> from the
5288: <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
5289: into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
5290: the position of the <var title="">furthest block</var> in that
5291: stack.</p></li>
5292:
5293: <li><p>Jump back to step 1 in this series of steps.</p></li>
5294:
1.334 mike 5295: </ol><p class="note">Because of the way this algorithm causes elements
1.304 mike 5296: to change parents, it has been dubbed the "adoption agency
5297: algorithm" (in contrast with other possible algorithms for dealing
5298: with misnested content, which included the "incest algorithm", the
1.1 mike 5299: "secret affair algorithm", and the "Heisenberg algorithm").</p>
5300:
5301: </dd>
5302:
5303: <dt>A start tag whose tag name is "button"</dt>
5304: <dd>
5305:
5306: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5307: an element in scope">has a <code>button</code> element in
5308: scope</a>, then this is a <a href="#parse-error">parse error</a>;
5309: act as if an end tag with the tag name "button" had been seen,
5310: then reprocess the token.</p>
5311:
5312: <p>Otherwise:</p>
5313:
5314: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5315: any.</p>
5316:
5317: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5318:
5319: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5320: formatting elements</a>.</p>
5321:
5322: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5323:
5324: </dd>
5325:
5326: <dt>A start tag token whose tag name is one of: "applet",
5327: "marquee", "object"</dt>
5328: <dd>
5329:
5330: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5331: any.</p>
5332:
5333: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5334:
5335: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5336: formatting elements</a>.</p>
5337:
5338: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5339:
5340: </dd>
5341:
5342: <dt>An end tag token whose tag name is one of: "applet", "button",
5343: "marquee", "object"</dt>
5344: <dd>
5345:
5346: <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>
5347: with the same tag name as that of the token, then this is a
5348: <a href="#parse-error">parse error</a>; ignore the token.</p>
5349:
5350: <p>Otherwise, run these steps:</p>
5351:
5352: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5353:
5354: <li><p>If the <a href="#current-node">current node</a> is not an element with
5355: the same tag name as that of the token, then this is a
5356: <a href="#parse-error">parse error</a>.</p></li>
5357:
5358: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5359: until an element with the same tag name as the token has been
5360: popped from the stack.</p></li>
5361:
5362: <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
5363: last marker</a>.</li>
5364:
5365: </ol></dd>
5366:
5367: <dt>A start tag whose tag name is "table"</dt>
5368: <dd>
5369:
5370: <p>If the <code>Document</code> is <em>not</em> set to
5371: <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
5372: elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
5373: <code>p</code> element in scope</a>, then act as if an end tag
5374: with the tag name "p" had been seen.</p> <!-- i hate myself (this
5375: quirk was basically caused by acid2; if i'd realised we could
5376: change the specs when i wrote acid2, we could have avoided having
5377: any parsing-mode quirks) -Hixie -->
5378:
5379: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5380:
5381: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5382:
5383: <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>
5384:
5385: </dd>
5386:
5387: <dt>A start tag whose tag name is one of: "area", "basefont",
5388: "bgsound", "br", "embed", "img", "input", "keygen", "spacer",
5389: "wbr"</dt>
5390: <dd>
5391:
5392: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5393: any.</p>
5394:
5395: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5396: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5397: elements</a>.</p>
5398:
5399: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5400: token's <i>self-closing flag</i></a>, if it is set.</p>
5401:
5402: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
5403: shouldn't really do it for <area>, <basefont>, <bgsound>, and
5404: <spacer> -->
5405:
5406: </dd>
5407:
5408: <dt>A start tag whose tag name is one of: "param", "source"</dt>
5409: <dd>
5410:
5411: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5412: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5413: elements</a>.</p>
5414:
5415: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5416: token's <i>self-closing flag</i></a>, if it is set.</p>
5417:
5418: </dd>
5419:
5420: <dt>A start tag whose tag name is "hr"</dt>
5421: <dd>
5422:
5423: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5424: an element in scope">has a <code>p</code> element in
5425: scope</a>, then act as if an end tag with the tag name
5426: "p" had been seen.</p>
5427:
5428: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5429: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5430: elements</a>.</p>
5431:
5432: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5433: token's <i>self-closing flag</i></a>, if it is set.</p>
5434:
5435: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5436:
5437: </dd>
5438:
5439: <dt>A start tag whose tag name is "image"</dt>
5440: <dd>
5441: <p><a href="#parse-error">Parse error</a>. Change the token's tag name
5442: to "img" and reprocess it. (Don't ask.)</p> <!-- As of
5443: 2005-12, studies showed that around 0.2% of pages used the
5444: <image> element. -->
5445: </dd>
5446:
5447: <dt id="isindex">A start tag whose tag name is "isindex"</dt>
5448: <dd>
5449:
5450: <p><a href="#parse-error">Parse error</a>.</p>
5451:
5452: <p>If the <a href="#form-element-pointer"><code title="">form</code> element
5453: pointer</a> is not null, then ignore the token.</p>
5454:
5455: <p>Otherwise:</p>
5456:
5457: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5458: token's <i>self-closing flag</i></a>, if it is set.</p> <!--
5459: purely to reduce the number of errors (we don't care if they
5460: included the /, they're not supposed to be including the tag at
5461: all! -->
5462:
5463: <p>Act as if a start tag token with the tag name "form" had been seen.</p>
5464:
5465: <p>If the token has an attribute called "action", set the
5466: <code title="attr-form-action">action</code> attribute on the
5467: resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
5468: "action" attribute of the token.</p>
5469:
5470: <p>Act as if a start tag token with the tag name "hr" had been
5471: seen.</p>
5472:
5473: <p>Act as if a start tag token with the tag name "label" had been
5474: seen.</p>
5475:
5476: <p>Act as if a stream of character tokens had been seen (see below
5477: for what they should say).</p>
5478:
5479: <p>Act as if a start tag token with the tag name "input" had been
5480: seen, with all the attributes from the "isindex" token except
5481: "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
5482: <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
5483:
5484: <p>Act as if a stream of character tokens had been seen (see
5485: below for what they should say).</p>
5486:
5487: <p>Act as if an end tag token with the tag name "label" had been
5488: seen.</p>
5489:
5490: <p>Act as if a start tag token with the tag name "hr" had been
5491: seen.</p>
5492:
5493: <p>Act as if an end tag token with the tag name "form" had been
5494: seen.</p>
5495:
5496: <p>If the token has an attribute with the name "prompt", then the
5497: first stream of characters must be the same string as given in
5498: that attribute, and the second stream of characters must be
5499: empty. Otherwise, the two streams of character tokens together
5500: should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
5501: equivalent of "This is a searchable index. Insert your search
5502: keywords here: (input field)" in the user's preferred
5503: language.</p>
5504:
5505: </dd>
5506:
5507: <dt>A start tag whose tag name is "textarea"</dt>
5508: <dd>
5509:
5510: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
5511: token.</p></li>
5512:
5513: <li><p>If the next token is a U+000A LINE FEED (LF) character
5514: token, then ignore that token and move on to the next
5515: one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
5516: ignored as an authoring convenience.)</p></li>
5517:
5518: <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
5519: the RCDATA state.</p></li>
5520:
5521: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
5522: current <a href="#insertion-mode">insertion mode</a>.</p>
5523:
5524: </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
5525: ok".</p></li>
5526:
1.91 mike 5527: <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
5528: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 5529:
5530: </ol></dd>
5531:
5532: <dt>A start tag whose tag name is "xmp"</dt>
5533: <dd>
5534:
1.233 mike 5535: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5536: an element in scope">has a <code>p</code> element in
5537: scope</a>, then act as if an end tag with the tag name
5538: "p" had been seen.</p>
5539:
1.1 mike 5540: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5541: any.</p>
5542:
5543: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5544:
1.91 mike 5545: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5546:
5547: </dd>
5548:
5549: <dt>A start tag whose tag name is "iframe"</dt>
5550: <dd>
5551:
5552: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5553:
1.91 mike 5554: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5555:
5556: </dd>
5557:
5558: <dt>A start tag whose tag name is "noembed"</dt>
5559: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
5560: <dd>
5561:
1.91 mike 5562: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5563:
5564: </dd>
5565:
5566: <dt>A start tag whose tag name is "select"</dt>
5567: <dd>
5568:
5569: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5570: any.</p>
5571:
5572: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5573:
5574: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5575:
5576: <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>",
5577: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
5578: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
5579: row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
5580: cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
5581: "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
5582: table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
5583: to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
5584:
5585: </dd>
5586:
5587: <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
5588: <dd>
5589:
5590: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5591: element in scope">has an <code>option</code> element in
5592: scope</a>, then act as if an end tag with the tag name "option"
5593: had been seen.</p>
5594:
5595: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5596: any.</p>
5597:
5598: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5599:
5600: </dd>
5601:
5602: <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
5603: <dd>
5604:
5605: <!-- the parsing rules for ruby really don't match IE much at all,
5606: but in practice the markup used is very simple and so strict
5607: compatibility with IE isn't required. For example, as defined
5608: here we get very, very different behaviour than IE for
5609: pathological cases like:
5610:
5611: <ruby><ol><li><p>a<rt>b
5612: <ruby>a<rt>b<p>c
5613:
5614: But in practice most ruby markup falls into these cases:
5615:
5616: <ruby>a<rt>b</ruby>
5617: <ruby>a<rp>b<rt>c<rp>d</ruby>
5618: <ruby>a<rt>b</rt></ruby>
5619: <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
5620:
5621: -->
5622:
5623: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5624: element in scope">has a <code>ruby</code> element in scope</a>,
5625: then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
5626: node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
5627: <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
5628: node</a> up to the node immediately before the bottommost
5629: <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
5630: elements</a>.</p>
5631:
5632: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5633:
5634: </dd>
5635:
5636: <dt>An end tag whose tag name is "br"</dt>
5637: <dd>
5638: <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
5639: the tag name "br" had been seen. Ignore the end tag token.</p>
5640: </dd>
5641:
5642: <dt>A start tag whose tag name is "math"</dt>
5643: <dd>
5644:
5645: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5646: any.</p>
5647:
5648: <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
5649: fixes the case of MathML attributes that are not all
5650: lowercase.)</p>
5651:
5652: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
5653: fixes the use of namespaced attributes, in particular XLink.)</p>
5654:
5655: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
5656: <a href="#mathml-namespace">MathML namespace</a>.</p>
5657:
5658: <!-- If we ever change the frameset-ok flag to an insertion mode,
5659: the following change would be implied, except we'd have to do it
5660: even in the face of a self-closed tag:
5661: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
5662: -->
5663:
5664: <p>If the token has its <i>self-closing flag</i> set, pop the
5665: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5666: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
5667: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
5668:
5669: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
5670: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
5671: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
5672: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
5673: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
5674: foreign content">in foreign content</a>".</p>
5675:
5676: </dd>
5677:
5678: <dt>A start tag whose tag name is "svg"</dt>
5679: <dd>
5680:
5681: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5682: any.</p>
5683:
5684: <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
5685: the case of SVG attributes that are not all lowercase.)</p>
5686:
5687: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
5688: fixes the use of namespaced attributes, in particular XLink in
5689: SVG.)</p>
5690:
5691: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
5692: <a href="#svg-namespace">SVG namespace</a>.</p>
5693:
5694: <!-- If we ever change the frameset-ok flag to an insertion mode,
5695: the following change would be implied, except we'd have to do it
5696: even in the face of a self-closed tag:
5697: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
5698: -->
5699:
5700: <p>If the token has its <i>self-closing flag</i> set, pop the
5701: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5702: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
5703: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
5704:
5705: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
5706: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
5707: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
5708: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
5709: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
5710: foreign content">in foreign content</a>".</p>
5711:
5712: </dd>
5713:
5714: <dt>A start <!--or end--> tag whose tag name is one of: "caption",
5715: "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
5716: "thead", "tr"</dt>
5717: <!--<dt>An end tag whose tag name is one of: "area", "base",
5718: "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
5719: "img", "input", "isindex", "keygen", "link", "meta", "noembed",
5720: "noframes", "param", "script", "select", "source", "spacer",
5721: "style", "table", "textarea", "title", "wbr"</dt>-->
5722: <!--<dt>An end tag whose tag name is "noscript", if the
5723: <span>scripting flag</span> is enabled</dt>-->
5724: <dd>
5725: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5726: <!-- end tags are commented out because since they can never end
5727: up on the stack anyway, the default end tag clause will
5728: automatically handle them. we don't want to have text in the spec
5729: that is just an optimisation, as that detracts from the spec
5730: itself -->
5731: </dd>
5732:
5733: <dt>Any other start tag</dt>
5734: <dd>
5735:
5736: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5737: any.</p>
5738:
5739: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5740:
5741: <p class="note">This element will be a <a href="#phrasing">phrasing</a>
5742: element.</p>
5743:
5744: </dd>
5745:
5746: <dt>Any other end tag</dt>
5747: <dd>
5748:
5749: <p>Run the following steps:</p>
5750:
5751: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
5752: node</a> (the bottommost node of the stack).</p></li>
5753:
5754: <li><p>If <var title="">node</var> has the same tag name as
5755: the end tag token, then:</p>
5756:
5757: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5758:
5759: <li><p>If the tag name of the end tag token does not match
5760: the tag name of the <a href="#current-node">current node</a>, this is a
5761: <a href="#parse-error">parse error</a>.</p></li>
5762:
5763: <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
5764: to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
5765:
5766: </ol></li>
5767:
5768: <li><p>Otherwise, if <var title="">node</var> is in neither the
5769: <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
5770: category, then this is a <a href="#parse-error">parse error</a>; ignore the
5771: token, and abort these steps.</p></li>
5772:
5773: <li><p>Set <var title="">node</var> to the previous entry in the
5774: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
5775:
5776: <li><p>Return to step 2.</p></li>
5777:
5778: </ol></dd>
5779:
1.91 mike 5780: </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 5781:
5782: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.91 mike 5783: mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>", tokens must be
1.1 mike 5784: handled as follows:</p>
5785:
5786: <dl class="switch"><dt>A character token</dt>
5787: <dd>
5788:
5789: <p><a href="#insert-a-character" title="insert a character">Insert the token's
5790: character</a> into the <a href="#current-node">current node</a>.</p>
5791:
5792: </dd>
5793:
5794: <dt>An end-of-file token</dt>
5795: <dd>
5796:
5797: <!-- can't be the fragment case -->
5798: <p><a href="#parse-error">Parse error</a>.</p>
5799:
5800: <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
1.484 mike 5801: element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-started">"already
5802: started"</a>.</p>
1.1 mike 5803:
5804: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5805: elements</a>.</p>
5806:
5807: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5808: insertion mode</a> and reprocess the current token.</p>
5809:
5810: </dd>
5811:
5812: <dt>An end tag whose tag name is "script"</dt>
5813: <dd>
5814:
5815: <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
5816: (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
5817:
5818: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5819: elements</a>.</p>
5820:
5821: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5822: insertion mode</a>.</p>
5823:
5824: <p>Let the <var title="">old insertion point</var> have the
5825: same value as the current <a href="#insertion-point">insertion point</a>. Let
5826: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
5827: input character</a>.</p>
5828:
5829: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
5830: one.</p>
5831:
5832: <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 5833: which might cause <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters
1.1 mike 5834: to be inserted into the tokenizer</a>, and might cause the
5835: tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
5836:
5837: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
5838: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
5839: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
5840:
5841: <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
5842: <a href="#insertion-point">insertion point</a> to its previous value. This value
5843: might be the "undefined" value.)</p>
5844:
5845: <p id="scriptTagParserResumes">At this stage, if there is a
1.484 mike 5846: <a href="semantics.html#pending-parsing-blocking-script">pending parsing-blocking script</a>, then:</p>
1.1 mike 5847:
5848: <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
5849:
5850: <dd>
5851:
5852: <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
5853: processing of any nested invocations of the tokenizer, yielding
5854: control back to the caller. (Tokenization will resume when the
5855: caller returns to the "outer" tree construction stage.)</p>
5856:
5857: <p class="note">The tree construction stage of this particular
5858: parser is <a href="#nestedParsing">being called reentrantly</a>,
1.159 mike 5859: 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 5860:
5861: </dd>
5862:
5863:
5864: <dt>Otherwise:</dt>
5865:
5866: <dd>
5867:
5868: <p>Follow these steps:</p>
5869:
1.484 mike 5870: <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-parsing-blocking-script">pending
5871: parsing-blocking script</a>. There is no longer a <a href="semantics.html#pending-parsing-blocking-script">pending
5872: parsing-blocking script</a>.</p></li>
5873:
5874: <li><p>Block the <a href="#tokenization" title="tokenization">tokenizer</a>
5875: for this instance of the <a href="#html-parser">HTML parser</a>, such that
5876: the <a href="browsers.html#event-loop">event loop</a> will not run <a href="browsers.html#concept-task" title="concept-task">tasks</a> that invoke the <a href="#tokenization" title="tokenization">tokenizer</a>.</p></li>
5877:
5878: <li><p><a href="browsers.html#spin-the-event-loop">Spin the event loop</a> until there is no <a href="semantics.html#a-style-sheet-blocking-scripts" title="a style sheet blocking scripts">style sheet blocking
5879: scripts</a> and <var title="">the script</var>'s
5880: <a href="semantics.html#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag is set.</p></li>
5881:
5882: <li><p>Unblock the <a href="#tokenization" title="tokenization">tokenizer</a>
5883: for this instance of the <a href="#html-parser">HTML parser</a>, such that
5884: <a href="browsers.html#concept-task" title="concept-task">tasks</a> that invoke the <a href="#tokenization" title="tokenization">tokenizer</a> can again be
5885: run.</p></li>
1.1 mike 5886:
5887: <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
5888: <a href="#next-input-character">next input character</a>.</p></li>
5889:
5890: <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
5891: by one (it should be zero before this step, so this sets it to
5892: one).</p></li>
5893:
1.484 mike 5894: <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute</a>
5895: <var title="">the script</var>.</p></li>
1.1 mike 5896:
5897: <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
5898: by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
5899: zero (which it always should be at this point), then set the
5900: <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
5901:
5902: </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
5903: again.</p></li>
5904:
1.484 mike 5905: <li><p>If there is once again a <a href="semantics.html#pending-parsing-blocking-script">pending parsing-blocking
1.1 mike 5906: script</a>, then repeat these steps from step 1.</p></li>
5907:
5908: </ol></dd>
5909:
5910: </dl></dd>
5911:
5912: <dt>Any other end tag</dt>
5913: <dd>
5914:
5915: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5916: elements</a>.</p>
5917:
5918: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5919: insertion mode</a>.</p>
5920:
5921: </dd>
5922:
5923: </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>
5924:
5925: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
5926: mode: in table">in table</a>", tokens must be handled as follows:</p>
5927:
5928: <dl class="switch"><dt>A character token</dt>
5929: <dd>
5930:
5931: <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
5932: be an empty list of tokens.</p>
5933:
5934: <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
5935: <a href="#insertion-mode">insertion mode</a>.</p>
5936:
5937: <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
5938: reprocess the token.</p>
5939:
5940: </dd>
5941:
5942: <dt>A comment token</dt>
5943: <dd>
5944: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
5945: node</a> with the <code title="">data</code> attribute set to
5946: the data given in the comment token.</p>
5947: </dd>
5948:
5949: <dt>A DOCTYPE token</dt>
5950: <dd>
5951: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5952: </dd>
5953:
5954: <dt>A start tag whose tag name is "caption"</dt>
5955: <dd>
5956:
5957: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5958: below.)</p>
5959:
5960: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5961: formatting elements</a>.</p>
5962:
5963: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5964: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
5965:
5966: </dd>
5967:
5968: <dt>A start tag whose tag name is "colgroup"</dt>
5969: <dd>
5970:
5971: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5972: below.)</p>
5973:
5974: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5975: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
5976: group</a>".</p>
5977:
5978: </dd>
5979:
5980: <dt>A start tag whose tag name is "col"</dt>
5981: <dd>
5982: <p>Act as if a start tag token with the tag name "colgroup"
5983: had been seen, then reprocess the current token.</p>
5984: </dd>
5985:
5986: <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
5987: <dd>
5988:
5989: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5990: below.)</p>
5991:
5992: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5993: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
5994: body</a>".</p>
5995:
5996: </dd>
5997:
5998: <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
5999: <dd>
6000: <p>Act as if a start tag token with the tag name "tbody" had
6001: been seen, then reprocess the current token.</p>
6002: </dd>
6003:
6004: <dt>A start tag whose tag name is "table"</dt>
6005: <dd>
6006:
6007: <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
6008: the tag name "table" had been seen, then, if that token wasn't
6009: ignored, reprocess the current token.</p>
6010:
6011: <p class="note">The fake end tag token here can only be
6012: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6013:
6014: </dd>
6015:
6016: <dt>An end tag whose tag name is "table"</dt>
6017: <dd>
6018:
6019: <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
6020: scope</a> with the same tag name as the token, this is a
6021: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6022: case</a>)</p>
6023:
6024: <p>Otherwise:</p>
6025:
6026: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
6027: element has been popped from the stack.</p>
6028:
6029: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
6030:
6031: </dd>
6032:
6033: <dt>An end tag whose tag name is one of: "body", "caption",
6034: "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
6035: "thead", "tr"</dt>
6036: <dd>
6037: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6038: </dd>
6039:
6040: <dt>A start tag whose tag name is one of: "style", "script"</dt>
6041: <dd>
6042:
6043: <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
6044: mode</a>.</p>
6045:
6046: </dd>
6047:
6048: <dt>A start tag whose tag name is "input"</dt>
6049: <dd>
6050:
6051: <p>If the token does not have an attribute with the name "type",
6052: or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
6053: case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
6054: else" entry below.</p>
6055:
6056: <p>Otherwise:</p>
6057:
6058: <p><a href="#parse-error">Parse error</a>.</p>
6059:
6060: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6061:
6062: <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
6063: open elements</a>.</p>
6064:
6065: </dd>
6066:
6067: <dt>An end-of-file token</dt>
6068: <dd>
6069:
6070: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 6071: <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 6072: error</a>.</p>
6073:
6074: <p class="note">It can only be the <a href="#current-node">current node</a> in
6075: the <a href="#fragment-case">fragment case</a>.</p>
6076:
6077: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6078:
6079: </dd>
6080:
6081: <dt>Anything else</dt>
6082: <dd>
6083:
6084: <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
6085: rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
6086: body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
6087: <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
6088: <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
6089: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
6090: into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
6091:
6092: </dd>
6093:
6094: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
6095: back to a table context</dfn>, it means that the UA must, while
6096: 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 6097: element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1 mike 6098: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6099:
6100: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 6101: <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 6102: case</a>.</p>
6103:
6104:
6105:
6106: <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>
6107:
6108: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
6109: mode: in table text">in table text</a>", tokens must be handled
6110: as follows:</p>
6111:
6112: <dl class="switch"><dt>A character token</dt>
6113: <dd>
6114:
6115: <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
6116: tokens</a></var> list.</p>
6117:
6118: </dd>
6119:
6120:
6121: <dt>Anything else</dt>
6122: <dd>
6123:
6124: <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
6125: tokens</a></var> list are character tokens that are not one of U+0009
6126: CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
6127: (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
6128: reprocess those character tokens using the rules given in the
6129: "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
6130: table">in table</a>" insertion mode.</p>
6131:
6132: <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
6133: characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
6134: tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
6135:
6136: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
6137: insertion mode</a> and reprocess the token.</p>
6138:
6139: </dd>
6140:
6141: </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>
6142:
6143: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
6144: mode: in caption">in caption</a>", tokens must be handled as follows:</p>
6145:
6146: <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
6147: <dd>
6148:
6149: <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
6150: scope</a> with the same tag name as the token, this is a
6151: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6152: case</a>)</p>
6153:
6154: <p>Otherwise:</p>
6155:
6156: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
6157:
6158: <p>Now, if the <a href="#current-node">current node</a> is not a
6159: <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
6160: error</a>.</p>
6161:
6162: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
6163: element has been popped from the stack.</p>
6164:
6165: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
6166: the last marker</a>.</p>
6167:
6168: <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>
6169:
6170: </dd>
6171:
6172: <dt>A start tag whose tag name is one of: "caption", "col",
6173: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
6174: <dt>An end tag whose tag name is "table"</dt>
6175: <dd>
6176:
6177: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
6178: name "caption" had been seen, then, if that token wasn't
6179: ignored, reprocess the current token.</p>
6180:
6181: <p class="note">The fake end tag token here can only be
6182: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6183:
6184: </dd>
6185:
6186: <dt>An end tag whose tag name is one of: "body", "col",
6187: "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
6188: "tr"</dt>
6189: <dd>
6190: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6191: </dd>
6192:
6193: <dt>Anything else</dt>
6194: <dd>
6195: <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
6196: mode</a>.</p>
6197: </dd>
6198:
6199: </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>
6200:
6201: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
6202: mode: in column group">in column group</a>", tokens must be handled as follows:</p>
6203:
6204: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6205: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6206: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6207: <dd>
6208: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6209: the <a href="#current-node">current node</a>.</p>
6210: </dd>
6211:
6212: <dt>A comment token</dt>
6213: <dd>
6214: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6215: node</a> with the <code title="">data</code> attribute set to
6216: the data given in the comment token.</p>
6217: </dd>
6218:
6219: <dt>A DOCTYPE token</dt>
6220: <dd>
6221: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6222: </dd>
6223:
6224: <dt>A start tag whose tag name is "html"</dt>
6225: <dd>
6226: <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
6227: mode</a>.</p>
6228: </dd>
6229:
6230: <dt>A start tag whose tag name is "col"</dt>
6231: <dd>
6232:
6233: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
6234: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6235: elements</a>.</p>
6236:
6237: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6238: token's <i>self-closing flag</i></a>, if it is set.</p>
6239:
6240: </dd>
6241:
6242: <dt>An end tag whose tag name is "colgroup"</dt>
6243: <dd>
6244:
6245: <p>If the <a href="#current-node">current node</a> is the root
1.159 mike 6246: <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 6247: error</a>; ignore the token. (<a href="#fragment-case">fragment
6248: case</a>)</p>
6249:
6250: <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
6251: 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
6252: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
6253: "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
6254:
6255: </dd>
6256:
6257: <dt>An end tag whose tag name is "col"</dt>
6258: <dd>
6259: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6260: </dd>
6261:
6262: <dt>An end-of-file token</dt>
6263: <dd>
6264:
1.159 mike 6265: <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 6266: element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
6267: case</a>)</p>
6268:
6269: <p>Otherwise, act as described in the "anything else" entry
6270: below.</p>
6271:
6272: </dd>
6273:
6274: <dt>Anything else</dt>
6275: <dd>
6276:
6277: <p>Act as if an end tag with the tag name "colgroup" had been
6278: seen, and then, if that token wasn't ignored, reprocess the
6279: current token.</p>
6280:
6281: <p class="note">The fake end tag token here can only be
6282: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6283:
6284: </dd>
6285:
6286: </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>
6287:
6288: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
6289: mode: in table body">in table body</a>", tokens must be handled as follows:</p>
6290:
6291: <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
6292: <dd>
6293:
6294: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6295: context</a>. (See below.)</p>
6296:
6297: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
6298: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
6299: in row">in row</a>".</p>
6300:
6301: </dd>
6302:
6303: <dt>A start tag whose tag name is one of: "th", "td"</dt>
6304: <dd>
6305: <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
6306: the tag name "tr" had been seen, then reprocess the current
6307: token.</p>
6308: </dd>
6309:
6310: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
6311: "thead"</dt>
6312: <dd>
6313:
6314: <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
6315: scope</a> with the same tag name as the token, this is a
6316: <a href="#parse-error">parse error</a>. Ignore the token.</p>
6317:
6318: <p>Otherwise:</p>
6319:
6320: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6321: context</a>. (See below.)</p>
6322:
6323: <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
6324: open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
6325: to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
6326:
6327: </dd>
6328:
6329: <dt>A start tag whose tag name is one of: "caption", "col",
6330: "colgroup", "tbody", "tfoot", "thead"</dt>
6331: <dt>An end tag whose tag name is "table"</dt>
6332: <dd>
6333:
6334: <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
6335: <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
6336: element in table scope</a>, this is a <a href="#parse-error">parse
6337: error</a>. Ignore the token. (<a href="#fragment-case">fragment
6338: case</a>)</p>
6339:
6340: <p>Otherwise:</p>
6341:
6342: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6343: context</a>. (See below.)</p>
6344:
6345: <p>Act as if an end tag with the same tag name as the
6346: <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
6347: been seen, then reprocess the current token.</p>
6348:
6349: </dd>
6350:
6351: <dt>An end tag whose tag name is one of: "body", "caption",
6352: "col", "colgroup", "html", "td", "th", "tr"</dt>
6353: <dd>
6354: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6355: </dd>
6356:
6357: <dt>Anything else</dt>
6358: <dd>
6359: <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
6360: mode</a>.</p>
6361: </dd>
6362:
6363: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
6364: back to a table body context</dfn>, it means that the UA must,
6365: 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 6366: <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 6367: element, pop elements from the <a href="#stack-of-open-elements">stack of open
6368: elements</a>.</p>
6369:
6370: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 6371: <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 6372: case</a>.</p>
6373:
6374:
6375: <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>
6376:
6377: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
6378: mode: in row">in row</a>", tokens must be handled as follows:</p>
6379:
6380: <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
6381: <dd>
6382:
6383: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
6384: context</a>. (See below.)</p>
6385:
6386: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
6387: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
6388: in cell">in cell</a>".</p>
6389:
6390: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
6391: formatting elements</a>.</p>
6392:
6393: </dd>
6394:
6395: <dt>An end tag whose tag name is "tr"</dt>
6396: <dd>
6397:
6398: <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
6399: scope</a> with the same tag name as the token, this is a
6400: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6401: case</a>)</p>
6402:
6403: <p>Otherwise:</p>
6404:
6405: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
6406: context</a>. (See below.)</p>
6407:
6408: <p>Pop the <a href="#current-node">current node</a> (which will be a
6409: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
6410: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
6411: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
6412: body</a>".</p>
6413:
6414: </dd>
6415:
6416: <dt>A start tag whose tag name is one of: "caption", "col",
6417: "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
6418: <dt>An end tag whose tag name is "table"</dt>
6419: <dd>
6420:
6421: <p>Act as if an end tag with the tag name "tr" had been seen,
6422: then, if that token wasn't ignored, reprocess the current
6423: token.</p>
6424:
6425: <p class="note">The fake end tag token here can only be
6426: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6427:
6428: </dd>
6429:
6430: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
6431: "thead"</dt>
6432: <dd>
6433:
6434: <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
6435: scope</a> with the same tag name as the token, this is a
6436: <a href="#parse-error">parse error</a>. Ignore the token.</p>
6437:
6438: <p>Otherwise, act as if an end tag with the tag name "tr" had
6439: been seen, then reprocess the current token.</p>
6440:
6441: </dd>
6442:
6443: <dt>An end tag whose tag name is one of: "body", "caption",
6444: "col", "colgroup", "html", "td", "th"</dt>
6445: <dd>
6446: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6447: </dd>
6448:
6449: <dt>Anything else</dt>
6450: <dd>
6451: <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
6452: mode</a>.</p>
6453: </dd>
6454:
6455: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
6456: back to a table row context</dfn>, it means that the UA must,
6457: 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 6458: element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1 mike 6459: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6460:
6461: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 6462: <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 6463: case</a>.</p>
6464:
6465:
6466: <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>
6467:
6468: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
6469: mode: in cell">in cell</a>", tokens must be handled as follows:</p>
6470:
6471: <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
6472: <dd>
6473:
6474: <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
6475: scope</a> with the same tag name as that of the token, then
6476: this is a <a href="#parse-error">parse error</a> and the token must be
6477: ignored.</p>
6478:
6479: <p>Otherwise:</p>
6480:
6481: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
6482:
6483: <p>Now, if the <a href="#current-node">current node</a> is not an element
6484: with the same tag name as the token, then this is a
6485: <a href="#parse-error">parse error</a>.</p>
6486:
6487: <p>Pop elements from this stack until an element with the same
6488: tag name as the token has been popped from the stack.</p>
6489:
6490: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
6491: the last marker</a>.</p>
6492:
6493: <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
6494: <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
6495: this point.)</p>
6496:
6497: </dd>
6498:
6499: <dt>A start tag whose tag name is one of: "caption", "col",
6500: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
6501: <dd>
6502:
6503: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
6504: <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
6505: a <code>td</code> or <code>th</code> element in table
6506: scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
6507: the token. (<a href="#fragment-case">fragment case</a>)</p>
6508:
6509: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
6510: reprocess the current token.</p>
6511:
6512: </dd>
6513:
6514: <dt>An end tag whose tag name is one of: "body", "caption",
6515: "col", "colgroup", "html"</dt>
6516: <dd>
6517: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6518: </dd>
6519:
6520: <dt>An end tag whose tag name is one of: "table", "tbody",
6521: "tfoot", "thead", "tr"</dt>
6522: <dd>
6523:
6524: <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
6525: scope</a> with the same tag name as that of the token
6526: (which can only happen for "tbody", "tfoot" and "thead", or,
6527: in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
6528: error</a> and the token must be ignored.</p>
6529:
6530: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
6531: reprocess the current token.</p>
6532:
6533: </dd>
6534:
6535: <dt>Anything else</dt>
6536: <dd>
6537: <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
6538: mode</a>.</p>
6539: </dd>
6540:
6541: </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
6542: mean to run the following algorithm:</p>
6543:
6544: <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>
6545: element in table scope</a>, then act as if an end tag token
6546: with the tag name "td" had been seen.</p></li>
6547:
6548: <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
6549: <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
6550: <code>th</code> element in table scope</a>; act as if an end
6551: tag token with the tag name "th" had been seen.</p></li>
6552:
6553: </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
6554: 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
6555: the same time, nor can it have neither when the <a href="#insertion-mode">insertion
6556: mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
6557: cell</a>".</p>
6558:
6559:
6560: <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>
6561:
6562: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
6563: mode: in select">in select</a>", tokens must be handled as follows:</p>
6564:
6565: <dl class="switch"><dt>A character token</dt>
6566: <dd>
6567: <p><a href="#insert-a-character" title="insert a character">Insert the token's
6568: character</a> into the <a href="#current-node">current node</a>.</p>
6569: </dd>
6570:
6571: <dt>A comment token</dt>
6572: <dd>
6573: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6574: node</a> with the <code title="">data</code> attribute set to
6575: the data given in the comment token.</p>
6576: </dd>
6577:
6578: <dt>A DOCTYPE token</dt>
6579: <dd>
6580: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6581: </dd>
6582:
6583: <dt>A start tag whose tag name is "html"</dt>
6584: <dd>
6585: <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
6586: mode</a>.</p>
6587: </dd>
6588:
6589: <dt>A start tag whose tag name is "option"</dt>
6590: <dd>
6591:
6592: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6593: element, act as if an end tag with the tag name "option" had
6594: been seen.</p>
6595:
6596: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6597:
6598: </dd>
6599:
6600: <dt>A start tag whose tag name is "optgroup"</dt>
6601: <dd>
6602:
6603: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6604: element, act as if an end tag with the tag name "option" had
6605: been seen.</p>
6606:
6607: <p>If the <a href="#current-node">current node</a> is an
6608: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
6609: tag name "optgroup" had been seen.</p>
6610:
6611: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6612:
6613: </dd>
6614:
6615: <dt>An end tag whose tag name is "optgroup"</dt>
6616: <dd>
6617:
6618: <p>First, if the <a href="#current-node">current node</a> is an
6619: <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
6620: it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
6621: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
6622: the tag name "option" had been seen.</p>
6623:
6624: <p>If the <a href="#current-node">current node</a> is an
6625: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
6626: <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
6627: <a href="#parse-error">parse error</a>; ignore the token.</p>
6628:
6629: </dd>
6630:
6631: <dt>An end tag whose tag name is "option"</dt>
6632: <dd>
6633:
6634: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6635: element, then pop that node from the <a href="#stack-of-open-elements">stack of open
6636: elements</a>. Otherwise, this is a <a href="#parse-error">parse
6637: error</a>; ignore the token.</p>
6638:
6639: </dd>
6640:
6641: <dt>An end tag whose tag name is "select"</dt>
6642: <dd>
6643:
6644: <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
6645: scope</a> with the same tag name as the token, this is a
6646: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6647: case</a>)</p>
6648:
6649: <p>Otherwise:</p>
6650:
6651: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
6652: until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
6653: stack.</p>
6654:
6655: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
6656:
6657: </dd>
6658:
6659: <dt>A start tag whose tag name is "select"</dt>
6660: <dd>
6661:
6662: <p><a href="#parse-error">Parse error</a>. Act as if the token had been
6663: an end tag with the tag name "select" instead.</p>
6664:
6665: </dd>
6666:
6667: <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
6668: <dd>
1.73 mike 6669:
6670: <p><a href="#parse-error">Parse error</a>.</p>
6671:
1.124 mike 6672: <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>
6673: element in table scope</a>, ignore the token. (<a href="#fragment-case">fragment
6674: case</a>)</p>
1.73 mike 6675:
6676: <p>Otherwise, act as if an end tag with the tag name "select" had
6677: been seen, and reprocess the token.</p>
6678:
1.1 mike 6679: </dd>
6680:
6681: <dt>A start tag token whose tag name is "script"</dt>
6682: <dd>
6683: <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
6684: mode</a>.</p>
6685: </dd>
6686:
6687: <dt>An end-of-file token</dt>
6688: <dd>
6689:
6690: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 6691: <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 6692: error</a>.</p>
6693:
6694: <p class="note">It can only be the <a href="#current-node">current node</a> in
6695: the <a href="#fragment-case">fragment case</a>.</p>
6696:
6697: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6698:
6699: </dd>
6700:
6701: <dt>Anything else</dt>
6702: <dd>
6703: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6704: </dd>
6705:
6706: </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>
6707:
6708: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
6709: mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
6710:
6711: <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
6712: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
6713: <dd>
6714: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
6715: name "select" had been seen, and reprocess the token.</p>
6716: </dd>
6717:
6718: <dt>An end tag whose tag name is one of: "caption", "table",
6719: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
6720: <dd>
6721:
6722: <p><a href="#parse-error">Parse error</a>.</p>
6723:
6724: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
6725: element in table scope</a> with the same tag name as that
6726: of the token, then act as if an end tag with the tag name
6727: "select" had been seen, and reprocess the token. Otherwise,
6728: ignore the token.</p>
6729:
6730: </dd>
6731:
6732: <dt>Anything else</dt>
6733: <dd>
6734: <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
6735: mode</a>.</p>
6736: </dd>
6737:
1.168 mike 6738: </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 6739:
6740: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
6741: mode: in foreign content">in foreign content</a>", tokens must be
6742: handled as follows:</p>
6743:
6744: <dl class="switch"><dt>A character token</dt>
6745: <dd>
6746:
6747: <p><a href="#insert-a-character" title="insert a character">Insert the token's
6748: character</a> into the <a href="#current-node">current node</a>.</p>
6749:
6750: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
6751: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
6752: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
6753: flag</a> to "not ok".</p>
6754:
6755: </dd>
6756:
6757: <dt>A comment token</dt>
6758: <dd>
6759: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6760: node</a> with the <code title="">data</code> attribute set to
6761: the data given in the comment token.</p>
6762: </dd>
6763:
6764: <dt>A DOCTYPE token</dt>
6765: <dd>
6766: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6767: </dd>
6768:
6769: <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>
6770: <dd>
6771:
6772: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6773: elements</a>.</p>
6774:
6775: <p>Let the <var title="">old insertion point</var> have the
6776: same value as the current <a href="#insertion-point">insertion point</a>. Let
6777: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
6778: input character</a>.</p>
6779:
6780: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
6781: one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
6782:
6783: <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
6784: the <code title="">script</code> element</a> according to the SVG
1.187 mike 6785: rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
1.1 mike 6786:
1.159 mike 6787: <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 6788: tokenizer</a>, the parser will not be executed reentrantly,
6789: since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
6790:
6791: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
6792: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
6793: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
6794:
6795: <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
6796: <a href="#insertion-point">insertion point</a> to its previous value. This value
6797: might be the "undefined" value.)</p>
6798:
6799: </dd>
6800:
6801: <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>
6802: <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>
6803: <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>
6804: <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>
6805: <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>
6806: <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>
6807: <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>
6808: <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>
6809: <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>
6810: <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>
6811: <dt>An end tag</dt>
6812: <dd>
6813:
6814: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
6815: <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
6816:
6817: <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
6818: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
1.336 mike 6819: content</a>", but there is no element <a href="#has-an-element-in-scope" title="has an
6820: element in scope">in scope</a> that has a namespace other than
6821: the <a href="#html-namespace-0">HTML namespace</a>, switch the <a href="#insertion-mode">insertion
1.1 mike 6822: mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
6823:
6824: </dd>
6825:
6826: <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
6827: "blockquote", "body"<!--by inspection-->, "br", "center", "code",
1.422 mike 6828: "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
6829: uniformly throughout the parser -->, "em", "embed", "h1", "h2",
6830: "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
1.1 mike 6831: completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
6832: "li", "listing"<!-- so that pre and listing can be handled
6833: uniformly throughout the parser -->, "menu", "meta", "nobr",
6834: "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
6835: the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
6836: "span", "strong", "strike"<!-- so that s and strike can be handled
6837: uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
1.305 mike 6838: "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt> <!-- this
6839: list was determined empirically by studying over 6,000,000,000
1.422 mike 6840: pages that were specifically not XML pages -->
6841: <dt>A start tag whose tag name is "font", if the token has any
6842: attributes named "color", "face", or "size"</dt> <!-- the
6843: attributes here are required so that SVG <font> will go through as
6844: SVG but legacy <font>s won't -->
6845: <dt>An end-of-file token</dt> <dd>
1.1 mike 6846:
6847: <p><a href="#parse-error">Parse error</a>.</p>
6848:
6849: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
6850: the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
6851: namespace</a>.</p>
6852:
6853: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
6854: insertion mode</a>, and reprocess the token.</p>
6855:
6856: </dd>
6857:
6858: <dt>Any other start tag</dt>
6859: <dd>
6860:
6861: <p>If the <a href="#current-node">current node</a> is an element in the
6862: <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
6863: attributes</a> for the token. (This fixes the case of MathML
6864: attributes that are not all lowercase.)</p>
6865:
6866: <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
6867: namespace</a>, and the token's tag name is one of the ones in
6868: the first column of the following table, change the tag name to
6869: the name given in the corresponding cell in the second
6870: column. (This fixes the case of SVG elements that are not all
6871: lowercase.)</p>
6872:
6873: <table><thead><tr><th> Tag name </th><th> Element name
6874: </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
6875: </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
6876: </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
6877: </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
6878: </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
6879: </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
6880: </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
6881: </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
6882: </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
6883: </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
6884: </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
6885: </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
6886: </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
6887: </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
6888: </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
6889: </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
6890: </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
6891: </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
6892: </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
6893: </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
6894: </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
6895: </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
6896: </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
6897: </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
6898: </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
6899: </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
6900: </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
6901: </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
6902: </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
6903: </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
6904: </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
6905: </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
6906: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
6907: </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
6908: </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
6909: <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
6910: </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
6911: </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
6912: namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
6913: token. (This fixes the case of SVG attributes that are not all
6914: lowercase.)</p>
6915:
6916: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
6917: fixes the use of namespaced attributes, in particular XLink in
6918: SVG.)</p>
6919:
6920: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
6921: same namespace as the <a href="#current-node">current node</a>.</p>
6922:
6923: <p>If the token has its <i>self-closing flag</i> set, pop the
6924: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6925: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
6926: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
6927:
6928: </dd>
6929:
6930: </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>
6931:
6932: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
6933: mode: after body">after body</a>", tokens must be handled as follows:</p>
6934:
6935: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6936: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6937: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6938: <dd>
6939: <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
6940: mode</a>.</p>
6941: </dd>
6942:
6943: <dt>A comment token</dt>
6944: <dd>
6945: <p>Append a <code>Comment</code> node to the first element in
1.159 mike 6946: 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 6947: element), with the <code title="">data</code> attribute set to
6948: the data given in the comment token.</p>
6949: </dd>
6950:
6951: <dt>A DOCTYPE token</dt>
6952: <dd>
6953: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6954: </dd>
6955:
6956: <dt>A start tag whose tag name is "html"</dt>
6957: <dd>
6958: <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
6959: mode</a>.</p>
6960: </dd>
6961:
6962: <dt>An end tag whose tag name is "html"</dt>
6963: <dd>
6964:
6965: <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
6966: fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
6967: error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
6968:
6969: <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
6970: body</a>".</p>
6971:
6972: </dd>
6973:
6974: <dt>An end-of-file token</dt>
6975: <dd>
6976: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6977: </dd>
6978:
6979: <dt>Anything else</dt>
6980: <dd>
6981:
6982: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
6983: mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
6984: body</a>" and reprocess the token.</p>
6985:
6986: </dd>
6987:
6988: </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>
6989:
6990: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
6991: mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
6992:
6993: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6994: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6995: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6996: <dd>
6997: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6998: the <a href="#current-node">current node</a>.</p>
6999: </dd>
7000:
7001: <dt>A comment token</dt>
7002: <dd>
7003: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
7004: node</a> with the <code title="">data</code> attribute set to
7005: the data given in the comment token.</p>
7006: </dd>
7007:
7008: <dt>A DOCTYPE token</dt>
7009: <dd>
7010: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7011: </dd>
7012:
7013: <dt>A start tag whose tag name is "html"</dt>
7014: <dd>
7015: <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
7016: mode</a>.</p>
7017: </dd>
7018:
7019: <dt>A start tag whose tag name is "frameset"</dt>
7020: <dd>
7021: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
7022: </dd>
7023:
7024: <dt>An end tag whose tag name is "frameset"</dt>
7025: <dd>
7026:
7027: <p>If the <a href="#current-node">current node</a> is the root
1.159 mike 7028: <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 7029: error</a>; ignore the token. (<a href="#fragment-case">fragment
7030: case</a>)</p>
7031:
7032: <p>Otherwise, pop the <a href="#current-node">current node</a> from the
7033: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
7034:
7035: <p>If the parser was <em>not</em> originally created as part
7036: of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
7037: (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5 mike 7038: node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1 mike 7039: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
7040: frameset</a>".</p>
7041:
7042: </dd>
7043:
7044: <dt>A start tag whose tag name is "frame"</dt>
7045: <dd>
7046:
7047: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
7048: Immediately pop the <a href="#current-node">current node</a> off the
7049: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
7050:
7051: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
7052: token's <i>self-closing flag</i></a>, if it is set.</p>
7053:
7054: </dd>
7055:
7056: <dt>A start tag whose tag name is "noframes"</dt>
7057: <dd>
7058: <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
7059: mode</a>.</p>
7060: </dd>
7061:
7062: <dt>An end-of-file token</dt>
7063: <dd>
7064:
7065: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 7066: <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 7067: error</a>.</p>
7068:
7069: <p class="note">It can only be the <a href="#current-node">current node</a> in
7070: the <a href="#fragment-case">fragment case</a>.</p>
7071:
7072: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7073:
7074: </dd>
7075:
7076: <dt>Anything else</dt>
7077: <dd>
7078: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7079: </dd>
7080:
7081: </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>
7082:
7083: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
7084: mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
7085:
7086: <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
7087: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
7088: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7089: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7090: <dd>
7091: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
7092: the <a href="#current-node">current node</a>.</p>
7093: </dd>
7094:
7095: <dt>A comment token</dt>
7096: <dd>
7097: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
7098: node</a> with the <code title="">data</code> attribute set to
7099: the data given in the comment token.</p>
7100: </dd>
7101:
7102: <dt>A DOCTYPE token</dt>
7103: <dd>
7104: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7105: </dd>
7106:
7107: <dt>A start tag whose tag name is "html"</dt>
7108: <dd>
7109: <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
7110: mode</a>.</p>
7111: </dd>
7112:
7113: <dt>An end tag whose tag name is "html"</dt>
7114: <dd>
7115: <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
7116: frameset</a>".</p>
7117: </dd>
7118:
7119: <dt>A start tag whose tag name is "noframes"</dt>
7120: <dd>
7121: <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
7122: mode</a>.</p>
7123: </dd>
7124:
7125: <dt>An end-of-file token</dt>
7126: <dd>
7127: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7128: </dd>
7129:
7130: <dt>Anything else</dt>
7131: <dd>
7132: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7133: </dd>
7134:
1.336 mike 7135: </dl><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>
1.1 mike 7136:
7137: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
7138: mode: after after body">after after body</a>", tokens must be handled as follows:</p>
7139:
7140: <dl class="switch"><dt>A comment token</dt>
7141: <dd>
7142: <p>Append a <code>Comment</code> node to the <code>Document</code>
7143: object with the <code title="">data</code> attribute set to the
7144: data given in the comment token.</p>
7145: </dd>
7146:
7147: <dt>A DOCTYPE token</dt>
7148: <dt>A character token that is one of U+0009 CHARACTER
7149: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7150: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7151: <dt>A start tag whose tag name is "html"</dt>
7152: <dd>
7153: <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
7154: mode</a>.</p>
7155: </dd>
7156:
7157: <dt>An end-of-file token</dt>
7158: <dd>
7159: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7160: </dd>
7161:
7162: <dt>Anything else</dt>
7163: <dd>
7164: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
7165: to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
7166: reprocess the token.</p>
7167: </dd>
7168:
7169: </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>
7170:
7171: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
7172: mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
7173:
7174: <dl class="switch"><dt>A comment token</dt>
7175: <dd>
7176: <p>Append a <code>Comment</code> node to the <code>Document</code>
7177: object with the <code title="">data</code> attribute set to the
7178: data given in the comment token.</p>
7179: </dd>
7180:
7181: <dt>A DOCTYPE token</dt>
7182: <dt>A character token that is one of U+0009 CHARACTER
7183: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7184: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7185: <dt>A start tag whose tag name is "html"</dt>
7186: <dd>
7187: <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
7188: mode</a>.</p>
7189: </dd>
7190:
7191: <dt>An end-of-file token</dt>
7192: <dd>
7193: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7194: </dd>
7195:
7196: <dt>A start tag whose tag name is "noframes"</dt>
7197: <dd>
7198: <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
7199: mode</a>.</p>
7200: </dd>
7201:
7202: <dt>Anything else</dt>
7203: <dd>
7204: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7205: </dd>
7206:
1.266 mike 7207: </dl></div><div class="impl">
7208:
7209: <h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4>
1.1 mike 7210:
7211: <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
1.484 mike 7212: the document, the user agent must run the following steps:</p>
1.1 mike 7213:
1.484 mike 7214: <ol><!-- this happens as part of one of the tasks that runs the parser --><li><p>Set the <a href="dom.html#current-document-readiness">current document readiness</a> to
7215: "interactive" <!-- this also synchronously fires an event --> and
7216: the <a href="#insertion-point">insertion point</a> to undefined.</p></li>
7217:
7218: <li><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
7219: document has finished parsing</a> is not empty, run these
7220: substeps:</p>
7221:
7222: <ol><li><p><a href="browsers.html#spin-the-event-loop">Spin the event loop</a> until the first
7223: <code><a href="semantics.html#script">script</a></code> in the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will
7224: execute when the document has finished parsing</a> has its
7225: <a href="semantics.html#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag set <em>and</em> there
7226: is no <a href="semantics.html#a-style-sheet-blocking-scripts" title="a style sheet blocking scripts">style sheet
7227: blocking scripts</a>.</p></li>
7228:
7229: <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute</a> the
7230: first <code><a href="semantics.html#script">script</a></code> in the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will
7231: execute when the document has finished parsing</a>.</p></li>
7232:
7233: <li><p>Remove the first <code><a href="semantics.html#script">script</a></code> element from the
7234: <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 has
7235: finished parsing</a> (i.e. shift out the first entry in the
7236: list).</p></li>
7237:
7238: <li><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
7239: document has finished parsing</a> is still not empty, repeat
7240: these substeps again from substep 1.</p>
7241:
7242: </li></ol></li>
7243:
7244: <li><p><a href="browsers.html#spin-the-event-loop">Spin the event loop</a> until the the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of
7245: scripts that will execute as soon as possible</a> is
7246: empty.</p></li>
7247:
7248: <li><p><a href="browsers.html#queue-a-task">Queue a task</a> to <a href="browsers.html#fire-a-simple-event">fire a simple
7249: event</a> named <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
7250: <code>Document</code>.</p></li>
7251:
7252: <li><p><a href="browsers.html#spin-the-event-loop">Spin the event loop</a> until there is nothing that
7253: <dfn id="delay-the-load-event" title="delay the load event">delays the load event</dfn> in
7254: the <code>Document</code>.</p></li>
7255:
7256: <li><p><a href="browsers.html#queue-a-task">Queue a task</a> to set the <a href="dom.html#current-document-readiness">current document
7257: readiness</a> to "complete". <!-- this also fires an event
7258: synchronously during the task --></p></li>
1.1 mike 7259:
1.484 mike 7260: <li><p>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
1.1 mike 7261: 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
1.460 mike 7262: simple event</a> named <code title="event-load">load</code> at
1.1 mike 7263: the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
7264: its <code title="dom-event-target">target</code> set to the
7265: <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
1.484 mike 7266: <code><a href="browsers.html#window">Window</a></code> object).</p></li>
1.1 mike 7267:
1.484 mike 7268: <li><p>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
1.1 mike 7269: 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
7270: <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
7271: <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
7272: current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
1.484 mike 7273: must bubble but not be cancelable and has no default
7274: action.</p></li>
1.1 mike 7275:
1.484 mike 7276: </ol><p>The <a href="browsers.html#task-source">task source</a> for the <a href="browsers.html#concept-task" title="concept-task">tasks</a> mentioned in this section is the
7277: <a href="browsers.html#dom-manipulation-task-source">DOM manipulation task source</a>.</p>
1.1 mike 7278:
1.266 mike 7279: </div><div class="impl">
1.1 mike 7280:
7281: <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4>
7282:
7283: <p>When an application uses an <a href="#html-parser">HTML parser</a> in
7284: conjunction with an XML pipeline, it is possible that the
7285: constructed DOM is not compatible with the XML tool chain in certain
7286: subtle ways. For example, an XML toolchain might not be able to
7287: represent attributes with the name <code title="">xmlns</code>,
7288: since they conflict with the Namespaces in XML syntax. There is also
7289: some data that the <a href="#html-parser">HTML parser</a> generates that isn't
7290: included in the DOM itself. This section specifies some rules for
7291: handling these issues.</p>
7292:
7293: <p>If the XML API being used doesn't support DOCTYPEs, the tool may
7294: drop DOCTYPEs altogether.</p>
7295:
7296: <p>If the XML API doesn't support attributes in no namespace that
7297: are named "<code title="">xmlns</code>", attributes whose names
7298: start with "<code title="">xmlns:</code>", or attributes in the
7299: <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
7300: attributes.</p>
7301:
7302: <p>The tool may annotate the output with any namespace declarations
7303: required for proper operation.</p>
7304:
7305: <p>If the XML API being used restricts the allowable characters in
7306: the local names of elements and attributes, then the tool may map
7307: all element and attribute local names that the API wouldn't support
7308: to a set of names that <em>are</em> allowed, by replacing any
7309: character that isn't supported with the uppercase letter U and the
7310: six digits of the character's Unicode code point when expressed in
7311: hexadecimal, using digits 0-9 and capital letters A-F as the
7312: symbols, in increasing numeric order.</p>
7313:
7314: <p class="example">For example, the element name <code title="">foo<bar</code>, which can be output by the <a href="#html-parser">HTML
7315: parser</a>, though it is neither a legal HTML element name nor a
7316: well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
7317: element name (though it's still not legal in HTML by any means).</p>
7318:
7319: <p class="example">As another example, consider the attribute
7320: <code>xlink:href</code>. Used on a MathML element, it becomes, after
7321: being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
7322: attribute with a prefix "<code title="">xlink</code>" and a local
7323: name "<code title="">href</code>". However, used on an HTML element,
7324: it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
7325: might not be accepted by an XML API. It could thus get converted,
7326: becoming "<code title="">xlinkU00003Ahref</code>".</p>
7327:
7328: <p class="note">The resulting names from this conversion
7329: conveniently can't clash with any attribute generated by the
7330: <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
7331: those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
7332: algorithm's table.</p>
7333:
7334: <p>If the XML API restricts comments from having two consecutive
7335: U+002D HYPHEN-MINUS characters (--), the tool may insert a single
7336: U+0020 SPACE character between any such offending characters.</p>
7337:
7338: <p>If the XML API restricts comments from ending in a
7339: U+002D HYPHEN-MINUS character (-), the tool may insert a single
7340: U+0020 SPACE character at the end of such comments.</p>
7341:
7342: <p>If the XML API restricts allowed characters in character data,
1.439 mike 7343: attribute values, or comments, the tool may replace any U+000C FORM
7344: FEED (FF) character with a U+0020 SPACE character, and any other
7345: literal non-XML character with a U+FFFD REPLACEMENT CHARACTER.</p>
1.1 mike 7346:
7347: <p>If the tool has no way to convey out-of-band information, then
7348: the tool may drop the following information:</p>
7349:
7350: <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
7351: <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>
7352:
7353: <li>The association between form controls and forms that aren't
7354: their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
7355: <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
7356:
7357: </ul><p class="note">The mutations allowed by this section apply
7358: <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
7359: applied. For example, a <code title=""><a::></code> start tag
7360: will be closed by a <code title=""></a::></code> end tag, and
7361: never by a <code title=""></aU00003AU00003A></code> end tag, even
7362: if the user agent is using the rules above to then generate an
7363: actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
7364:
1.266 mike 7365: </div><div class="impl">
1.1 mike 7366:
1.35 mike 7367: <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 7368:
7369: <p><i>This section is non-normative.</i></p>
7370:
7371: <p>This section examines some erroneous markup and discusses how
7372: the <a href="#html-parser">HTML parser</a> handles these cases.</p>
7373:
7374:
7375: <h5 id="misnested-tags:-b-i-b-i"><span class="secno">9.2.8.1 </span>Misnested tags: <b><i></b></i></h5>
7376:
7377: <p><i>This section is non-normative.</i></p>
7378:
7379: <p>The most-often discussed example of erroneous markup is as
7380: follows:</p>
7381:
7382: <pre><p>1<b>2<i>3</b>4</i>5</p></pre>
7383:
7384: <p>The parsing of this markup is straightforward up to the "3". At
7385: this point, the DOM looks like this:</p>
7386:
1.159 mike 7387: <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
7388: 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 7389: <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
7390: formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
7391: <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>
7392:
7393: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
7394: invoked. This is a simple case, in that the <var title="">formatting
7395: element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
7396: <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
1.159 mike 7397: elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element-0">html</a></code>,
7398: <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 7399: active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
7400: DOM tree is unmodified at this point.</p>
7401:
7402: <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
7403: the active formatting elements</a>, in this case just the
7404: <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
7405: for the "4" text node. After the end tag token for the "i" is also
7406: received, and the "5" text node is inserted, the DOM looks as
7407: follows:</p>
7408:
1.159 mike 7409: <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 7410:
7411: <p><i>This section is non-normative.</i></p>
7412:
7413: <p>A case similar to the previous one is the following:</p>
7414:
7415: <pre><b>1<p>2</b>3</p></pre>
7416:
7417: <p>Up to the "2" the parsing here is straightforward:</p>
7418:
1.159 mike 7419: <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 7420: "b" is parsed.</p>
7421:
7422: <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
1.159 mike 7423: elements</a> has four elements on it: <code><a href="semantics.html#the-html-element-0">html</a></code>,
7424: <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 7425: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
7426: <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>
7427:
7428: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
7429: in the previous example. However, in this case, there <em>is</em> a
7430: <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
7431: this time the adoption agency algorithm isn't skipped over.</p>
7432:
1.159 mike 7433: <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 7434: element. A conceptual "bookmark" marks the position of the
7435: <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
7436: elements</a>, but since that list has only one element in it,
7437: it won't have much effect.</p>
7438:
7439: <p>As the algorithm progresses, <var title="">node</var> ends up set
7440: to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
7441: node</var> ends up set to the <var title="">furthest block</var>
7442: (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
7443:
7444: <p>The <var title="">last node</var> gets appended (moved) to the
7445: <var title="">common ancestor</var>, so that the DOM looks like:</p>
7446:
1.159 mike 7447: <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 7448: <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
7449:
1.159 mike 7450: <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 7451: <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
7452:
1.159 mike 7453: <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 7454: active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
7455: elements</a>, so that when the "3" is parsed, it is appended to
7456: the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
7457:
1.159 mike 7458: <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 7459:
7460: <p><i>This section is non-normative.</i></p>
7461:
7462: <p>Error handling in tables is, for historical reasons, especially
7463: strange. For example, consider the following markup:</p>
7464:
7465: <pre><table><strong><b></strong><tr><td>aaa</td></tr><strong>bbb</strong></table>ccc</pre>
7466:
7467: <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
7468: directly inside a table like that, and the parser handles this case
7469: 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
7470: examining the DOM tree as it stands just after the
7471: <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
7472:
1.159 mike 7473: <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 7474: tag has been seen:</p>
7475:
1.159 mike 7476: <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
7477: 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 7478: <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
7479: resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
7480: elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
7481: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
7482: table">in table</a>".</p>
7483:
7484: <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
7485: to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
7486: 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
7487: then handled in a rather straight-forward manner, taking the parser
7488: through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
7489: body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
7490: row</a>" insertion modes, after which the DOM looks as
7491: follows:</p>
7492:
1.159 mike 7493: <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
7494: 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 7495: <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
7496: formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
7497: it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
7498: mode: in row">in row</a>".</p>
7499:
7500: <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
7501: <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
7502: 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
7503: mode</a>).</p>
7504:
1.159 mike 7505: <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 7506: no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
7507: node:</p>
7508:
1.159 mike 7509: <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 7510: handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
1.159 mike 7511: 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 7512: 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
7513: elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
7514: marker having been removed by the "td" end tag token); and the
7515: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
7516: table body">in table body</a>".</p>
7517:
7518: <p>Thus it is that the "bbb" character tokens are found. These
7519: trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
7520: text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
7521: insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
7522: body">in table body</a>"). The character tokens are collected,
7523: and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
7524: seen, they are processed as a group. Since they are not all spaces,
7525: 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,
7526: which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
7527: body</a>" insertion mode but with <a href="#foster-parent" title="foster
7528: parent">foster parenting</a>.</p>
7529:
7530: <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
7531: active formatting elements are reconstructed</a>, a
7532: <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
7533: parent">foster parented</a>, and then the "bbb" text node is
7534: appended to it:</p>
7535:
1.159 mike 7536: <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
7537: <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 7538: <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
7539: this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
7540: formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
7541: and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
7542: mode: in table body">in table body</a>".</p>
7543:
7544: <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
7545: character">space characters</a> instead of "bbb", then those
7546: <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
7547: appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
7548:
7549: <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
7550: tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
7551: elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
7552: but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
7553: elements</a>, so the "ccc" character tokens after the table
7554: result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
7555: time after the table:</p>
7556:
1.159 mike 7557: <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 7558:
7559: <p><i>This section is non-normative.</i></p>
7560:
7561: <p>Consider the following markup, which for this example we will
7562: 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 7563: content of an <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code> in another document with the
1.1 mike 7564: <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
7565:
7566: <pre><div id=a>
7567: <script>
7568: var div = document.getElementById('a');
7569: parent.document.body.appendChild(div);
7570: </script>
7571: <script>
7572: alert(document.URL);
7573: </script>
7574: </div>
7575: <script>
7576: alert(document.URL);
7577: </script></pre>
7578:
7579: <p>Up to the first "script" end tag, before the script is parsed,
7580: the result is relatively straightforward:</p>
7581:
1.306 mike 7582: <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="">
7583: </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 7584: and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
7585:
1.159 mike 7586: <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 7587: aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
7588: <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
1.306 mike 7589: <code><a href="semantics.html#the-div-element">div</a></code> element</em>.</p>
1.1 mike 7590:
7591: <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
7592: is inserted <em>into the outer <code>Document</code>
7593: object</em>.</p>
7594:
7595: <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
7596: the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
7597: object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
1.159 mike 7598: <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>.</p>
1.1 mike 7599:
7600: <p class="note">This isn't a security problem since the script that
1.306 mike 7601: moves the <code><a href="semantics.html#the-div-element">div</a></code> into the outer <code>Document</code> can
1.1 mike 7602: only do so because they have the two <code>Document</code> object
1.159 mike 7603: have the same <a href="browsers.html#origin">origin</a>.</p>
1.1 mike 7604:
7605: <p>Thus, the first alert says "http://example.com/outer".</p>
7606:
1.306 mike 7607: <p>Once the <code><a href="semantics.html#the-div-element">div</a></code> element's end tag is parsed, the
7608: <code><a href="semantics.html#the-div-element">div</a></code> element is popped off the stack, and so the next
1.1 mike 7609: <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
7610:
1.159 mike 7611: <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 7612:
7613:
7614:
1.215 mike 7615: <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3>
1.1 mike 7616:
7617: <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
7618:
7619: <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
7620:
7621: <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
7622:
7623: <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
7624:
7625: <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
7626:
7627: <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
7628:
7629: <hr><p>Data mining tools and other user agents that perform operations
1.83 mike 7630: on <code><a href="iana-considerations.html#text-html">text/html</a></code> content without running scripts,
1.1 mike 7631: evaluating CSS or XPath expressions, or otherwise exposing the
7632: resulting DOM to arbitrary content, may "support namespaces" by just
7633: asserting that their DOM node analogues are in certain namespaces,
7634: without actually exposing the above strings.</p>
7635:
7636:
7637:
7638:
7639: <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3>
7640:
7641: <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
7642: algorithm</dfn>. The algorithm takes as input a DOM
7643: <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
7644: exception.</p>
7645:
7646: <p class="note">This algorithm serializes the <em>children</em> of
7647: the node being serialized, not the node itself.</p>
7648:
7649: <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
7650: the empty string.</p></li>
7651:
7652: <li>
7653:
7654: <p>For each child node of <var title="">the node</var>, in
7655: <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
7656:
7657: </p><ol><li><p>Let <var title="">current node</var> be the child node
7658: being processed.</p></li>
7659:
7660: <li>
7661:
7662: <p>Append the appropriate string from the following list to
7663: <var title="">s</var>:</p>
7664:
7665: <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
7666:
7667: <dd>
7668:
7669: <p>Append a U+003C LESS-THAN SIGN (<code title=""><</code>)
7670: character, followed by the element's tag name. (For nodes
7671: created by the <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
7672: lowercase.)</p>
7673:
7674: <p>For each attribute that the element has, append a U+0020
7675: SPACE character, the attribute's name (which, for attributes
7676: 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
7677: U+003D EQUALS SIGN (<code title="">=</code>) character, a
7678: U+0022 QUOTATION MARK (<code title="">"</code>)
7679: character, the attribute's value, <a href="#escapingString" title="escaping a
7680: string">escaped as described below</a> in <i>attribute
7681: mode</i>, and a second U+0022 QUOTATION MARK (<code title="">"</code>) character.</p>
7682:
7683: <p>While the exact order of attributes is UA-defined, and may
7684: depend on factors such as the order that the attributes were
7685: given in the original markup, the sort order must be stable,
7686: such that consecutive invocations of this algorithm serialize an
7687: element's attributes in the same order.</p>
7688:
7689: <p>Append a U+003E GREATER-THAN SIGN (<code title="">></code>)
7690: character.</p>
7691:
7692: <p>If <var title="">current node</var> is an
1.5 mike 7693: <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 7694: <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 7695: <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>,
7696: <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>,
7697: <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 7698: <code><a href="obsolete.html#spacer">spacer</a></code>, or <code>wbr</code> element, then
1.1 mike 7699: continue on to the next child node at this point.</p> <!--
7700: also, i guess: image and isindex, but we don't list those
7701: because we don't consider those "elements", more "macros", and
7702: thus we should never serialize them -->
7703:
7704: <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42 mike 7705: <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 7706: a U+000A LINE FEED (LF) character.</p>
7707:
7708: <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
7709: serialization algorithm</a> on the <var title="">current
7710: node</var> element (thus recursing into this algorithm for
7711: 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,
7712: and finally a U+003E GREATER-THAN SIGN (<code title="">></code>) character.</p>
7713:
7714: </dd>
7715:
7716:
7717: <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
7718: node</dt>
7719:
7720: <dd>
7721:
1.19 mike 7722: <p>If the parent of <var title="">current node</var> is a
1.42 mike 7723: <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 7724: <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 7725: <code><a href="obsolete.html#noframes">noframes</a></code>, or <code><a href="obsolete.html#plaintext">plaintext</a></code> element, or
7726: if the parent of <var title="">current node</var> is
7727: <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
7728: node, then append the value of <var title="">current
7729: node</var>'s <code title="">data</code> IDL attribute
7730: literally.</p>
1.1 mike 7731:
7732: <p>Otherwise, append the value of <var title="">current
1.192 mike 7733: node</var>'s <code title="">data</code> IDL attribute, <a href="#escapingString" title="escaping a string">escaped as described
1.1 mike 7734: below</a>.</p>
7735:
7736: </dd>
7737:
7738:
7739: <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
7740:
7741: <dd>
7742:
7743: <p>Append the literal string <code><!--</code> (U+003C
7744: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
1.192 mike 7745: U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1 mike 7746: attribute, followed by the literal string <code>--></code>
7747: (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
7748: SIGN).</p>
7749:
7750: </dd>
7751:
7752:
7753: <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
7754:
7755: <dd>
7756:
7757: <p>Append the literal string <code><?</code> (U+003C
7758: LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
1.192 mike 7759: of <var title="">current node</var>'s <code title="">target</code> IDL attribute, followed by a single
7760: U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1 mike 7761: attribute, followed by a single U+003E GREATER-THAN SIGN
1.464 mike 7762: character (>).</p>
1.1 mike 7763:
7764: </dd>
7765:
7766:
7767: <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
7768:
7769: <dd>
7770:
7771: <p>Append the literal string <code><!DOCTYPE</code> (U+003C
7772: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
7773: LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
7774: LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
7775: LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
7776: LETTER E), followed by a space (U+0020 SPACE), followed by the
1.192 mike 7777: value of <var title="">current node</var>'s <code title="">name</code> IDL attribute, followed by the literal
1.1 mike 7778: string <code>></code> (U+003E GREATER-THAN SIGN).</p>
7779:
7780: </dd>
7781:
7782:
7783: </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
7784: occur as children of elements. If, despite this, they somehow do
7785: occur, this algorithm must raise an
7786: <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
7787:
7788: </li>
7789:
7790: </ol></li>
7791:
7792: <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
7793:
7794: </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
7795: purposes of the algorithm above) consists of replacing any
7796: occurrences of the "<code title="">&</code>" character by the
7797: string "<code title="">&amp;</code>", any occurrences of the
7798: U+00A0 NO-BREAK SPACE character by the string "<code title="">&nbsp;</code>", and, if the algorithm was invoked in
7799: 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
7800: 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>
7801:
7802: <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
7803: agent, and are therefore not covered in the algorithm above.</p>
7804:
7805: <p class="note">It is possible that the output of this algorithm, if
7806: parsed with an <a href="#html-parser">HTML parser</a>, will not return the
7807: original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
7808: element to which a <code title="">Comment</code> node has been
7809: appended is serialized and the output is then reparsed, the comment
7810: will end up being displayed in the text field. Similarly, if, as a
7811: result of DOM manipulation, an element contains a comment that
7812: contains the literal string "<code title="">--></code>", then
7813: when the result of serializing the element is parsed, the comment
7814: will be truncated at that point and the rest of the comment will be
7815: interpreted as markup. More examples would be making a
7816: <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
7817: "<code></script></code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
7818: 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
7819: <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
7820: tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
7821:
7822:
7823: <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3>
7824:
7825: <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
7826: algorithm</dfn>. The algorithm optionally takes as input an
7827: <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
7828: parser, as well as <var title="">input</var>, a string to parse, and
7829: returns a list of zero or more nodes.</p>
7830:
7831: <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
7832: in the parser section are parts that only occur if the parser was
7833: created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
7834: with such markings for informational purposes only; such markings
7835: have no normative weight. If it is possible for a condition
7836: described as a <a href="#fragment-case">fragment case</a> to occur even when the
7837: parser wasn't created for the purposes of handling this algorithm,
7838: then that is an error in the specification.</p>
7839:
7840: <ol><li>
7841:
7842: <p>Create a new <code>Document</code> node, and mark it as being
7843: an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
7844:
7845: </li>
7846:
7847: <li>
7848:
7849: <p>If there is a <var title="">context</var> element, and the
7850: <code>Document</code> of the <var title="">context</var> element
7851: is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
7852: 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
7853: the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
7854: mode</a>, then let the <code>Document</code> be in
7855: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
7856: <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
7857:
7858: </li>
7859:
7860: <li>
7861:
7862: <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
7863: the just created <code>Document</code> node.</p>
7864:
7865: </li>
7866:
7867: <li>
7868:
7869: <p>If there is a <var title="">context</var> element, run these
7870: substeps:</p>
7871:
7872: <ol><li>
7873:
7874: <p>Set the <a href="#html-parser">HTML parser</a>'s <a href="#tokenization">tokenization</a>
7875: stage's <a href="#content-model-flag">content model flag</a> according to the <var title="">context</var> element, as follows:</p>
7876:
1.159 mike 7877: <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 7878: element</dt>
7879:
7880: <dd>Set the <a href="#content-model-flag">content model flag</a> to
7881: the RCDATA state.</dd>
7882:
7883:
7884: <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 7885: <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 7886: <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1 mike 7887:
7888: <dd>Set the <a href="#content-model-flag">content model flag</a> to
1.91 mike 7889: the RAWTEXT state.</dd>
1.1 mike 7890:
7891:
7892: <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
7893:
7894: <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, set the
1.91 mike 7895: <a href="#content-model-flag">content model flag</a> to the RAWTEXT
1.1 mike 7896: state. Otherwise, set the <a href="#content-model-flag">content model flag</a> to the
7897: PCDATA state.</dd>
7898:
7899:
1.42 mike 7900: <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1 mike 7901:
7902: <dd>Set the <a href="#content-model-flag">content model flag</a> to
7903: PLAINTEXT.</dd>
7904:
7905:
7906: <dt>Otherwise</dt>
7907:
7908: <dd>Leave the <a href="#content-model-flag">content model flag</a> in the PCDATA
7909: state.</dd>
7910:
7911: </dl></li>
7912:
7913: <li>
7914:
1.159 mike 7915: <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 7916: with no attributes.</p>
7917:
7918: </li>
7919:
7920: <li>
7921:
7922: <p>Append the element <var title="">root</var> to the
7923: <code>Document</code> node created above.</p>
7924:
7925: </li>
7926:
7927: <li>
7928:
7929: <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
7930: it contains just the single element <var title="">root</var>.</p>
7931:
7932: </li>
7933:
7934: <li>
7935:
7936: <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
7937: parser's insertion mode appropriately</a>.</p>
7938:
7939: <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
7940:
7941: </li>
7942:
7943: <li>
7944:
7945: <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
7946: to the nearest node to the <var title="">context</var> element
7947: that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
7948: ancestor chain, and including the element itself, if it is a
7949: <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
7950: <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
7951:
7952: </li>
7953:
7954: </ol></li>
7955:
7956: <li>
7957:
7958: <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
7959: parser</a> just created the <var title="">input</var>. The
7960: encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
7961: <i>irrelevant</i>.</p>
7962:
7963: </li>
7964:
7965: <li>
7966:
7967: <p>Start the parser and let it run until it has consumed all the
7968: characters just inserted into the input stream.</p>
7969:
7970: </li>
7971:
7972: <li>
7973:
7974: <p>If there is a <var title="">context</var> element, return the
7975: child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
7976: order</a>.</p>
7977:
7978: <p>Otherwise, return the children of the <code>Document</code>
7979: object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
7980:
7981: </li>
7982:
1.123 mike 7983: </ol></div></body></html>
Webmaster