Annotation of html5/spec/syntax.html, revision 1.460
1.2 mike 1: <!DOCTYPE HTML>
1.258 mike 2: <!-- when publishing, change bits marked ZZZ --><html lang="en-US-x-Hixie"><head><title>9 The HTML syntax — HTML 5</title><style type="text/css">
1.1 mike 3: pre { margin-left: 2em; white-space: pre-wrap; }
4: h2 { margin: 3em 0 1em 0; }
5: h3 { margin: 2.5em 0 1em 0; }
6: h4 { margin: 2.5em 0 0.75em 0; }
7: h5, h6 { margin: 2.5em 0 1em; }
8: h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
9: h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
10: p { margin: 1em 0; }
11: hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
12: dl, dd { margin-top: 0; margin-bottom: 0; }
13: dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
14: dt + dt { margin-top: 0; }
15: dd dt { margin-top: 0.25em; margin-bottom: 0; }
16: dd p { margin-top: 0; }
17: dd dl + p { margin-top: 1em; }
18: dd table + p { margin-top: 1em; }
19: p + * > li, dd li { margin: 1em 0; }
20: dt, dfn { font-weight: bold; font-style: normal; }
21: dt dfn { font-style: italic; }
22: pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
23: pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
24: pre em { font-weight: bolder; font-style: normal; }
25: @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
26: var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
27: table { border-collapse: collapse; border-style: hidden hidden none hidden; }
28: table thead { border-bottom: solid; }
29: table tbody th:first-child { border-left: solid; }
30: table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
31: blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
32:
33: .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
34: .matrix, .matrix td { border: none; text-align: right; }
35: .matrix { margin-left: 2em; }
36: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
37: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
38: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
39:
40: .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
41: img.extra { float: right; }
42: pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
43: pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
44: pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
45: pre.css:first-line { color: #AAAA50; }
46: dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #EEFFEE; }
47: hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
48: dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
49: dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
50: dl.domintro dd p { margin: 0.5em 0; }
51: dl.switch { padding-left: 2em; }
52: dl.switch > dt { text-indent: -1.5em; }
53: dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
54: dl.triple { padding: 0 0 0 1em; }
55: dl.triple dt, dl.triple dd { margin: 0; display: inline }
56: dl.triple dt:after { content: ':'; }
57: dl.triple dd:after { content: '\A'; white-space: pre; }
58: .diff-old { text-decoration: line-through; color: silver; background: transparent; }
59: .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
60: a .diff-new { border-bottom: 1px blue solid; }
61:
62: h2 { page-break-before: always; }
63: h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
64: h1 + h2, hr + h2.no-toc { page-break-before: auto; }
65:
66: p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
67:
68: div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
69: div.head p { margin: 0; }
70: div.head h1 { margin: 0; }
71: div.head .logo { float: right; margin: 0 1em; }
72: div.head .logo img { border: none } /* remove border from top image */
73: div.head dl { margin: 1em 0; }
74: p.copyright { font-size: x-small; font-style: oblique; margin: 0; }
75:
76: body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
77: body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
78: body > .toc > li > * { margin-bottom: 0.5em; }
79: body > .toc > li > * > li > * { margin-bottom: 0.25em; }
80: .toc, .toc li { list-style: none; }
81:
82: .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
83: .brief li { margin: 0; padding: 0; }
84: .brief li p { margin: 0; padding: 0; }
85:
86: .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
87: .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
88: .category-list li { display: inline; }
89: .category-list li:not(:last-child)::after { content: ', '; }
90: .category-list li > span, .category-list li > a { text-transform: lowercase; }
91: .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
92:
93: .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
94: .XXX > :first-child { margin-top: 0; }
95: p .XXX { line-height: 3em; }
1.159 mike 96: .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
97: .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
98: .annotation :link, .annotation :visited { color: inherit; }
99: .annotation :link:hover, .annotation :visited:hover { background: transparent; }
100: .annotation span { border: none ! important; }
1.1 mike 101: .note { color: green; background: transparent; font-family: sans-serif; }
102: .warning { color: red; background: transparent; }
103: .note, .warning { font-weight: bolder; font-style: italic; }
104: p.note, div.note { padding: 0.5em 2em; }
105: span.note { padding: 0 2em; }
106: .note p:first-child, .warning p:first-child { margin-top: 0; }
107: .note p:last-child, .warning p:last-child { margin-bottom: 0; }
108: .warning:before { font-style: normal; }
109: p.note:before { content: 'Note: '; }
110: p.warning:before { content: '\26A0 Warning! '; }
111:
112: .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
113: .bookkeeping { font-size: 0.8em; margin: 2em 0; }
114: .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
115:
116: h4 { position: relative; z-index: 3; }
117: h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
118: .element {
119: background: #EEEEFF;
120: color: black;
121: margin: 0 0 1em 0.15em;
122: padding: 0 1em 0.25em 0.75em;
123: border-left: solid #9999FF 0.25em;
124: position: relative;
125: z-index: 1;
126: }
127: .element:before {
128: position: absolute;
129: z-index: 2;
130: top: 0;
131: left: -1.15em;
132: height: 2em;
133: width: 0.9em;
134: background: #EEEEFF;
135: content: ' ';
136: border-style: none none solid solid;
137: border-color: #9999FF;
138: border-width: 0.25em;
139: }
140:
1.149 mike 141: .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
142: td > .example:only-child { margin: 0 0 0 0.1em; }
1.1 mike 143:
144: .tall-and-narrow {
145: font-size: 0.6em;
146: column-width: 25em;
147: column-gap: 1em;
148: -moz-column-width: 25em;
149: -moz-column-gap: 1em;
150: -webkit-column-width: 25em;
151: -webkit-column-gap: 1em;
152: }
153:
154: ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
155: ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
156: ul.domTree li li { list-style: none; }
157: ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
158: ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
159: ul.domTree span { font-style: italic; font-family: serif; }
160: ul.domTree .t1 code { color: purple; font-weight: bold; }
161: ul.domTree .t2 { font-style: normal; font-family: monospace; }
162: ul.domTree .t2 .name { color: black; font-weight: bold; }
163: ul.domTree .t2 .value { color: blue; font-weight: normal; }
164: ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
165: ul.domTree .t7 code, .domTree .t8 code { color: green; }
166: ul.domTree .t10 code { color: teal; }
167:
1.267 mike 168: </style><style type="text/css">
169:
1.292 mike 170: .applies thead th > * { display: block; }
171: .applies thead code { display: block; }
172: .applies tbody th { whitespace: nowrap; }
173: .applies td { text-align: center; }
174: .applies .yes { background: yellow; }
175:
1.267 mike 176: .matrix, .matrix td { border: none; text-align: right; }
177: .matrix { margin-left: 2em; }
178:
179: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
180: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
181: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
182:
183: #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
184: #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
185: #table-example-1 caption { padding-bottom: 0.5em; }
186: #table-example-1 thead, #table-example-1 tbody { border: none; }
187: #table-example-1 th, #table-example-1 td { border: solid thin; }
188: #table-example-1 th { font-weight: normal; }
189: #table-example-1 td { border-style: none solid; vertical-align: top; }
190: #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
191: #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
192: #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
193: #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
194: #table-example-1 tbody td:first-child::after { content: leader(". "); }
195: #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
196: #table-example-1 tbody td:first-child + td { width: 10em; }
197: #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
198: #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
199:
200: .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
201: .apple-table-examples * { font-family: "Times", serif; }
202: .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
203: .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
204: .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
205: .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
206: .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
207: .apple-table-examples td { text-align: right; vertical-align: top; }
208: .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
209: .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
210: .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
211: .apple-table-examples sup { line-height: 0; }
212:
1.235 mike 213: </style><link href="data:text/css," rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D" rel="alternate stylesheet" title="Highlight implementation requirements"><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css"><!-- ZZZ ED vs WD -->
1.2 mike 214: <script src="link-fixup.js"></script>
215: <link href="comms.html" title="8 Communication" rel="prev">
216: <link href="spec.html#contents" title="Table of contents" rel="index">
1.1 mike 217: <link href="named-character-references.html" title="9.6 Named character references" rel="next">
1.16 mike 218: </head><body onload="fixBrokenLink(); fixBrokenLink()"><div class="head">
1.1 mike 219: <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
1.183 mike 220: <h1>HTML5</h1>
1.1 mike 221: <h2 class="no-num no-toc" id="a-vocabulary-and-associated-apis-for-html-and-xhtml">A vocabulary and associated APIs for HTML and XHTML</h2>
1.123 mike 222: </div><nav>
1.1 mike 223: <a href="comms.html">← 8 Communication</a> –
1.2 mike 224: <a href="spec.html#contents">Table of contents</a> –
1.1 mike 225: <a href="named-character-references.html">9.6 Named character references →</a>
1.460 ! mike 226: </nav><p>This is revision 1.3234.</p>
1.11 mike 227:
1.1 mike 228:
1.123 mike 229: <h2 id="syntax"><span class="secno">9 </span><dfn>The HTML syntax</dfn></h2><p class="note">This section only describes the rules for
1.83 mike 230: <code><a href="iana-considerations.html#text-html">text/html</a></code> resources. Rules for XML resources are
1.1 mike 231: discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.159 mike 232: syntax</a>".</p><h3 id="writing"><span class="secno">9.1 </span>Writing HTML documents</h3><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p><div class="impl">
1.1 mike 233:
234: <p><i>This section only applies to documents, authoring tools, and
235: markup generators. In particular, it does not apply to conformance
236: checkers; conformance checkers must use the requirements given in
237: the next section ("parsing HTML documents").</i></p>
238:
1.123 mike 239: </div><p>Documents must consist of the following parts, in the given
240: order:</p><ol><li>Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.</li>
1.1 mike 241:
242: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
243: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
244:
245: <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
246:
247: </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
248: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
249:
1.159 mike 250: <li>The root element, in the form of an <code><a href="semantics.html#the-html-element-0">html</a></code> <a href="#syntax-elements" title="syntax-elements">element</a>.</li>
1.1 mike 251:
252: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
253: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
254:
255: </ol><p>The various types of content mentioned above are described in the
1.123 mike 256: next few sections.</p><p>In addition, there are some restrictions on how <a href="semantics.html#character-encoding-declaration" title="character encoding declaration">character encoding
1.1 mike 257: declarations</a> are to be serialized, as discussed in the
1.123 mike 258: section on that topic.</p><div class="note">
1.1 mike 259:
1.159 mike 260: <p>Space characters before the root <code><a href="semantics.html#the-html-element-0">html</a></code> element, and
261: space characters at the start of the <code><a href="semantics.html#the-html-element-0">html</a></code> element and
262: before the <code><a href="semantics.html#the-head-element-0">head</a></code> element, will be dropped when the
1.1 mike 263: document is parsed; space characters <em>after</em> the root
1.159 mike 264: <code><a href="semantics.html#the-html-element-0">html</a></code> element will be parsed as if they were at the end
265: of the <code><a href="semantics.html#the-body-element-0">body</a></code> element. Thus, space characters around the
1.1 mike 266: root element do not round-trip.</p>
267:
268: <p>It is suggested that newlines be inserted after the DOCTYPE,
269: after any comments that are before the root element, after the
1.159 mike 270: <code><a href="semantics.html#the-html-element-0">html</a></code> element's start tag (if it is not <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>), and after any comments
271: that are inside the <code><a href="semantics.html#the-html-element-0">html</a></code> element but before the
272: <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 273:
1.123 mike 274: </div><p>Many strings in the HTML syntax (e.g. the names of elements and
1.1 mike 275: their attributes) are case-insensitive, but only for characters in
276: the ranges U+0041 .. U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
277: LETTER Z) and U+0061 .. U+007A (LATIN SMALL LETTER A to LATIN SMALL
278: LETTER Z). For convenience, in this section this is just referred to
1.168 mike 279: as "case-insensitive".</p><h4 id="the-doctype"><span class="secno">9.1.1 </span>The DOCTYPE</h4><p class="XXX annotation"><span><a href="http://www.w3.org/html/wg/tracker/issues/4">ISSUE-4</a> (html-versioning) blocks progress to Last Call</span></p><p>A <dfn id="syntax-doctype" title="syntax-doctype">DOCTYPE</dfn> is a mostly useless,
1.123 mike 280: but required, header.</p><p class="note">DOCTYPEs are required for legacy reasons. When
1.1 mike 281: omitted, browsers tend to use a different rendering mode that is
282: incompatible with some specifications. Including the DOCTYPE in a
283: document ensures that the browser makes a best-effort attempt at
1.123 mike 284: following the relevant specifications.</p><p>A DOCTYPE must consist of the following characters, in this
285: order:</p><ol class="brief"><li>A U+003C LESS-THAN SIGN (<code><</code>) character.</li>
1.1 mike 286: <li>A U+0021 EXCLAMATION MARK (<code>!</code>) character.</li>
287: <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">DOCTYPE</code>".</li>
288: <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
289: <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">HTML</code>".</li>
290: <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> (defined below).</li>
291: <li>Zero or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
292: <li>A U+003E GREATER-THAN SIGN (<code>></code>) character.</li>
293: </ol><p class="note">In other words, <code><!DOCTYPE HTML></code>,
1.123 mike 294: case-insensitively.</p><p>For the purposes of HTML generators that cannot output HTML
1.1 mike 295: markup with the short DOCTYPE "<code title=""><!DOCTYPE
296: HTML></code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
297: into the DOCTYPE (in the position defined above). This string must
1.123 mike 298: consist of:</p><ol class="brief"><li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.1 mike 299: <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">SYSTEM</code>".</li>
1.444 mike 300: <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.1 mike 301: <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
302: <li>The literal string "<code title="">about:legacy-compat</code>".</li>
303: <li>A matching U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (i.e. the same character as in the earlier step marked <i>quote mark</i>).</li>
304: </ol><p class="note">In other words, <code><!DOCTYPE HTML SYSTEM
305: "about:legacy-compat"></code> or <code><!DOCTYPE HTML SYSTEM
306: 'about:legacy-compat'></code>, case-insensitively except for the bit
1.123 mike 307: in quotes.</p><p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1 mike 308: the document is generated from a system that cannot output the
1.373 mike 309: shorter string.</p><h4 id="elements-0"><span class="secno">9.1.2 </span>Elements</h4><p>There are five different kinds of <dfn id="syntax-elements" title="syntax-elements">elements</dfn>: <a href="#void-elements">void elements</a>,
310: <a href="#raw-text-elements">raw text elements</a>, <a href="#rcdata-elements">RCDATA elements</a>,
311: <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 312:
313: <dd><code><a href="the-canvas-element.html#the-area-element">area</a></code>, <code><a href="semantics.html#the-base-element">base</a></code>, <code><a href="semantics.html#the-br-element">br</a></code>,
1.159 mike 314: <code><a href="tabular-data.html#the-col-element">col</a></code>, <code><a href="interactive-elements.html#the-command">command</a></code>, <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>,
315: <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="text-level-semantics.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>,
1.1 mike 316: <code><a href="forms.html#the-keygen-element">keygen</a></code>, <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#meta">meta</a></code>,
1.159 mike 317: <code><a href="text-level-semantics.html#the-param-element">param</a></code>, <code><a href="video.html#the-source-element">source</a></code></dd>
1.1 mike 318:
1.373 mike 319: <dt><dfn id="raw-text-elements">Raw text elements</dfn></dt>
1.1 mike 320:
321: <dd><code><a href="semantics.html#script">script</a></code>, <code><a href="semantics.html#the-style-element">style</a></code></dd> <!-- iframe and
1.91 mike 322: noscript don't count as raw text for syntax purposes -->
1.1 mike 323:
1.373 mike 324: <dt><dfn id="rcdata-elements">RCDATA elements</dfn></dt>
1.1 mike 325:
1.159 mike 326: <dd><code><a href="forms.html#the-textarea-element">textarea</a></code>, <code><a href="semantics.html#the-title-element-0">title</a></code></dd>
1.1 mike 327:
1.373 mike 328: <dt><dfn id="foreign-elements">Foreign elements</dfn></dt>
1.1 mike 329:
330: <dd>Elements from the <a href="#mathml-namespace">MathML namespace</a>
331: and the <a href="#svg-namespace">SVG namespace</a>.</dd>
332:
1.373 mike 333: <dt><dfn id="normal-elements">Normal elements</dfn></dt>
1.1 mike 334:
335: <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
336: elements.</dd>
337:
338: </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.373 mike 339: and end of elements in the markup. <a href="#raw-text-elements" title="raw text
340: elements">Raw text</a>, <a href="#rcdata-elements" title="RCDATA
341: elements">RCDATA</a>, and <a href="#normal-elements" title="normal
342: elements">normal</a> elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to indicate where they
343: begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> to
344: indicate where they end. The start and end tags of certain
345: <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 346: later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
347: elements</a> only have a start tag; end tags must not be
1.373 mike 348: specified for <a href="#void-elements">void elements</a>. <a href="#foreign-elements">Foreign
349: elements</a> must either have a start tag and an end tag, or a
350: start tag that is marked as self-closing, in which case they must
351: not have an end tag.</p><p>The contents of the element must be placed between just after the
1.1 mike 352: start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
353: in certain cases</a>) and just before the end tag (which again,
354: <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
355: cases</a>). The exact allowed contents of each individual element
356: depends on the content model of that element, as described earlier
357: in this specification. Elements must not contain content that their
358: content model disallows. In addition to the restrictions placed on
359: the contents by those content models, however, the five types of
1.123 mike 360: 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 361: no end tag, no content can be put between the start tag and the end
1.373 mike 362: 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
363: 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
364: must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
1.1 mike 365: There are also <a href="#cdata-rcdata-restrictions">further
1.373 mike 366: restrictions</a> described below.</p><p><a href="#foreign-elements">Foreign elements</a> whose start tag is marked as
367: self-closing can't have any contents (since, again, as there's no
368: end tag, no content can be put between the start tag and the end
369: tag). <a href="#foreign-elements">Foreign elements</a> whose start tag is <em>not</em>
370: 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 371: contain the character U+003C LESS-THAN SIGN (<code><</code>) or
372: an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.374 mike 373: ampersand</a>.</p><div class="note">
374:
375: <p>The HTML syntax does not support namespace
376: declarations, even in <a href="#foreign-elements">foreign elements</a>.</p>
377:
378: <p>For instance, consider the following HTML fragment:</p>
379:
380: <pre><p>
381: <svg>
382: <metadata>
383: <!-- this is invalid -->
384: <cdr:license xmlns:cdr="http://www.example.com/cdr/metadata" name="MIT"/>
385: </metadata>
386: </svg>
387: </p></pre>
388:
389: <p>The innermost element, <code title="">cdr:license</code>, is
390: actually in the SVG namespace, as the "<code title="">xmlns:cdr</code>" attribute has no effect (unlike in
391: XML). In fact, as the comment in the fragment above says, the
392: fragment is actually non-conforming. This is because the SVG
393: specification does not define any elements called "<code title="">cdr:license</code>" in the SVG namespace.</p>
394:
395: </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 396: contain the character U+003C LESS-THAN SIGN (<code><</code>) or
397: an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.373 mike 398: 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 399: content they are allowed to hold, beyond the restrictions imposed by
400: the content model and those described in this paragraph. Those
1.123 mike 401: restrictions are described below.</p><p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1 mike 402: giving the element's name. HTML elements all have names that only
403: use characters in the range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE,
1.202 mike 404: U+0061 LATIN SMALL LETTER A .. U+007A LATIN SMALL LETTER Z, and
405: U+0041 LATIN CAPITAL LETTER A .. U+005A LATIN CAPITAL LETTER Z. In
406: the HTML syntax, tag names may be written with any mix of lower- and
407: uppercase letters that, when converted to all-lowercase, matches the
408: element's tag name; tag names are case-insensitive.</p><h5 id="start-tags"><span class="secno">9.1.2.1 </span>Start tags</h5><p><dfn id="syntax-start-tag" title="syntax-start-tag">Start tags</dfn> must have the
1.123 mike 409: following format:</p><ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.1 mike 410: SIGN (<code><</code>).</li>
411:
412: <li>The next few characters of a start tag must be the element's
413: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
414:
415: <li>If there are to be any attributes in the next step, there must
416: first be one or more <a href="infrastructure.html#space-character" title="space character">space
417: characters</a>.</li>
418:
419: <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
420: below. Attributes may be separated from each other by one or more
421: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
422:
423: <li>After the attributes, there may be one or more <a href="infrastructure.html#space-character" title="space character">space characters</a>. (Some attributes
424: are required to be followed by a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes section</a> below.)</li>
425:
426: <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
1.373 mike 427: or if the element is a <a href="#foreign-elements" title="foreign elements">foreign
428: element</a>, then there may be a single U+002F SOLIDUS
429: (<code>/</code>) character. This character has no effect on
430: <a href="#void-elements">void elements</a>, but on <a href="#foreign-elements">foreign elements</a> it
431: marks the start tag as self-closing.</li>
1.1 mike 432:
433: <li>Finally, start tags must be closed by a U+003E GREATER-THAN
434: SIGN (<code>></code>) character.</li>
435:
1.123 mike 436: </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
437: following format:</p><ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.1 mike 438: SIGN (<code><</code>).</li>
439:
440: <li>The second character of an end tag must be a U+002F SOLIDUS
441: (<code>/</code>).</li>
442:
443: <li>The next few characters of an end tag must be the element's
444: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
445:
446: <li>After the tag name, there may be one or more <a href="infrastructure.html#space-character" title="space
447: character">space characters</a>.</li>
448:
449: <li>Finally, end tags must be closed by a U+003E GREATER-THAN
450: SIGN (<code>></code>) character.</li>
451:
1.123 mike 452: </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
453: 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 454: one or more characters other than the <a href="infrastructure.html#space-character" title="space
455: character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
456: MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
457: (>), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters,
458: the control characters, and any characters that are not defined by
459: Unicode. In the HTML syntax, attribute names may be written with any
460: mix of lower- and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.123 mike 461: 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 462: 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 463: 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 464:
465: <dd>
466:
467: <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
468: name</a>.</p>
469:
470: <div class="example">
471:
472: <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
473: the empty attribute syntax:</p>
474:
475: <pre><input <em>disabled</em>></pre>
476:
477: </div>
478:
479: <p>If an attribute using the empty attribute syntax is to be
480: followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
481: character</a> separating the two.</p>
482:
483: </dd>
484:
1.2 mike 485: <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1 mike 486:
487: <dd>
488:
489: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
490: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
491: characters</a>, followed by a single U+003D EQUALS SIGN
492: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
493: character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
494: addition to the requirements given above for attribute values,
495: must not contain any literal <a href="infrastructure.html#space-character" title="space character">space
496: characters</a>, any U+0022 QUOTATION MARK (<code>"</code>)
497: characters, U+0027 APOSTROPHE (<code>'</code>) characters,
498: U+003D EQUALS SIGN (<code>=</code>) characters, U+003C LESS-THAN
499: SIGN (<code><</code>) characters, or U+003E GREATER-THAN SIGN
500: (<code>></code>) characters, and must not be the empty
501: string.</p>
502:
503: <div class="example">
504:
505: <p>In the following example, the <code title="attr-input-value"><a href="forms.html#attr-input-value">value</a></code> attribute is given
506: with the unquoted attribute value syntax:</p>
507:
508: <pre><input <em>value=yes</em>></pre>
509:
510: </div>
511:
512: <p>If an attribute using the unquoted attribute syntax is to be
1.101 mike 513: followed by another attribute or by the optional U+002F SOLIDUS
514: (<code>/</code>) character allowed in step 6 of the <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> syntax above, then there
1.1 mike 515: must be a <a href="infrastructure.html#space-character">space character</a> separating the two.</p>
516:
517: </dd>
518:
519: <dt>Single-quoted attribute value syntax</dt>
520:
521: <dd>
522:
523: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
524: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
525: characters</a>, followed by a single U+003D EQUALS SIGN
526: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
527: character">space characters</a>, followed by a single U+0027
528: APOSTROPHE (<code>'</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
529: addition to the requirements given above for attribute values,
530: must not contain any literal U+0027 APOSTROPHE (<code>'</code>)
531: characters, and finally followed by a second single U+0027
532: APOSTROPHE (<code>'</code>) character.</p>
533:
534: <div class="example">
535:
536: <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
537: single-quoted attribute value syntax:</p>
538:
539: <pre><input <em>type='checkbox'</em>></pre>
540:
541: </div>
542:
543: <p>If an attribute using the single-quoted attribute syntax is to
544: be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
545: character</a> separating the two.</p>
546:
547: </dd>
548:
549: <dt>Double-quoted attribute value syntax</dt>
550:
551: <dd>
552:
553: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
554: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
555: characters</a>, followed by a single U+003D EQUALS SIGN
556: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
557: character">space characters</a>, followed by a single U+0022
558: QUOTATION MARK (<code>"</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
559: addition to the requirements given above for attribute values,
560: must not contain any literal U+0022 QUOTATION MARK
561: (<code>"</code>) characters, and finally followed by a second
562: single U+0022 QUOTATION MARK (<code>"</code>) character.</p>
563:
564: <div class="example">
565:
566: <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
567: double-quoted attribute value syntax:</p>
568:
569: <pre><input <em>name="be evil"</em>></pre>
570:
571: </div>
572:
573: <p>If an attribute using the double-quoted attribute syntax is to
574: be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
575: character</a> separating the two.</p>
576:
577: </dd>
578:
579: </dl><p>There must never be two or more attributes on the same start tag
580: whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.123 mike 581: each other.</p><h5 id="optional-tags"><span class="secno">9.1.2.4 </span>Optional tags</h5><p>Certain tags can be <dfn id="syntax-tag-omission" title="syntax-tag-omission">omitted</dfn>.</p><p class="note">Omitting an element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> does not mean the element
1.1 mike 582: is not present; it is implied, but it is still there. An HTML
1.159 mike 583: document always has a root <code><a href="semantics.html#the-html-element-0">html</a></code> element, even if the
1.1 mike 584: string <code title=""><html></code> doesn't appear anywhere in
1.159 mike 585: 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
586: 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
587: tag</a> may be omitted if the <code><a href="semantics.html#the-html-element-0">html</a></code> element is not
588: 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 589: element is empty, or--> if the first thing inside the
1.159 mike 590: <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
591: tag</a> may be omitted if the <code><a href="semantics.html#the-head-element-0">head</a></code> element is not
592: 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
593: 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 594: 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 595: 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 596: <code><a href="semantics.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
597: tag is present, the parser makes <style> and <script> elements
598: between </head> and <body> end up in the <head> instead of implying
1.159 mike 599: 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
600: 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 601: 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 602: tag</a> may be omitted if the <code><a href="semantics.html#the-li-element">li</a></code> element is
603: immediately followed by another <code><a href="semantics.html#the-li-element">li</a></code> element or if there
1.422 mike 604: 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 605: tag</a> may be omitted if the <code><a href="semantics.html#the-dt-element">dt</a></code> element is
606: immediately followed by another <code><a href="semantics.html#the-dt-element">dt</a></code> element or a
1.123 mike 607: <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 608: tag</a> may be omitted if the <code><a href="semantics.html#the-dd-element">dd</a></code> element is
609: immediately followed by another <code><a href="semantics.html#the-dd-element">dd</a></code> element or a
610: <code><a href="semantics.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.123 mike 611: 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 612: tag</a> may be omitted if the <code><a href="semantics.html#the-p-element">p</a></code> element is
613: immediately followed by an <code><a href="semantics.html#the-address-element">address</a></code>,
614: <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 615: <!--v2DATAGRID <code>datagrid</code>,--> <code><a href="obsolete.html#dir">dir</a></code>,
1.306 mike 616: <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 617: <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>,
618: <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>,
619: <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>,
620: <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>,
621: <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 622: <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>,
623: element, or if there is no more content in the parent element and
1.123 mike 624: 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 625: tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element is
626: 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 627: 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 628: tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element is
629: 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 630: 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 631: <select>; commented out text below can handle the non-<select> case
1.123 mike 632: 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 633: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
634: <code>select</code> element and--> is immediately followed by
635: another <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
636: that are ancestors of the <code>optgroup</code> element, up to and
637: including the first ancestor element that is not an
638: <code>optgroup</code> element, have no more content--> there is no
1.123 mike 639: more content in the parent element.</p><!-- so e.g. the max number of </optgroup>s are omitted here:
1.1 mike 640: <select><optgroup></select>
641: <p id=x><optgroup></optgroup>x</p>
642: <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
643: <p><optgroup id=x><optgroup></optgroup>x</p>
644: <p><optgroup><optgroup id=x>x</p>
1.123 mike 645: --><!-- </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 646: tag</a> may be omitted if the <code><a href="forms.html#the-option-element">option</a></code> element is
647: immediately followed by another <code><a href="forms.html#the-option-element">option</a></code> element, or if
648: it is immediately followed by an <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or
1.123 mike 649: 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 650: first thing inside the <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is a
651: <code><a href="tabular-data.html#the-col-element">col</a></code> element, and if the element is not immediately
652: 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 653: 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 654: <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.123 mike 655: <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 656: tag</a> may be omitted if the <code><a href="tabular-data.html#the-thead-element">thead</a></code> element is
657: 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 658: 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 659: first thing inside the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is a
660: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, and if the element is not immediately
661: 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
662: <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
663: tag</a> has been omitted. (It can't be omitted if the element is
1.123 mike 664: 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 665: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is
666: 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 667: 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 668: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element is
669: immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, or if there is
1.123 mike 670: 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 671: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
672: immediately followed by another <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, or if there
1.123 mike 673: 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 674: tag</a> may be omitted if the <code><a href="tabular-data.html#the-td-element">td</a></code> element is
675: 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 676: 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 677: tag</a> may be omitted if the <code><a href="tabular-data.html#the-th-element">th</a></code> element is
678: 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 679: 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
680: 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
681: 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 682: elements, even though these elements are technically allowed inside
683: <code><a href="tabular-data.html#the-table-element">table</a></code> elements according to the content models
684: described in this specification. (If a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
685: 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 686: 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
687: placed immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
1.1 mike 688: 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>
689: elements. This does not affect the processing of the element. The
1.304 mike 690: otherwise optional <a href="#syntax-newlines" title="syntax-newlines">newline</a>
1.381 mike 691: <em>must</em> be included if the element's contents themselves start
692: with a <a href="#syntax-newlines" title="syntax-newlines">newline</a> (because
693: otherwise the leading newline in the contents would be treated like
694: the optional newline, and ignored).</p><div class="example">
1.1 mike 695: <p>The following two <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
696: <pre><pre>Hello</pre></pre>
697: <pre><pre><br>Hello</pre></pre>
1.373 mike 698: </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
699: <a href="#rcdata-elements" title="RCDATA elements">RCDATAs</a> element must not
700: contain any occurrences of the string "<code title=""></</code>"
701: (U+003C LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that
1.1 mike 702: case-insensitively match the tag name of the element followed by one
703: of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM
1.304 mike 704: FEED (FF), U+000D CARRIAGE RETURN (CR), U+0020 SPACE, U+003E
705: GREATER-THAN SIGN (>), or U+002F SOLIDUS (/), unless that string is
706: part of an <a href="#syntax-escape" title="syntax-escape">escaping text
707: span</a>.</p><p>An <dfn id="syntax-escape" title="syntax-escape">escaping text span</dfn> is a span
1.1 mike 708: 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
709: not itself in an <a href="#syntax-escape" title="syntax-escape">escaping text
710: span</a>, and ends at the next <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span end</a>. There
711: cannot be any <a href="#syntax-charref" title="syntax-charref">character
712: references</a> inside an <a href="#syntax-escape" title="syntax-escape">escaping
713: text span</a> — sequences of characters that would look
714: like <a href="#syntax-charref" title="syntax-charref">character references</a> do not
1.123 mike 715: have special meaning.</p><p>An <dfn id="syntax-escape-start" title="syntax-escape-start">escaping text span
1.1 mike 716: start</dfn> is a part of <a href="#syntax-text" title="syntax-text">text</a> that
717: consists of the four character sequence "<code title=""><!--</code>" (U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
1.123 mike 718: 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 719: a part of <a href="#syntax-text" title="syntax-text">text</a> that consists of the
720: three character sequence "<code title="">--></code>" (U+002D
1.134 mike 721: 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 722: start</a> may share its U+002D HYPHEN-MINUS characters with its
723: corresponding <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span
1.373 mike 724: end</a>.</p><p>The text in <a href="#raw-text-elements">raw text elements</a> and <a href="#rcdata-elements">RCDATA
725: elements</a> must not have an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a> that is
726: not followed by an <a href="#syntax-escape-end" title="syntax-escape-end">escaping text
727: 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 728: attributes, and comments. Text must consist of Unicode characters.
729: Text must not contain U+0000 characters. Text must not contain
1.316 mike 730: permanently undefined Unicode characters (noncharacters). Text must
731: not contain control characters other than <a href="infrastructure.html#space-character" title="space
732: character">space characters</a>. Extra constraints are placed on
733: what is and what is not allowed in text based on where the text is
734: 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 735: represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A
736: LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR),
1.123 mike 737: 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 738: to escape characters that couldn't otherwise legally be included in
1.123 mike 739: <a href="#syntax-text" title="syntax-text">text</a>.</p><p>Character references must start with a U+0026 AMPERSAND
1.1 mike 740: (<code>&</code>). Following this, there are three possible kinds
1.123 mike 741: of character references:</p><dl><dt>Named character references</dt>
1.1 mike 742:
743: <dd>The ampersand must be followed by one of the names given in the
744: <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
745: case. The name must be one that is terminated by a U+003B SEMICOLON
746: (<code title="">;</code>) character.</dd>
747:
748:
749: <dt>Decimal numeric character reference</dt>
750:
751: <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
752: (<code>#</code>) character, followed by one or more digits in the
753: range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, representing a
1.378 mike 754: base-ten integer that corresponds to a Unicode code point that is
755: allowed according to the definition below. The digits must then be
756: followed by a U+003B SEMICOLON character (<code title="">;</code>).</dd>
1.1 mike 757:
758:
759: <dt>Hexadecimal numeric character reference</dt>
760:
761: <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
762: (<code>#</code>) character, which must be followed by either a
763: U+0078 LATIN SMALL LETTER X or a U+0058 LATIN CAPITAL LETTER X
764: character, which must then be followed by one or more digits in the
765: range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, U+0061 LATIN SMALL
766: LETTER A .. U+0066 LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL
767: LETTER A .. U+0046 LATIN CAPITAL LETTER F, representing a
1.378 mike 768: base-sixteen integer that corresponds to a Unicode code point that
769: is allowed according to the definition below. The digits must then
770: be followed by a U+003B SEMICOLON character (<code title="">;</code>).</dd>
771:
772: </dl><p>The numeric character reference forms described above are allowed
773: to reference any Unicode code point other than U+0000, permanently
774: undefined Unicode characters (noncharacters), and control characters
775: other than <a href="infrastructure.html#space-character" title="space character">space
776: characters</a>.</p><p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.1 mike 777: ampersand</dfn> is a U+0026 AMPERSAND (<code>&</code>) character
778: that is followed by some <a href="#syntax-text" title="syntax-text">text</a> other
779: than a <a href="infrastructure.html#space-character">space character</a>, a U+003C LESS-THAN SIGN
780: character ('<'), or another U+0026 AMPERSAND (<code>&</code>)
1.123 mike 781: character.</p><h4 id="cdata-sections"><span class="secno">9.1.5 </span>CDATA sections</h4><p><dfn id="syntax-cdata" title="syntax-cdata">CDATA sections</dfn> must start with
1.1 mike 782: the character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
783: MARK, U+005B LEFT SQUARE BRACKET, U+0043 LATIN CAPITAL LETTER C,
784: U+0044 LATIN CAPITAL LETTER D, U+0041 LATIN CAPITAL LETTER A, U+0054
785: LATIN CAPITAL LETTER T, U+0041 LATIN CAPITAL LETTER A, U+005B LEFT
786: SQUARE BRACKET (<code title=""><![CDATA[</code>). Following this
787: sequence, the CDATA section may have <a href="#syntax-text" title="syntax-text">text</a>, with the additional restriction
788: that the text must not contain the three character sequence U+005D
789: RIGHT SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E
790: GREATER-THAN SIGN (<code title="">]]></code>). Finally, the CDATA
791: section must be ended by the three character sequence U+005D RIGHT
792: SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E GREATER-THAN
1.159 mike 793: 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 794: four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
795: MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title=""><!--</code>). Following this sequence, the comment may
796: have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
797: restriction that the text must not start with a single U+003E
798: GREATER-THAN SIGN ('>') character, nor start with a U+002D
799: HYPHEN-MINUS (<code title="">-</code>) character followed by a
800: U+003E GREATER-THAN SIGN ('>') character, nor contain two
801: consecutive U+002D HYPHEN-MINUS (<code title="">-</code>)
802: characters, nor end with a U+002D HYPHEN-MINUS (<code title="">-</code>) character. Finally, the comment must be ended by
803: the three character sequence U+002D HYPHEN-MINUS, U+002D
1.123 mike 804: HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--></code>).</p><div class="impl">
1.1 mike 805:
1.159 mike 806: <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 807:
808: <p><i>This section only applies to user agents, data mining tools,
809: and conformance checkers.</i></p>
810:
811: <p class="note">The rules for parsing XML documents into DOM trees
812: are covered by the next section, entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
813: syntax</a>".</p>
814:
815: <p>For <a href="dom.html#html-documents">HTML documents</a>, user agents must use the parsing
816: rules described in this section to generate the DOM trees. Together,
817: these rules define what is referred to as the <dfn id="html-parser">HTML
818: parser</dfn>.</p>
819:
820: <div class="note">
821:
822: <p>While the HTML syntax described in this specification bears a
823: close resemblance to SGML and XML, it is a separate language with
824: its own parsing rules.</p>
825:
1.183 mike 826: <p>Some earlier versions of HTML (in particular from HTML2 to
827: HTML4) were based on SGML and used SGML parsing rules. However, few
1.1 mike 828: (if any) web browsers ever implemented true SGML parsing for HTML
829: documents; the only user agents to strictly handle HTML as an SGML
830: application have historically been validators. The resulting
831: confusion — with validators claiming documents to have one
832: representation while widely deployed Web browsers interoperably
833: implemented a different representation — has wasted decades
834: of productivity. This version of HTML thus returns to a non-SGML
835: basis.</p>
836:
837: <p>Authors interested in using SGML tools in their authoring
838: pipeline are encouraged to use XML tools and the XML serialization
839: of HTML.</p>
840:
841: </div>
842:
843: <p>This specification defines the parsing rules for HTML documents,
844: whether they are syntactically correct or not. Certain points in the
845: parsing algorithm are said to be <dfn id="parse-error" title="parse error">parse
846: errors</dfn>. The error handling for parse errors is well-defined:
847: user agents must either act as described below when encountering
848: such problems, or must abort processing at the first error that they
849: encounter for which they do not wish to apply the rules described
850: below.</p>
851:
852: <p>Conformance checkers must report at least one parse error
853: condition to the user if one or more parse error conditions exist in
854: the document and must not report parse error conditions if none
855: exist in the document. Conformance checkers may report more than one
1.174 mike 856: parse error condition if more than one parse error condition exists
1.1 mike 857: in the document. Conformance checkers are not required to recover
858: from parse errors.</p>
859:
860: <p class="note">Parse errors are only errors with the
861: <em>syntax</em> of HTML. In addition to checking for parse errors,
862: conformance checkers will also verify that the document obeys all
863: the other conformance requirements described in this
864: specification.</p>
865:
866: <p>For the purposes of conformance checkers, if a resource is
867: determined to be in <a href="#syntax">the HTML syntax</a>, then it is an
868: <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
869:
1.266 mike 870: </div><div class="impl">
1.1 mike 871:
872: <h4 id="overview-of-the-parsing-model"><span class="secno">9.2.1 </span>Overview of the parsing model</h4>
873:
874: <p>The input to the HTML parsing process consists of a stream of
875: Unicode characters, which is passed through a
876: <a href="#tokenization">tokenization</a> stage followed by a <a href="#tree-construction">tree
877: construction</a> stage. The output is a <code>Document</code>
878: object.</p>
879:
880: <p class="note">Implementations that <a href="infrastructure.html#non-scripted">do not
881: support scripting</a> do not have to actually create a DOM
882: <code>Document</code> object, but the DOM tree in such cases is
883: still used as the model for the rest of the specification.</p>
884:
885: <p>In the common case, the data handled by the tokenization stage
1.159 mike 886: comes from the network, but <a href="embedded-content-0.html#dynamic-markup-insertion" title="dynamic markup
887: 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 888:
889: <p><img alt="" src="images/parsing-model-overview.png"></p>
890:
891: <p id="nestedParsing">There is only one set of states for the
892: tokenizer stage and the tree construction stage, but the tree
893: construction stage is reentrant, meaning that while the tree
894: construction stage is handling one token, the tokenizer might be
895: resumed, causing further tokens to be emitted and processed before
896: the first token's processing is complete.</p>
897:
898: <div class="example">
899:
900: <p>In the following example, the tree construction stage will be
901: called upon to handle a "p" start tag token while handling the
902: "script" start tag token:</p>
903:
904: <pre>...
905: <script>
906: document.write('<p>');
907: </script>
908: ...</pre>
909:
910: </div>
911:
912: <p>To handle these cases, parsers have a <dfn id="script-nesting-level">script nesting
913: level</dfn>, which must be initially set to zero, and a <dfn id="parser-pause-flag">parser
914: pause flag</dfn>, which must be initially set to false.</p>
915:
1.266 mike 916: </div><div class="impl">
1.1 mike 917:
918: <h4 id="the-input-stream"><span class="secno">9.2.2 </span>The <dfn>input stream</dfn></h4>
919:
920: <p>The stream of Unicode characters that comprises the input to the
921: tokenization stage will be initially seen by the user agent as a
922: stream of bytes (typically coming over the network or from the local
923: file system). The bytes encode the actual characters according to a
924: particular <em>character encoding</em>, which the user agent must
925: use to decode the bytes into characters.</p>
926:
927: <p class="note">For XML documents, the algorithm user agents must
928: use to determine the character encoding is given by the XML
1.104 mike 929: specification. This section does not apply to XML documents. <a href="references.html#refsXML">[XML]</a></p>
1.1 mike 930:
931:
1.168 mike 932: <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 933:
934: <p>In some cases, it might be impractical to unambiguously determine
935: the encoding before parsing the document. Because of this, this
936: specification provides for a two-pass mechanism with an optional
937: pre-scan. Implementations are allowed, as described below, to apply
938: a simplified parsing algorithm to whatever bytes they have available
939: before beginning to parse the document. Then, the real parser is
940: started, using a tentative encoding derived from this pre-parse and
941: other out-of-band metadata. If, while the document is being loaded,
942: the user agent discovers an encoding declaration that conflicts with
943: this information, then the parser can get reinvoked to perform a
944: parse of the document with the real encoding.</p>
945:
946: <p id="documentEncoding">User agents must use the following
947: algorithm (the <dfn id="encoding-sniffing-algorithm">encoding sniffing algorithm</dfn>) to determine
948: the character encoding to use when decoding a document in the first
949: pass. This algorithm takes as input any out-of-band metadata
950: available to the user agent (e.g. the <a href="infrastructure.html#content-type" title="Content-Type">Content-Type metadata</a> of the document)
951: and all the bytes available so far, and returns an encoding and a
952: <dfn id="concept-encoding-confidence" title="concept-encoding-confidence">confidence</dfn>. The
953: confidence is either <i>tentative</i>, <i>certain</i>, or
954: <i>irrelevant</i>. The encoding used, and whether the confidence in
955: that encoding is <i>tentative</i> or <i>certain</i>, is <a href="#meta-charset-during-parse">used during the parsing</a> to
956: determine whether to <a href="#change-the-encoding">change the encoding</a>. If no
957: encoding is necessary, e.g. because the parser is operating on a
958: stream of Unicode characters and doesn't have to use an encoding at
959: all, then the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
960: <i>irrelevant</i>.</p>
961:
962: <ol><li><p>If the transport layer specifies an encoding, and it is
963: supported, return that encoding with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
964: <i>certain</i>, and abort these steps.</p></li>
965:
966: <li><p>The user agent may wait for more bytes of the resource to be
967: available, either in this step or at any later step in this
968: algorithm. For instance, a user agent might wait 500ms or 512
969: bytes, whichever came first. In general preparsing the source to
970: find the encoding improves performance, as it reduces the need to
971: throw away the data structures used when parsing upon finding the
972: encoding information. However, if the user agent delays too long to
973: obtain data to determine the encoding, then the cost of the delay
974: could outweigh any performance improvements from the
975: preparse.</p></li>
976:
977: <li><p>For each of the rows in the following table, starting with
978: the first one and going down, if there are as many or more bytes
979: available than the number of bytes in the first column, and the
980: first bytes of the file match the bytes given in the first column,
981: then return the encoding given in the cell in the second column of
982: that row, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
983: <i>certain</i>, and abort these steps:</p>
984:
985: <!-- this table is present in several forms in this file; keep them in sync -->
986: <table><thead><tr><th>Bytes in Hexadecimal
987: </th><th>Encoding
988: </th></tr></thead><tbody><!-- nobody uses this
989: <tr>
990: <td>00 00 FE FF
991: <td>UTF-32BE
992: <tr>
993: <td>FF FE 00 00
994: <td>UTF-32LE
995: --><tr><td>FE FF
996: </td><td>UTF-16BE
997: </td></tr><tr><td>FF FE
998: </td><td>UTF-16LE
999: </td></tr><tr><td>EF BB BF
1000: </td><td>UTF-8
1001: <!-- nobody uses this
1002: <tr>
1003: <td>DD 73 66 73
1004: <td>UTF-EBCDIC
1005: -->
1006: </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
1007: (BOMs).</p></li>
1008:
1009: <li><p>Otherwise, the user agent will have to search for explicit
1010: character encoding information in the file itself. This should
1011: proceed as follows:
1012:
1013: </p><p>Let <var title="">position</var> be a pointer to a byte in the
1014: input stream, initially pointing at the first byte. If at any
1015: point during these substeps the user agent either runs out of
1016: bytes or decides that scanning further bytes would not be
1017: efficient, then skip to the next step of the overall character
1018: encoding detection algorithm. User agents may decide that scanning
1019: <em>any</em> bytes is not efficient, in which case these substeps
1020: are entirely skipped.</p>
1021:
1022: <p>Now, repeat the following "two" steps until the algorithm
1023: aborts (either because user agent aborts, as described above, or
1024: because a character encoding is found):</p>
1025:
1026: <ol><li><p>If <var title="">position</var> points to:</p>
1027:
1028: <dl class="switch"><dt>A sequence of bytes starting with: 0x3C 0x21 0x2D 0x2D (ASCII '<!--')</dt>
1029: <dd>
1030:
1031: <p>Advance the <var title="">position</var> pointer so that it
1032: points at the first 0x3E byte which is preceded by two 0x2D
1033: bytes (i.e. at the end of an ASCII '-->' sequence) and comes
1034: after the 0x3C byte that was found. (The two 0x2D bytes can be
1035: the same as the those in the '<!--' sequence.)</p>
1036:
1037: </dd>
1038:
1039: <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>
1040: <dd>
1041:
1042: <ol><li><p>Advance the <var title="">position</var> pointer so
1043: that it points at the next 0x09, 0x0A, 0x0C, 0x0D, 0x20, or
1044: 0x2F byte (the one in sequence of characters matched
1045: above).</p></li>
1046:
1047: <li><p><a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">Get
1048: an attribute</a> and its value. If no attribute was
1049: sniffed, then skip this inner set of steps, and jump to the
1050: second step in the overall "two step" algorithm.</p></li>
1051:
1052: <li><p>If the attribute's name is neither "<code title="">charset</code>" nor "<code title="">content</code>",
1053: then return to step 2 in these inner steps.</p></li>
1054:
1055: <li><p>If the attribute's name is "<code title="">charset</code>", let <var title="">charset</var> be
1056: the attribute's value, interpreted as a character
1057: encoding.</p></li>
1058:
1059: <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
1060: extracting an encoding from a Content-Type</a>, giving the
1061: attribute's value as the string to parse. If an encoding is
1062: returned, let <var title="">charset</var> be that
1063: encoding. Otherwise, return to step 2 in these inner
1064: steps.</p></li>
1065:
1066: <li><p>If <var title="">charset</var> is a UTF-16 encoding,
1067: change the value of <var title="">charset</var> to
1068: UTF-8.</p></li>
1069:
1070: <li><p>If <var title="">charset</var> is a supported
1071: character encoding, then return the given encoding, with
1072: <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1073: <i>tentative</i>, and abort all these steps.</p></li>
1074:
1075: <li><p>Otherwise, return to step 2 in these inner
1076: steps.</p></li>
1077:
1078: </ol></dd>
1079:
1080: <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>
1081: <dd>
1082:
1083: <ol><li><p>Advance the <var title="">position</var> pointer so
1084: that it points at the next 0x09 (ASCII TAB), 0x0A (ASCII LF),
1085: 0x0C (ASCII FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E
1086: (ASCII '>') byte.</p></li>
1087:
1088: <li><p>Repeatedly <a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
1089: attribute</a> until no further attributes can be found,
1090: then jump to the second step in the overall "two step"
1091: algorithm.</p></li>
1092:
1093: </ol></dd>
1094:
1095: <dt>A sequence of bytes starting with: 0x3C 0x21 (ASCII '<!')</dt>
1096: <dt>A sequence of bytes starting with: 0x3C 0x2F (ASCII '</')</dt>
1097: <dt>A sequence of bytes starting with: 0x3C 0x3F (ASCII '<?')</dt>
1098: <dd>
1099:
1100: <p>Advance the <var title="">position</var> pointer so that it
1101: points at the first 0x3E byte (ASCII '>') that comes after the
1102: 0x3C byte that was found.</p>
1103:
1104: </dd>
1105:
1106: <dt>Any other byte</dt>
1107: <dd>
1108:
1109: <p>Do nothing with that byte.</p>
1110:
1111: </dd>
1112:
1113: </dl></li>
1114:
1115: <li>Move <var title="">position</var> so it points at the next
1116: byte in the input stream, and return to the first step of this
1117: "two step" algorithm.</li>
1118:
1119: </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
1120: attribute</dfn>, it means doing this:</p>
1121:
1122: <ol><li><p>If the byte at <var title="">position</var> is one of 0x09
1123: (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII FF), 0x0D (ASCII CR),
1124: 0x20 (ASCII space), or 0x2F (ASCII '/') then advance <var title="">position</var> to the next byte and redo this
1125: substep.</p></li>
1126:
1127: <li><p>If the byte at <var title="">position</var> is 0x3E (ASCII
1128: '>'), then abort the "get an attribute" algorithm. There isn't
1129: one.</p></li>
1130:
1131: <li><p>Otherwise, the byte at <var title="">position</var> is the
1132: start of the attribute name. Let <var title="">attribute
1133: name</var> and <var title="">attribute value</var> be the empty
1134: string.</p></li>
1135:
1136: <li><p><i>Attribute name</i>: Process the byte at <var title="">position</var> as follows:</p>
1137:
1138: <dl class="switch"><dt>If it is 0x3D (ASCII '='), and the <var title="">attribute
1139: name</var> is longer than the empty string</dt>
1140:
1141: <dd>Advance <var title="">position</var> to the next byte and
1142: jump to the step below labeled <i>value</i>.</dd>
1143:
1144: <dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
1145: FF), 0x0D (ASCII CR), or 0x20 (ASCII space)</dt>
1146:
1147: <dd>Jump to the step below labeled <i>spaces</i>.</dd>
1148:
1149: <dt>If it is 0x2F (ASCII '/') or 0x3E (ASCII '>')</dt>
1150:
1151: <dd>Abort the "get an attribute" algorithm. The attribute's
1152: name is the value of <var title="">attribute name</var>, its
1153: value is the empty string.</dd>
1154:
1155: <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
1156: 'Z')</dt>
1157:
1158: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1159: name</var> (where <var title="">b</var> is the value of the
1160: byte at <var title="">position</var>).</dd>
1161:
1162: <dt>Anything else</dt>
1163:
1164: <dd>Append the Unicode character with the same code point as the
1165: value of the byte at <var title="">position</var>) to <var title="">attribute name</var>. (It doesn't actually matter how
1166: bytes outside the ASCII range are handled here, since only
1167: ASCII characters can contribute to the detection of a character
1168: encoding.)</dd>
1169:
1170: </dl></li>
1171:
1172: <li><p>Advance <var title="">position</var> to the next byte and
1173: return to the previous step.</p></li>
1174:
1175: <li><p><i>Spaces</i>: If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
1176: LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
1177: advance <var title="">position</var> to the next byte, then,
1178: repeat this step.</p></li>
1179:
1180: <li><p>If the byte at <var title="">position</var> is
1181: <em>not</em> 0x3D (ASCII '='), abort the "get an attribute"
1182: algorithm. The attribute's name is the value of <var title="">attribute name</var>, its value is the empty
1183: string.</p></li>
1184:
1185: <li><p>Advance <var title="">position</var> past the 0x3D (ASCII
1186: '=') byte.</p></li>
1187:
1188: <li><p><i>Value:</i> If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
1189: LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
1190: advance <var title="">position</var> to the next byte, then,
1191: repeat this step.</p></li>
1192:
1193: <li><p>Process the byte at <var title="">position</var> as
1194: follows:</p>
1195:
1196: <dl class="switch"><dt>If it is 0x22 (ASCII '"') or 0x27 ("'")</dt>
1197:
1198: <dd>
1199:
1200: <ol><li>Let <var title="">b</var> be the value of the byte at
1201: <var title="">position</var>.</li>
1202:
1203: <li>Advance <var title="">position</var> to the next
1204: byte.</li>
1205:
1206: <li>If the value of the byte at <var title="">position</var>
1207: is the value of <var title="">b</var>, then advance <var title="">position</var> to the next byte and abort the "get
1208: an attribute" algorithm. The attribute's name is the value of
1209: <var title="">attribute name</var>, and its value is the
1210: value of <var title="">attribute value</var>.</li>
1211:
1212: <li>Otherwise, if the value of the byte at <var title="">position</var> is in the range 0x41 (ASCII 'A') to
1213: 0x5A (ASCII 'Z'), then append a Unicode character to <var title="">attribute value</var> whose code point is 0x20 more
1214: than the value of the byte at <var title="">position</var>.</li>
1215:
1216: <li>Otherwise, append a Unicode character to <var title="">attribute value</var> whose code point is the same as
1217: the value of the byte at <var title="">position</var>.</li>
1218:
1219: <li>Return to the second step in these substeps.</li>
1220:
1221: </ol></dd>
1222:
1223: <dt>If it is 0x3E (ASCII '>')</dt>
1224:
1225: <dd>Abort the "get an attribute" algorithm. The attribute's
1226: name is the value of <var title="">attribute name</var>, its
1227: value is the empty string.</dd>
1228:
1229:
1230: <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
1231: 'Z')</dt>
1232:
1233: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1234: value</var> (where <var title="">b</var> is the value of the
1235: byte at <var title="">position</var>). Advance <var title="">position</var> to the next byte.</dd>
1236:
1237: <dt>Anything else</dt>
1238:
1239: <dd>Append the Unicode character with the same code point as the
1240: 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>
1241:
1242: </dl></li>
1243:
1244: <li><p>Process the byte at <var title="">position</var> as
1245: follows:</p>
1246:
1247: <dl class="switch"><dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
1248: FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E (ASCII
1249: '>')</dt>
1250:
1251: <dd>Abort the "get an attribute" algorithm. The attribute's
1252: name is the value of <var title="">attribute name</var> and its
1253: value is the value of <var title="">attribute value</var>.</dd>
1254:
1255: <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
1256: 'Z')</dt>
1257:
1258: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1259: value</var> (where <var title="">b</var> is the value of the
1260: byte at <var title="">position</var>).</dd>
1261:
1262: <dt>Anything else</dt>
1263:
1264: <dd>Append the Unicode character with the same code point as the
1265: value of the byte at <var title="">position</var>) to <var title="">attribute value</var>.</dd>
1266:
1267: </dl></li>
1268:
1269: <li><p>Advance <var title="">position</var> to the next byte and
1270: return to the previous step.</p></li>
1271:
1272: </ol><p>For the sake of interoperability, user agents should not use a
1273: pre-scan algorithm that returns different results than the one
1274: described above. (But, if you do, please at least let us know, so
1275: that we can improve this algorithm and benefit everyone...)</p>
1276:
1277: </li>
1278:
1279: <li><p>If the user agent has information on the likely encoding for
1280: this page, e.g. based on the encoding of the page when it was last
1281: visited, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1282: <i>tentative</i>, and abort these steps.</p></li>
1283:
1.322 mike 1284: <li>
1285:
1286: <p>The user agent may attempt to autodetect the character encoding
1287: from applying frequency analysis or other algorithms to the data
1288: stream. If autodetection succeeds in determining a character
1289: encoding, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1290: <i>tentative</i>, and abort these steps. <a href="references.html#refsUNIVCHARDET">[UNIVCHARDET]</a></p>
1291:
1292: <p class="note">The UTF-8 encoding has a highly detectable bit
1293: pattern. Documents that contain bytes with values greater than
1294: 0x7F which match the UTF-8 pattern are very likely to be UTF-8,
1295: while documents with byte sequences that do not match it are very
1296: likely not. User-agents are therefore encouraged to search for
1297: this common encoding.</p>
1298:
1299: </li>
1.1 mike 1300:
1301: <li><p>Otherwise, return an implementation-defined or
1302: user-specified default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1.459 mike 1303: <i>tentative</i>. In controlled environments or in environments
1304: where the encoding of documents can be prescribed (for example, for
1305: user agents intended for dedicated use in new networks), the more
1.1 mike 1306: comprehensive <code title="">UTF-8</code> encoding is
1.459 mike 1307: suggested. Due to its use in legacy content, <code title="">windows-1252</code> is suggested as a default in
1.187 mike 1308: predominantly Western demographics instead.</p></li>
1.1 mike 1309:
1310: </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
1311: be set to the value returned from this algorithm, at the same time
1312: as the user agent uses the returned value to select the decoder to
1313: use for the input stream.</p>
1314:
1315:
1.237 mike 1316: <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 1317:
1.237 mike 1318: <p>User agents must at a minimum support the UTF-8 and Windows-1252
1319: encodings, but may support more.</p>
1320:
1321: <p class="note">It is not unusual for Web browsers to support dozens
1322: if not upwards of a hundred distinct character encodings.</p>
1323:
1.365 mike 1324: <p>User agents must support the <a href="infrastructure.html#preferred-mime-name">preferred MIME name</a> of
1325: every character encoding they support, and should support all the
1326: IANA-registered names and aliases of every character encoding they
1327: support. <a href="references.html#refsIANACHARSET">[IANACHARSET]</a></p>
1.237 mike 1328:
1329: <p>When comparing a string specifying a character encoding with the
1330: name or alias of a character encoding to determine if they are
1331: 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
1332: then perform the comparison in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1333: case-insensitive</a> manner.</p>
1334:
1335: <!-- this bit will be replaced by actual alias registrations in due course -->
1336:
1337: <p>In addition, user agents must support the aliases given in the
1338: following table for every character encoding they support, so that
1339: labels from the first column are treated as equivalent to the labels
1340: given in the corresponding cell from the second column on the same
1341: row.</p>
1342:
1343: <table><caption>Additional character encoding aliases</caption>
1344: <thead><tr><th> Alias </th><th> Corresponding encoding </th><th> References
1345: </th></tr></thead><tbody><tr><td> x-sjis </td><td> windows-31J </td><td>
1346: <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
1347: <a href="references.html#refsWIN31J">[WIN31J]</a>
1348: </td></tr><tr><td> windows-932 </td><td> windows-31J </td><td>
1349: <a href="references.html#refsWIN31J">[WIN31J]</a>
1350: </td></tr><tr><td> x-x-big5 </td><td> Big5 </td><td>
1351: <a href="references.html#refsBIG5">[BIG5]</a>
1352: </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
1353: first column of the following table to either convert content to
1354: Unicode characters or convert Unicode characters to bytes, it must
1355: instead use the encoding given in the cell in the second column of
1356: the same row. When a byte or sequence of bytes is treated
1357: differently due to this encoding aliasing, it is said to have been
1358: <dfn id="misinterpreted-for-compatibility">misinterpreted for compatibility</dfn>.</p>
1359:
1360: <table><caption>Character encoding overrides</caption>
1361: <thead><tr><th> Input encoding </th><th> Replacement encoding </th><th> References
1362: </th></tr></thead><tbody><!-- how about EUC-JP? --><tr><td> EUC-KR </td><td> windows-949 </td><td>
1363: <a href="references.html#refsEUCKR">[EUCKR]</a>
1364: <a href="references.html#refsWIN949">[WIN949]</a>
1365: </td></tr><tr><td> GB2312 </td><td> GBK </td><td>
1366: <a href="references.html#refsRFC1345">[RFC1345]</a>
1367: <a href="references.html#refsGBK">[GBK]</a>
1368: </td></tr><tr><td> GB_2312-80 </td><td> GBK </td><td>
1369: <a href="references.html#refsRFC1345">[RFC1345]</a>
1370: <a href="references.html#refsGBK">[GBK]</a>
1371: </td></tr><tr><td> ISO-8859-1 </td><td> windows-1252 </td><td>
1372: <a href="references.html#refsRFC1345">[RFC1345]</a>
1373: <a href="references.html#refsWIN1252">[WIN1252]</a>
1374: </td></tr><tr><td> ISO-8859-9 </td><td> windows-1254 </td><td>
1375: <a href="references.html#refsRFC1345">[RFC1345]</a>
1376: <a href="references.html#refsWIN1254">[WIN1254]</a>
1377: </td></tr><tr><td> ISO-8859-11 </td><td> windows-874 </td><td>
1378: <a href="references.html#refsISO885911">[ISO885911]</a>
1379: <a href="references.html#refsWIN874">[WIN874]</a>
1380: </td></tr><tr><td> KS_C_5601-1987 </td><td> windows-949 </td><td>
1381: <a href="references.html#refsRFC1345">[RFC1345]</a>
1382: <a href="references.html#refsWIN949">[WIN949]</a>
1383: </td></tr><tr><td> Shift_JIS </td><td> windows-31J </td><td>
1384: <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
1385: <a href="references.html#refsWIN31J">[WIN31J]</a>
1386: </td></tr><tr><td> TIS-620 </td><td> windows-874 </td><td>
1387: <a href="references.html#refsTIS620">[TIS620]</a>
1388: <a href="references.html#refsWIN874">[WIN874]</a>
1389: </td></tr><tr><td> US-ASCII </td><td> windows-1252 </td><td>
1390: <a href="references.html#refsRFC1345">[RFC1345]</a>
1391: <a href="references.html#refsWIN1252">[WIN1252]</a>
1392: </td></tr></tbody></table><p class="note">The requirement to treat certain encodings as other
1393: encodings according to the table above is a <a href="introduction.html#willful-violation">willful
1394: violation</a> of the W3C Character Model specification, motivated
1395: by a desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
1396:
1397: <p>When a user agent is to use the UTF-16 encoding but no BOM has
1398: been found, user agents must default to UTF-16LE.</p>
1399:
1400: <p class="note">The requirement to default UTF-16 to LE rather than
1401: BE is a <a href="introduction.html#willful-violation">willful violation</a> of RFC 2781, motivated by a
1402: desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
1403:
1404: <hr><p>User agents must not support the CESU-8, UTF-7, BOCU-1 and SCSU
1405: 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>
1406:
1407: <p>Support for encodings based on EBCDIC is not recommended. This
1408: encoding is rarely used for publicly-facing Web content.</p>
1409:
1410: <p>Support for UTF-32 is not recommended. This encoding is rarely
1411: used, and frequently implemented incorrectly.</p>
1412:
1413: <p class="note">This specification does not make any attempt to
1414: support EBCDIC-based encodings and UTF-32 in its algorithms; support
1415: and use of these encodings can thus lead to unexpected behavior in
1416: implementations of this specification.</p>
1417:
1418:
1419:
1420: <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.3 </span>Preprocessing the input stream</h5>
1.1 mike 1421:
1422: <p>Given an encoding, the bytes in the input stream must be
1423: converted to Unicode characters for the tokenizer, as described by
1424: the rules for that encoding, except that the leading U+FEFF BYTE
1425: ORDER MARK character, if any, must not be stripped by the encoding
1426: layer (it is stripped by the rule below).</p> <!-- this is to
1427: prevent two leading BOMs from being both stripped, once by the
1428: decoder, and once by the parser -->
1429:
1430: <p>Bytes or sequences of bytes in the original byte stream that
1.393 mike 1431: could not be converted to Unicode code points must be converted to
1432: U+FFFD REPLACEMENT CHARACTERs.</p>
1.1 mike 1433:
1434: <p class="note">Bytes or sequences of bytes in the original byte
1435: stream that did not conform to the encoding specification
1436: (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
1437: errors that conformance checkers are expected to report.</p>
1438:
1.438 mike 1439: <p>Any byte or sequence of bytes in the original byte stream that is
1440: <a href="#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
1.1 mike 1441: error</a>.</p>
1442:
1443: <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
1444: any are present.</p>
1445:
1.300 mike 1446: <p class="note">The requirement to strip a U+FEFF BYTE ORDER MARK
1447: character regardless of whether that character was used to determine
1448: the byte order is a <a href="introduction.html#willful-violation">willful violation</a> of Unicode,
1449: motivated by a desire to increase the resilience of user agents in
1450: the face of naïve transcoders.</p>
1451:
1.316 mike 1452: <p>All U+0000 NULL characters and code points in the range U+D800 to
1.315 mike 1453: U+DFFF<!-- surrogates not allowed e.g. in UTF-8, and we don't want
1454: them to suddenly turn into codepoints when they go through a UTF-16
1455: pipe --> in the input must be replaced by U+FFFD REPLACEMENT
1.316 mike 1456: CHARACTERs. Any occurrences of such characters and code points are
1457: <a href="#parse-error" title="parse error">parse errors</a>.</p>
1.1 mike 1458:
1459: <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
1460: <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
1461: CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
1.315 mike 1462: <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+FDD0
1463: to U+FDEF, and characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF,
1464: U+2FFFE, U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE,
1465: U+5FFFF, U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF,
1466: U+9FFFE, U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE,
1467: U+CFFFF, U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF,
1468: U+10FFFE, and U+10FFFF are <a href="#parse-error" title="parse error">parse
1.316 mike 1469: errors</a>. These are all control characters or permanently
1470: undefined Unicode characters (noncharacters).</p>
1.1 mike 1471:
1472: <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
1473: characters are treated specially. Any CR characters that are
1474: followed by LF characters must be removed, and any CR characters not
1475: followed by LF characters must be converted to LF characters. Thus,
1476: newlines in HTML DOMs are represented by LF characters, and there
1477: are never any CR characters in the input to the
1478: <a href="#tokenization">tokenization</a> stage.</p>
1479:
1480: <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
1481: input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
1482: the <i><a href="#next-input-character">next input character</a></i> is the first character in the
1483: input. The <dfn id="current-input-character">current input character</dfn> is the last character
1484: to have been <i><a href="#consumed">consumed</a></i>.</p>
1485:
1486: <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
1487: character or just before the end of the input stream) where content
1.159 mike 1488: 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 1489: inserted. The insertion point is relative to the position of the
1490: character immediately after it, it is not an absolute offset into
1491: the input stream. Initially, the insertion point is
1.10 mike 1492: undefined.</p>
1.1 mike 1493:
1494: <p>The "EOF" character in the tables below is a conceptual character
1495: representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
1.159 mike 1496: is a <a href="embedded-content-0.html#script-created-parser">script-created parser</a>, then the end of the
1.1 mike 1497: <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
1.159 mike 1498: 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 1499: consumed. Otherwise, the "EOF" character is not a real character in
1500: the stream, but rather the lack of any further characters.</p>
1501:
1502:
1.237 mike 1503: <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.4 </span>Changing the encoding while parsing</h5>
1.1 mike 1504:
1505: <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
1506: encoding</dfn>, it must run the following steps. This might happen
1507: if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
1508: failed to find an encoding, or if it found an encoding that was not
1509: the actual encoding of the file.</p>
1510:
1511: <ol><li>If the new encoding is identical or equivalent to the encoding
1512: that is already being used to interpret the input stream, then set
1513: the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1514: <i>certain</i> and abort these steps. This happens when the
1515: encoding information found in the file matches what the
1516: <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
1517: encoding, and in the second pass through the parser if the first
1518: pass found that the encoding sniffing algorithm described in the
1519: earlier section failed to find the right encoding.</li>
1520:
1521: <li>If the encoding that is already being used to interpret the
1522: input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1523: <i>certain</i> and abort these steps. The new encoding is ignored;
1524: if it was anything but the same encoding, then it would be clearly
1525: incorrect.</li>
1526:
1527: <li>If the new encoding is a UTF-16 encoding, change it to
1528: UTF-8.</li>
1529:
1530: <li>If all the bytes up to the last byte converted by the current
1531: decoder have the same Unicode interpretations in both the current
1532: encoding and the new encoding, and if the user agent supports
1533: changing the converter on the fly, then the user agent may change
1534: to the new converter for the encoding on the fly. Set the
1535: <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
1536: convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1537: <i>certain</i>, and abort these steps.</li>
1538:
1539: <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
1540: <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
1541: browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
1542: sniffing algorithm</a> and instead just set the encoding to the
1543: new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1544: <i>certain</i>. Whenever possible, this should be done without
1545: actually contacting the network layer (the bytes should be
1546: re-parsed from memory), even if, e.g., the document is marked as
1547: not being cacheable. If this is not possible and contacting the
1548: network layer would involve repeating a request that uses a method
1549: other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
1550: equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1551: <i>certain</i> and ignore the new encoding. The resource will be
1552: misinterpreted. User agents may notify the user of the situation,
1553: to aid in application development.</li>
1554:
1.266 mike 1555: </ol></div><div class="impl">
1556:
1557: <h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4>
1.1 mike 1558:
1559: <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5>
1560:
1561: <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
1562: the primary operation of the tree construction stage.</p>
1563:
1564: <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
1565: "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
1566: "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
1567: "<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 1568: "<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 1569: "<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>",
1570: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
1571: "<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
1572: table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
1573: foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
1574: body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
1575: frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
1576: frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
1577: after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
1578: frameset</a>" during the course of the parsing, as described in
1579: the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
1580: how tokens are processed and whether CDATA sections are
1581: supported.</p>
1582:
1583: <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
1584: head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
1585: body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
1586: table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
1587: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
1588: "<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
1589: that the other modes defer to them at various times. When the
1590: algorithm below says that the user agent is to do something
1591: "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
1592: mode", where <var title="">m</var> is one of these modes, the user
1593: agent must use the rules described under the <var title="">m</var>
1594: <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
1595: <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>
1596: to a new value.</p>
1597:
1598: <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.91 mike 1599: 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 1600: <dfn id="original-insertion-mode">original insertion mode</dfn> is also set. This is the
1601: insertion mode to which the tree construction stage will return.</p>
1602:
1603: <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
1604: mode: in foreign content">in foreign content</a>", the
1605: <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
1606: is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
1607: foreign content">in foreign content</a>" mode to handle HTML
1608: (i.e. not foreign) content.</p>
1609:
1610: <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
1611: mode appropriately</dfn>, it means the UA must follow these
1612: steps:</p>
1613:
1614: <ol><li>Let <var title="">last</var> be false.</li>
1615:
1616: <li>Let <var title="">node</var> be the last node in the
1617: <a href="#stack-of-open-elements">stack of open elements</a>.</li>
1618:
1619: <li>If <var title="">node</var> is the first node in the stack of
1620: open elements, then set <var title="">last</var> to true and set
1621: <var title="">node</var> to the <var title="">context</var>
1622: element. (<a href="#fragment-case">fragment case</a>)</li>
1623:
1624: <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
1625: 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
1626: steps. (<a href="#fragment-case">fragment case</a>)</li>
1627:
1628: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
1629: <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
1630: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
1631: mode: in cell">in cell</a>" and abort these steps.</li>
1632:
1633: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
1634: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
1635: mode: in row">in row</a>" and abort these steps.</li>
1636:
1637: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
1638: <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
1639: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
1640: table body">in table body</a>" and abort these steps.</li>
1641:
1642: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
1643: 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
1644: these steps.</li>
1645:
1646: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
1647: 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
1648: abort these steps. (<a href="#fragment-case">fragment case</a>)</li>
1649:
1650: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
1651: 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
1652: steps.</li>
1653:
1654: <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
1655: namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then switch the
1656: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
1657: foreign content">in foreign content</a>", let the
1658: <a href="#secondary-insertion-mode">secondary insertion mode</a> be "<a href="#parsing-main-inbody" title="insertion
1659: mode: in body">in body</a>", and abort these steps.</li>
1660:
1.159 mike 1661: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element-0">head</a></code> element,
1.1 mike 1662: 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
1663: these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- This is only
1664: here for now in case people think that the spec accidentally
1665: omitted it and try to "fix" it. Note that noscript-in-head is also
1666: handled this way. This is all intentional. The only thing it
1667: doesn't handle is the scripting-disabled fragment parsing case for
1668: a <head> element containing a <noscript> which itself contains
1669: something other than a <link> or a <style> element; you'd expect
1670: that to break out of the <noscript> but it doesn't. This is an edge
1671: case that doesn't affect the spec, since the algorithm for fragment
1672: parsing is only used for innerHTML/outerHTML/insertAdjacentHTML(),
1.333 mike 1673: where we know scripting is enabled. -->
1.1 mike 1674:
1.159 mike 1675: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element-0">body</a></code> element,
1.1 mike 1676: 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
1677: steps.</li>
1678:
1.5 mike 1679: <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.1 mike 1680: 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
1681: these steps. (<a href="#fragment-case">fragment case</a>)</li>
1682:
1.159 mike 1683: <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element-0">html</a></code> element,
1.333 mike 1684: then <!--: if the <span><code title="">head</code> element
1685: pointer</span> is null,--> switch the <a href="#insertion-mode">insertion mode</a>
1686: to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before
1687: head</a>"<!--, otherwise, switch the <span>insertion mode</span>
1688: to "<span title="insertion mode: after head">after head</span>".-->
1689: Then, <!-- in either case, --> abort these steps. (<a href="#fragment-case">fragment
1690: case</a>)</li> <!-- if the head element pointer can ever be
1691: non-null when we're going through these steps, we'll need to
1692: uncomment out the commented-out bits -->
1.1 mike 1693:
1694: <li>If <var title="">last</var> is true, then switch the
1695: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
1696: body">in body</a>" and abort these steps. (<a href="#fragment-case">fragment
1697: case</a>)</li>
1698:
1699: <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
1700: elements</a>.</li>
1701:
1702: <li>Return to step 3.</li>
1703:
1704: </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5>
1705:
1706: <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
1707: stack grows downwards; the topmost node on the stack is the first
1708: one added to the stack, and the bottommost node of the stack is the
1709: most recently added node in the stack (notwithstanding when the
1710: stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
1711:
1712: <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
1713: html</a>" <a href="#insertion-mode">insertion mode</a> creates the
1.159 mike 1714: <code><a href="semantics.html#the-html-element-0">html</a></code> root element node, which is then added to the
1.1 mike 1715: stack.</p>
1716:
1717: <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
1.159 mike 1718: elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1 mike 1719: element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
1720: parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
1721: case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
1722: html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
1723:
1.159 mike 1724: <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 1725: node of the stack. It never gets popped off the stack.</p>
1726:
1727: <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
1728: stack.</p>
1729:
1730: <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
1731: element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
1732: 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
1733: open elements</a> (<a href="#fragment-case">fragment case</a>), then the
1734: <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
1.159 mike 1735: of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code> element).</p>
1.1 mike 1736:
1737: <p>Elements in the stack fall into the following categories:</p>
1738:
1739: <dl><dt><dfn id="special">Special</dfn></dt>
1740:
1741: <dd><p>The following HTML elements have varying levels of special
1742: 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>,
1743: <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 1744: <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.159 mike 1745: <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 1746: <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 1747: <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
1.422 mike 1748: <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>,
1749: <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>,
1750: <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>,
1751: <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>,
1752: <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>,
1753: <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>,
1754: <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>,
1755: <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>,
1756: (commented out because this isn't an element that can end up on the
1757: stack, so it doesn't matter) --> <code><a href="text-level-semantics.html#the-img-element">img</a></code>,
1758: <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>,
1759: <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>,
1760: <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>,
1761: <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>,
1762: <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>,
1763: <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>,
1764: <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>,
1765: <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>,
1766: <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>,
1767: <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 1768:
1769: <dt><dfn id="scoping">Scoping</dfn></dt>
1770: <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
1771: an element in scope">scopes</a> for various parts of the
1.5 mike 1772: 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 1773: <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>,
1774: <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 1775: <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
1776:
1777: <dt><dfn id="formatting">Formatting</dfn></dt>
1778: <dd><p>The following HTML elements are those that end up in the
1779: <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 1780: <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>,
1781: <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>,
1782: <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>,
1783: <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
1784: <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1 mike 1785:
1786: <dt><dfn id="phrasing">Phrasing</dfn></dt>
1787: <dd><p>All other elements found while parsing an HTML
1788: document.</p></dd>
1789:
1.234 mike 1790: </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
1791: specific scope</dfn> consisting of a list of element types <var title="">list</var> when the following algorithm terminates in a
1792: match state:</p>
1.1 mike 1793:
1794: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
1795: node</a> (the bottommost node of the stack).</p></li>
1796:
1797: <li><p>If <var title="">node</var> is the target node, terminate in
1798: a match state.</p></li>
1799:
1.234 mike 1800: <li><p>Otherwise, if <var title="">node</var> is one of the element
1801: types in <var title="">list</var>, terminate in a failure
1802: state.</p></li>
1.1 mike 1803:
1804: <li><p>Otherwise, set <var title="">node</var> to the previous
1805: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
1806: 2. (This will never fail, since the loop will always terminate in
1807: the previous step if the top of the stack — an
1.159 mike 1808: <code><a href="semantics.html#the-html-element-0">html</a></code> element — is reached.)</p></li>
1.1 mike 1809:
1.234 mike 1810: </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
1811: it <a href="#has-an-element-in-the-specific-scope">has an element in the specific scope</a> consisting
1812: of the following element types:</p>
1813:
1814: <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
1815: <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
1816: <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.) -->
1817: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
1818: <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
1819: <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
1820: <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
1821: <li><code><a href="obsolete.html#the-marquee-element">marquee</a></code> in the HTML namespace</li>
1822: <li><code><a href="text-level-semantics.html#the-object-element">object</a></code> in the HTML namespace</li>
1823: <li><code title="">foreignObject</code> in the SVG namespace</li>
1824: </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
1825: item scope</dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
1826: scope</a> consisting of the following element types:</p>
1827:
1828: <ul class="brief"><li>All the element types listed above for the <i><a href="#has-an-element-in-scope">has an element
1829: in scope</a></i> algorithm.</li>
1830: <li><code><a href="semantics.html#the-ol-element">ol</a></code> in the HTML namespace</li>
1831: <li><code><a href="semantics.html#the-ul-element">ul</a></code> in the HTML namespace</li>
1832: </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
1833: scope</em></dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
1834: scope</a> consisting of the following element types:</p>
1835:
1836: <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.) -->
1837: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
1838: </ul><p>Nothing happens if at any time any of the elements in the
1.1 mike 1839: <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
1840: or removed from, the <code>Document</code> tree. In particular, the
1841: stack is not changed in this situation. This can cause, amongst
1842: other strange effects, content to be appended to nodes that are no
1843: longer in the DOM.</p>
1844:
1845: <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
1846: the stack is manipulated in a random-access fashion.</p>
1847:
1848:
1849: <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5>
1850:
1851: <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
1852: empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
1853:
1854: <p>The list contains elements in the <a href="#formatting">formatting</a>
1855: category, and scope markers. The scope markers are inserted when
1.159 mike 1856: 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 1857: elements, marquees, table cells, and table captions, and are used to
1.5 mike 1858: prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.159 mike 1859: elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code> elements, marquees, and
1.1 mike 1860: tables.</p>
1861:
1862: <p class="note">The scope markers are unrelated to the concept of an
1863: element being <a href="#has-an-element-in-scope" title="has an element in scope">in
1864: scope</a>.</p>
1865:
1866: <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
1867: elements</a> is associated with the token for which it was
1868: created, so that further elements can be created for that token if
1869: necessary.</p>
1870:
1871: <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
1872: active formatting elements</dfn>, the UA must perform the following
1873: steps:</p>
1874:
1875: <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
1876: elements</a>, then there is nothing to reconstruct; stop this
1877: algorithm.</li>
1878:
1879: <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
1880: active formatting elements</a> is a marker, or if it is an
1881: element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
1882: there is nothing to reconstruct; stop this algorithm.</li>
1883:
1884: <li>Let <var title="">entry</var> be the last (most recently added)
1885: element in the <a href="#list-of-active-formatting-elements">list of active formatting
1886: elements</a>.</li>
1887:
1888: <li>If there are no entries before <var title="">entry</var> in the
1889: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
1890: 8.</li>
1891:
1892: <li>Let <var title="">entry</var> be the entry one earlier than
1893: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
1894: elements</a>.</li>
1895:
1896: <li>If <var title="">entry</var> is neither a marker nor an element
1897: that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
1898: 4.</li>
1899:
1900: <li>Let <var title="">entry</var> be the element one later than
1901: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
1902: elements</a>.</li>
1903:
1904: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
1905: element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
1906:
1907: <li>Append <var title="">new element</var> to the <a href="#current-node">current
1908: node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
1909: elements</a> so that it is the new <a href="#current-node">current
1910: node</a>.</li>
1911:
1912: <li>Replace the entry for <var title="">entry</var> in the list
1913: with an entry for <var title="">new element</var>.</li>
1914:
1915: <li>If the entry for <var title="">new element</var> in the
1916: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
1917: entry in the list, return to step 7.</li>
1918:
1919: </ol><p>This has the effect of reopening all the formatting elements that
1920: were opened in the current body, cell, or caption (whichever is
1921: youngest) that haven't been explicitly closed.</p>
1922:
1923: <p class="note">The way this specification is written, the
1924: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
1925: elements in chronological order with the least recently added
1926: element first and the most recently added element last (except for
1927: while steps 8 to 11 of the above algorithm are being executed, of
1928: course).</p>
1929:
1930: <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
1931: active formatting elements up to the last marker</dfn>, the UA must
1932: perform the following steps:</p>
1933:
1934: <ol><li>Let <var title="">entry</var> be the last (most recently added)
1935: entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
1936:
1937: <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
1938: formatting elements</a>.</li>
1939:
1940: <li>If <var title="">entry</var> was a marker, then stop the
1941: algorithm at this point. The list has been cleared up to the last
1942: marker.</li>
1943:
1944: <li>Go to step 1.</li>
1945:
1946: </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5>
1947:
1948: <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
1949: pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
1950: pointer</dfn> are both null.</p>
1951:
1.159 mike 1952: <p>Once a <code><a href="semantics.html#the-head-element-0">head</a></code> element has been parsed (whether
1.1 mike 1953: implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
1954: element pointer</a> gets set to point to this node.</p>
1955:
1956: <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
1957: points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
1958: whose end tag has not yet been seen. It is used to make form
1959: controls associate with forms in the face of dramatically bad
1960: markup, for historical reasons.</p>
1961:
1962:
1963: <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5>
1964:
1965: <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
1966: <code>Document</code> with which the parser is associated when the
1967: parser was created, and "disabled" otherwise.</p>
1968:
1969: <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
1970: when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
1971: parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
1972: don't execute in that case.</p>
1973:
1974: <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
1975: created. It is set to "not ok" after certain tokens are seen.</p>
1976:
1.266 mike 1977: </div><div class="impl">
1.1 mike 1978:
1.159 mike 1979: <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 1980:
1981: <p>Implementations must act as if they used the following state
1982: machine to tokenize HTML. The state machine must start in the
1983: <a href="#data-state">data state</a>. Most states consume a single character,
1984: which may have various side-effects, and either switches the state
1985: machine to a new state to <em>reconsume</em> the same character, or
1986: switches it to a new state (to consume the next character), or
1987: repeats the same state (to consume the next character). Some states
1988: have more complicated behavior and can consume several characters
1989: before switching to another state.</p>
1990:
1991: <p>The exact behavior of certain states depends on a <dfn id="content-model-flag">content
1992: model flag</dfn> that is set after certain tokens are emitted. The
1.91 mike 1993: 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
1994: state. In the RCDATA and RAWTEXT states, a further <dfn id="escape-flag">escape
1.1 mike 1995: flag</dfn> is used to control the behavior of the tokenizer. It is
1996: either true or false, and initially must be set to the false
1997: state. The <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
1998: elements</a> also affects tokenization.</p>
1999:
2000: <p>The output of the tokenization step is a series of zero or more
2001: of the following tokens: DOCTYPE, start tag, end tag, comment,
2002: character, end-of-file. DOCTYPE tokens have a name, a public
2003: identifier, a system identifier, and a <i>force-quirks
2004: flag</i>. When a DOCTYPE token is created, its name, public
2005: identifier, and system identifier must be marked as missing (which
2006: is a distinct state from the empty string), and the <i>force-quirks
2007: flag</i> must be set to <i>off</i> (its other state is
2008: <i>on</i>). Start and end tag tokens have a tag name, a
2009: <i>self-closing flag</i>, and a list of attributes, each of which
2010: has a name and a value. When a start or end tag token is created,
2011: its <i>self-closing flag</i> must be unset (its other state is that
2012: it be set), and its attributes list must be empty. Comment and
2013: character tokens have data.</p>
2014:
2015: <p>When a token is emitted, it must immediately be handled by the
2016: <a href="#tree-construction">tree construction</a> stage. The tree construction stage
2017: can affect the state of the <a href="#content-model-flag">content model flag</a>, and can
2018: insert additional characters into the stream. (For example, the
2019: <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
1.159 mike 2020: using the <a href="embedded-content-0.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
1.1 mike 2021: characters into the stream being tokenized.)</p>
2022:
2023: <p>When a start tag token is emitted with its <i>self-closing
2024: flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
2025: self-closing flag">acknowledged</dfn> when it is processed by the
2026: tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
2027:
2028: <p>When an end tag token is emitted, the <a href="#content-model-flag">content model
2029: flag</a> must be switched to the PCDATA state.</p>
2030:
2031: <p>When an end tag token is emitted with attributes, that is a
2032: <a href="#parse-error">parse error</a>.</p>
2033:
2034: <p>When an end tag token is emitted with its <i>self-closing
2035: flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
2036:
2037: <p>Before each step of the tokenizer, the user agent must first
2038: check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
2039: tokenizer must abort the processing of any nested invocations of the
2040: tokenizer, yielding control back to the caller. If it is false, then
2041: the user agent may then check to see if either one of the scripts in
2042: the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will execute as soon as
2043: possible</a> or the first script in the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts
2044: that will execute asynchronously</a>, has <a href="semantics.html#completed-loading">completed
2045: loading</a>. If one has, then it must be <a href="semantics.html#executing-a-script-block" title="executing a
2046: script block">executed</a> and removed from its list.</p>
2047:
2048: <p>The tokenizer state machine consists of the states defined in the
2049: following subsections.</p>
2050:
1.333 mike 2051: <!-- Order of the lists below is supposed to be non-error then
2052: error, by unicode, then EOF, ending with "anything else" -->
1.1 mike 2053:
2054: <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5>
2055:
2056: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2057:
2058: <dl class="switch"><dt>U+0026 AMPERSAND (&)</dt>
2059: <dd>When the <a href="#content-model-flag">content model flag</a> is set to one of the
2060: PCDATA or RCDATA states and the <a href="#escape-flag">escape flag</a> is
1.299 mike 2061: false: switch to the <a href="#character-reference-in-data-state">character reference in data
1.56 mike 2062: state</a>.</dd>
2063: <dd>Otherwise: treat it as per the "anything else" entry
2064: below.</dd>
1.1 mike 2065:
2066: <dt>U+002D HYPHEN-MINUS (-)</dt>
2067: <dd>
2068:
2069: <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 2070: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1 mike 2071: is false, and there are at least three characters before this
2072: one in the input stream, and the last four characters in the
2073: input stream, including this one, are U+003C LESS-THAN SIGN,
2074: U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, and U+002D
2075: HYPHEN-MINUS ("<!--"), then set the <a href="#escape-flag">escape flag</a>
2076: to true.</p>
2077:
2078: <p>In any case, emit the input character as a character
2079: token. Stay in the <a href="#data-state">data state</a>.</p>
2080:
2081: </dd>
2082:
2083: <dt>U+003C LESS-THAN SIGN (<)</dt>
2084: <dd>When the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
2085: state: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
2086: <dd>When the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 2087: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1 mike 2088: is false: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
2089: <dd>Otherwise: treat it as per the "anything else" entry
2090: below.</dd>
2091:
2092: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2093: <dd>
2094:
2095: <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 2096: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape
1.1 mike 2097: flag</a> is true, and the last three characters in the input
2098: stream including this one are U+002D HYPHEN-MINUS, U+002D
2099: HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("-->"), set the
2100: <a href="#escape-flag">escape flag</a> to false.</p> <!-- no need to check
2101: that there are enough characters, since you can only run into
2102: this if the flag is true in the first place, which requires four
2103: characters. -->
2104:
2105: <p>In any case, emit the input character as a character
2106: token. Stay in the <a href="#data-state">data state</a>.</p>
2107:
2108: </dd>
2109:
2110: <dt>EOF</dt>
2111: <dd>Emit an end-of-file token.</dd>
2112:
2113: <dt>Anything else</dt>
2114: <dd>Emit the input character as a character token. Stay in the
2115: <a href="#data-state">data state</a>.</dd>
2116:
1.299 mike 2117: </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 2118:
2119: <p><i>(This cannot happen if the <a href="#content-model-flag">content model flag</a>
1.91 mike 2120: is set to the RAWTEXT state.)</i></p>
1.1 mike 2121:
2122: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
2123: <a href="#additional-allowed-character">additional allowed character</a>.</p>
2124:
2125: <p>If nothing is returned, emit a U+0026 AMPERSAND character
2126: token.</p>
2127:
2128: <p>Otherwise, emit the character token that was returned.</p>
2129:
2130: <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
2131:
2132:
2133: <h5 id="tag-open-state"><span class="secno">9.2.4.3 </span><dfn>Tag open state</dfn></h5>
2134:
2135: <p>The behavior of this state depends on the <a href="#content-model-flag">content model
2136: flag</a>.</p>
2137:
2138: <dl><dt>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA
1.91 mike 2139: or RAWTEXT states</dt>
1.1 mike 2140:
2141: <dd>
2142:
2143: <p>Consume the <a href="#next-input-character">next input character</a>. If it is a
2144: U+002F SOLIDUS (/) character, switch to the <a href="#close-tag-open-state">close tag open
2145: state</a>. Otherwise, emit a U+003C LESS-THAN SIGN character
2146: token and reconsume the <a href="#current-input-character">current input character</a> in the
2147: <a href="#data-state">data state</a>.</p>
2148:
2149: </dd>
2150:
2151: <dt>If the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
2152: state</dt>
2153:
2154: <dd>
2155:
2156: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2157:
2158: <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
2159: <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
2160:
2161: <dt>U+002F SOLIDUS (/)</dt>
2162: <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
2163:
2164: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2165: <dd>Create a new start tag token, set its tag name to the
2166: lowercase version of the input character (add 0x0020 to the
2167: character's code point), then switch to the <a href="#tag-name-state">tag name
2168: state</a>. (Don't emit the token yet; further details will
2169: be filled in before it is emitted.)</dd>
2170:
2171: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2172: <dd>Create a new start tag token, set its tag name to the input
2173: character, then switch to the <a href="#tag-name-state">tag name
2174: state</a>. (Don't emit the token yet; further details will
2175: be filled in before it is emitted.)</dd>
2176:
2177: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2178: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2179: character token and a U+003E GREATER-THAN SIGN character
2180: token. Switch to the <a href="#data-state">data state</a>.</dd>
2181:
2182: <dt>U+003F QUESTION MARK (?)</dt>
2183: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2184: comment state</a>.</dd>
2185:
2186: <dt>Anything else</dt>
2187: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2188: character token and reconsume the <a href="#current-input-character">current input character</a> in the
2189: <a href="#data-state">data state</a>.</dd>
2190:
2191: </dl></dd>
2192:
2193: </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.4 </span><dfn>Close tag open state</dfn></h5>
2194:
2195: <p>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA or
1.91 mike 2196: RAWTEXT states but no start tag token has ever been emitted by this
1.1 mike 2197: instance of the tokenizer (<a href="#fragment-case">fragment case</a>), or, if the
1.91 mike 2198: <a href="#content-model-flag">content model flag</a> is set to the RCDATA or RAWTEXT states
1.1 mike 2199: and the next few characters do not match the tag name of the last
2200: start tag token emitted (compared in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2201: case-insensitive</a> manner), or if they do but they are not
2202: immediately followed by one of the following characters:</p>
2203:
2204: <ul class="brief"><li>U+0009 CHARACTER TABULATION</li>
2205: <li>U+000A LINE FEED (LF)</li>
2206: <li>U+000C FORM FEED (FF)</li>
2207: <!--<li>U+000D CARRIAGE RETURN (CR)</li>-->
2208: <li>U+0020 SPACE</li>
2209: <li>U+003E GREATER-THAN SIGN (>)</li>
2210: <li>U+002F SOLIDUS (/)</li>
2211: <li>EOF</li>
2212: </ul><p>...then emit a U+003C LESS-THAN SIGN character token, a U+002F
2213: SOLIDUS character token, and switch to the <a href="#data-state">data state</a>
2214: to process the <a href="#next-input-character">next input character</a>.</p>
2215:
2216: <p>Otherwise, if the <a href="#content-model-flag">content model flag</a> is set to the
2217: PCDATA state, or if the next few characters <em>do</em> match that tag
2218: name, consume the <a href="#next-input-character">next input character</a>:</p>
2219:
2220: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2221: <dd>Create a new end tag token, set its tag name to the lowercase
2222: version of the input character (add 0x0020 to the character's
2223: code point), then switch to the <a href="#tag-name-state">tag name
2224: state</a>. (Don't emit the token yet; further details will be
2225: filled in before it is emitted.)</dd>
2226:
2227: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2228: <dd>Create a new end tag token, set its tag name to the input
2229: character, then switch to the <a href="#tag-name-state">tag name state</a>. (Don't
2230: emit the token yet; further details will be filled in before it
2231: is emitted.)</dd>
2232:
2233: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2234: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
2235: state</a>.</dd>
2236:
2237: <dt>EOF</dt>
2238: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2239: character token and a U+002F SOLIDUS character token. Reconsume
2240: the EOF character in the <a href="#data-state">data state</a>.</dd>
2241:
2242: <dt>Anything else</dt>
2243: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2244: comment state</a>.</dd>
2245:
2246: </dl><h5 id="tag-name-state"><span class="secno">9.2.4.5 </span><dfn>Tag name state</dfn></h5>
2247:
2248: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2249:
2250: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2251: <dt>U+000A LINE FEED (LF)</dt>
2252: <dt>U+000C FORM FEED (FF)</dt>
2253: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2254: <dt>U+0020 SPACE</dt>
2255: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2256:
2257: <dt>U+002F SOLIDUS (/)</dt>
2258: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2259:
2260: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2261: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2262: state</a>.</dd>
2263:
2264: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2265: <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
2266: (add 0x0020 to the character's code point) to the current tag
2267: token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
2268:
2269: <dt>EOF</dt>
2270: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2271: <a href="#data-state">data state</a>.</dd>
2272:
2273: <dt>Anything else</dt>
2274: <dd>Append the <a href="#current-input-character">current input character</a> to the current tag token's
2275: tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
2276:
2277: </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.6 </span><dfn>Before attribute name state</dfn></h5>
2278:
2279: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2280:
2281: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2282: <dt>U+000A LINE FEED (LF)</dt>
2283: <dt>U+000C FORM FEED (FF)</dt>
2284: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2285: <dt>U+0020 SPACE</dt>
2286: <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2287:
2288: <dt>U+002F SOLIDUS (/)</dt>
2289: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2290:
2291: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2292: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2293: state</a>.</dd>
2294:
2295: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2296: <dd>Start a new attribute in the current tag token. Set that
2297: attribute's name to the lowercase version of the <a href="#current-input-character">current input
2298: character</a> (add 0x0020 to the character's code point), and its
2299: value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
2300: state</a>.</dd>
2301:
2302: <dt>U+0022 QUOTATION MARK (")</dt>
2303: <dt>U+0027 APOSTROPHE (')</dt>
2304: <dt>U+003C LESS-THAN SIGN (<)</dt>
2305: <dt>U+003D EQUALS SIGN (=)</dt>
2306: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2307: entry below.</dd>
2308:
2309: <dt>EOF</dt>
2310: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2311: <a href="#data-state">data state</a>.</dd>
2312:
2313: <dt>Anything else</dt>
2314: <dd>Start a new attribute in the current tag token. Set that
2315: attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
2316: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2317: state</a>.</dd>
2318:
2319: </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.7 </span><dfn>Attribute name state</dfn></h5>
2320:
2321: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2322:
2323: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2324: <dt>U+000A LINE FEED (LF)</dt>
2325: <dt>U+000C FORM FEED (FF)</dt>
2326: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2327: <dt>U+0020 SPACE</dt>
2328: <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
2329:
2330: <dt>U+002F SOLIDUS (/)</dt>
2331: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2332:
2333: <dt>U+003D EQUALS SIGN (=)</dt>
2334: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2335:
2336: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2337: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2338: state</a>.</dd>
2339:
2340: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2341: <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
2342: (add 0x0020 to the character's code point) to the current
2343: attribute's name. Stay in the <a href="#attribute-name-state">attribute name
2344: state</a>.</dd>
2345:
2346: <dt>U+0022 QUOTATION MARK (")</dt>
2347: <dt>U+0027 APOSTROPHE (')</dt>
2348: <dt>U+003C LESS-THAN SIGN (<)</dt>
2349: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2350: entry below.</dd>
2351:
2352: <dt>EOF</dt>
2353: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2354: <a href="#data-state">data state</a>.</dd>
2355:
2356: <dt>Anything else</dt>
2357: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2358: name. Stay in the <a href="#attribute-name-state">attribute name state</a>.</dd>
2359:
2360: </dl><p>When the user agent leaves the attribute name state (and before
2361: emitting the tag token, if appropriate), the complete attribute's
2362: name must be compared to the other attributes on the same token;
2363: if there is already an attribute on the token with the exact same
2364: name, then this is a <a href="#parse-error">parse error</a> and the new
2365: attribute must be dropped, along with the value that gets
2366: associated with it (if any).</p>
2367:
2368:
2369: <h5 id="after-attribute-name-state"><span class="secno">9.2.4.8 </span><dfn>After attribute name state</dfn></h5>
2370:
2371: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2372:
2373: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2374: <dt>U+000A LINE FEED (LF)</dt>
2375: <dt>U+000C FORM FEED (FF)</dt>
2376: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2377: <dt>U+0020 SPACE</dt>
2378: <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
2379:
2380: <dt>U+002F SOLIDUS (/)</dt>
2381: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2382:
2383: <dt>U+003D EQUALS SIGN (=)</dt>
2384: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2385:
2386: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2387: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2388: state</a>.</dd>
2389:
2390: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2391: <dd>Start a new attribute in the current tag token. Set that
2392: attribute's name to the lowercase version of the <a href="#current-input-character">current input character</a>
2393: (add 0x0020 to the character's code point), and its value to
2394: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2395: state</a>.</dd>
2396:
2397: <dt>U+0022 QUOTATION MARK (")</dt>
2398: <dt>U+0027 APOSTROPHE (')</dt>
2399: <dt>U+003C LESS-THAN SIGN (<)</dt>
2400: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2401: entry below.</dd>
2402:
2403: <dt>EOF</dt>
2404: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2405: <a href="#data-state">data state</a>.</dd>
2406:
2407: <dt>Anything else</dt>
2408: <dd>Start a new attribute in the current tag token. Set that
2409: attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
2410: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2411: state</a>.</dd>
2412:
2413: </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.9 </span><dfn>Before attribute value state</dfn></h5>
2414:
2415: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2416:
2417: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2418: <dt>U+000A LINE FEED (LF)</dt>
2419: <dt>U+000C FORM FEED (FF)</dt>
2420: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2421: <dt>U+0020 SPACE</dt>
2422: <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2423:
2424: <dt>U+0022 QUOTATION MARK (")</dt>
2425: <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
2426:
2427: <dt>U+0026 AMPERSAND (&)</dt>
2428: <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
2429: and reconsume this input character.</dd>
2430:
2431: <dt>U+0027 APOSTROPHE (')</dt>
2432: <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
2433:
2434: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2435: <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
2436: the <a href="#data-state">data state</a>.</dd>
2437:
2438: <dt>U+003C LESS-THAN SIGN (<)</dt>
2439: <dt>U+003D EQUALS SIGN (=)</dt>
2440: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2441: entry below.</dd>
2442:
2443: <dt>EOF</dt>
2444: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2445: <a href="#data-state">data state</a>.</dd>
2446:
2447: <dt>Anything else</dt>
2448: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2449: attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
2450: state</a>.</dd>
2451:
2452: </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.10 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
2453:
2454: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2455:
2456: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
2457: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
2458: state</a>.</dd>
2459:
2460: <dt>U+0026 AMPERSAND (&)</dt>
2461: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
2462: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2463: being U+0022 QUOTATION MARK (").</dd>
2464:
2465: <dt>EOF</dt>
2466: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2467: <a href="#data-state">data state</a>.</dd>
2468:
2469: <dt>Anything else</dt>
2470: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2471: value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted)
2472: state</a>.</dd>
2473:
2474: </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.11 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
2475:
2476: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2477:
2478: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
2479: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
2480: state</a>.</dd>
2481:
2482: <dt>U+0026 AMPERSAND (&)</dt>
2483: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
2484: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2485: being U+0027 APOSTROPHE (').</dd>
2486:
2487: <dt>EOF</dt>
2488: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2489: <a href="#data-state">data state</a>.</dd>
2490:
2491: <dt>Anything else</dt>
2492: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2493: value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted)
2494: state</a>.</dd>
2495:
2496: </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.12 </span><dfn>Attribute value (unquoted) state</dfn></h5>
2497:
2498: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2499:
2500: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2501: <dt>U+000A LINE FEED (LF)</dt>
2502: <dt>U+000C FORM FEED (FF)</dt>
2503: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2504: <dt>U+0020 SPACE</dt>
2505: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2506:
2507: <dt>U+0026 AMPERSAND (&)</dt>
2508: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
1.299 mike 2509: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2510: being U+003E GREATER-THAN SIGN (>).</dd>
1.1 mike 2511:
2512: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2513: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2514: state</a>.</dd>
2515:
2516: <dt>U+0022 QUOTATION MARK (")</dt>
2517: <dt>U+0027 APOSTROPHE (')</dt>
2518: <dt>U+003C LESS-THAN SIGN (<)</dt>
2519: <dt>U+003D EQUALS SIGN (=)</dt>
2520: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2521: entry below.</dd>
2522:
2523: <dt>EOF</dt>
2524: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2525: <a href="#data-state">data state</a>.</dd>
2526:
2527: <dt>Anything else</dt>
2528: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2529: value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
2530: state</a>.</dd>
2531:
2532: </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>
2533:
2534: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
2535:
2536: <p>If nothing is returned, append a U+0026 AMPERSAND character to
2537: the current attribute's value.</p>
2538:
2539: <p>Otherwise, append the returned character token to the current
2540: attribute's value.</p>
2541:
2542: <p>Finally, switch back to the attribute value state that you were
2543: in when were switched into this state.</p>
2544:
2545:
2546: <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.14 </span><dfn>After attribute value (quoted) state</dfn></h5>
2547:
2548: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2549:
2550: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2551: <dt>U+000A LINE FEED (LF)</dt>
2552: <dt>U+000C FORM FEED (FF)</dt>
2553: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2554: <dt>U+0020 SPACE</dt>
2555: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2556:
2557: <dt>U+002F SOLIDUS (/)</dt>
2558: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2559:
2560: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2561: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2562: state</a>.</dd>
2563:
2564: <dt>EOF</dt>
2565: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2566: <a href="#data-state">data state</a>.</dd>
2567:
2568: <dt>Anything else</dt>
2569: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
2570: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2571:
2572: </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.15 </span><dfn>Self-closing start tag state</dfn></h5>
2573:
2574: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2575:
2576: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2577: <dd>Set the <i>self-closing flag</i> of the current tag
2578: token. Emit the current tag token. Switch to the <a href="#data-state">data
2579: state</a>.</dd>
2580:
2581: <dt>EOF</dt>
2582: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2583: <a href="#data-state">data state</a>.</dd>
2584:
2585: <dt>Anything else</dt>
2586: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
2587: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2588:
2589: </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.16 </span><dfn>Bogus comment state</dfn></h5>
2590:
2591: <p><i>(This can only happen if the <a href="#content-model-flag">content model
2592: flag</a> is set to the PCDATA state.)</i></p>
2593:
2594: <p>Consume every character up to and including the first U+003E
2595: GREATER-THAN SIGN character (>) or the end of the file (EOF),
2596: whichever comes first. Emit a comment token whose data is the
2597: concatenation of all the characters starting from and including
2598: the character that caused the state machine to switch into the
2599: bogus comment state, up to and including the character immediately
2600: before the last consumed character (i.e. up to the character just
2601: before the U+003E or EOF character). (If the comment was started
2602: by the end of the file (EOF), the token is empty.)</p>
2603:
2604: <p>Switch to the <a href="#data-state">data state</a>.</p>
2605:
2606: <p>If the end of the file was reached, reconsume the EOF
2607: character.</p>
2608:
2609:
2610: <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.17 </span><dfn>Markup declaration open state</dfn></h5>
2611:
2612: <p><i>(This can only happen if the <a href="#content-model-flag">content model
2613: flag</a> is set to the PCDATA state.)</i></p>
2614:
2615: <p>If the next two characters are both U+002D HYPHEN-MINUS (-)
2616: characters, consume those two characters, create a comment token
2617: whose data is the empty string, and switch to the <a href="#comment-start-state">comment
2618: start state</a>.</p>
2619:
2620: <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2621: case-insensitive</a> match for the word "DOCTYPE", then consume
2622: those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
2623:
2624: <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
2625: content</a>" and the <a href="#current-node">current node</a> is not an element
2626: in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
2627: an <span>ASCII case-sensitive</span> match for the string "[CDATA["
2628: (the five uppercase letters "CDATA" with a U+005B LEFT SQUARE
2629: BRACKET character before and after), then consume those characters
1.91 mike 2630: and switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1 mike 2631:
2632: <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
2633: <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
2634: consumed, if any, is the first character that will be in the
2635: comment.</p>
2636:
2637:
2638: <h5 id="comment-start-state"><span class="secno">9.2.4.18 </span><dfn>Comment start state</dfn></h5>
2639:
2640: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2641:
2642: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2643: <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
2644:
2645: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2646: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
2647: <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
2648: -->
2649:
2650: <dt>EOF</dt>
2651: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2652: the EOF character in the <a href="#data-state">data state</a>.</dd>
2653:
2654: <dt>Anything else</dt>
2655: <dd>Append the input character to the comment token's
2656: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
2657:
2658: </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.19 </span><dfn>Comment start dash state</dfn></h5>
2659:
2660: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2661:
2662: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2663: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
2664:
2665: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2666: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
2667: the <a href="#data-state">data state</a>.</dd>
2668:
2669: <dt>EOF</dt>
2670: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2671: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2672: in comment end state -->
2673:
2674: <dt>Anything else</dt>
2675: <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
2676: character to the comment token's data. Switch to the
2677: <a href="#comment-state">comment state</a>.</dd>
2678:
2679: </dl><h5 id="comment-state"><span class="secno">9.2.4.20 </span><dfn id="comment">Comment state</dfn></h5>
2680:
2681: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2682:
2683: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2684: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
2685:
2686: <dt>EOF</dt>
2687: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2688: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2689: in comment end state -->
2690:
2691: <dt>Anything else</dt>
2692: <dd>Append the input character to the comment token's data. Stay
2693: in the <a href="#comment-state">comment state</a>.</dd>
2694:
2695: </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.21 </span><dfn>Comment end dash state</dfn></h5>
2696:
2697: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2698:
2699: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2700: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
2701:
2702: <dt>EOF</dt>
2703: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2704: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2705: in comment end state -->
2706:
2707: <dt>Anything else</dt>
2708: <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
2709: character to the comment token's data. Switch to the
2710: <a href="#comment-state">comment state</a>.</dd>
2711:
2712: </dl><h5 id="comment-end-state"><span class="secno">9.2.4.22 </span><dfn>Comment end state</dfn></h5>
2713:
2714: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2715:
2716: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2717: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2718: state</a>.</dd>
2719:
2720: <dt>U+0009 CHARACTER TABULATION</dt>
2721: <dt>U+000A LINE FEED (LF)</dt>
2722: <dt>U+000C FORM FEED (FF)</dt>
2723: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2724: <dt>U+0020 SPACE</dt>
2725: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
2726: characters and the input character to the comment token's
2727: data. Switch to the <a href="#comment-end-space-state">comment end space state</a>.</dd>
2728:
2729: <dt>U+0021 EXCLAMATION MARK (!)</dt>
2730: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
2731: state</a>.</dd>
2732:
1.333 mike 2733: <dt>U+002D HYPHEN-MINUS (-)</dt>
2734: <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
2735: (-) character to the comment token's data. Stay in the
2736: <a href="#comment-end-state">comment end state</a>.</dd>
2737:
1.1 mike 2738: <dt>EOF</dt>
2739: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2740: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
2741: security reasons: otherwise, hostile user could put a <script> in
2742: a comment e.g. in a blog comment and then DOS the server so that
2743: the end tag isn't read, and then the commented <script> tag would
2744: be treated as live code -->
2745:
2746: <dt>Anything else</dt>
2747: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
2748: characters and the input character to the comment token's
2749: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
2750:
2751: </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.23 </span><dfn>Comment end bang state</dfn></h5>
2752:
2753: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2754:
1.333 mike 2755: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
1.1 mike 2756: <dd>Append two U+002D HYPHEN-MINUS (-) characters and a U+0021
2757: EXCLAMATION MARK (!) character to the comment token's data. Switch
2758: to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
2759:
1.333 mike 2760: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2761: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2762: state</a>.</dd>
2763:
1.1 mike 2764: <dt>EOF</dt>
2765: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2766: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
2767: comment in comment end state -->
2768:
2769: <dt>Anything else</dt>
2770: <dd>Append two U+002D HYPHEN-MINUS (-) characters, a U+0021
2771: EXCLAMATION MARK (!) character, and the input character to the
2772: comment token's data. Switch to the <a href="#comment-state">comment
2773: state</a>.</dd>
2774:
2775: </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.24 </span><dfn>Comment end space state</dfn></h5>
2776:
2777: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2778:
1.333 mike 2779: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
1.1 mike 2780: <dt>U+000A LINE FEED (LF)</dt>
2781: <dt>U+000C FORM FEED (FF)</dt>
2782: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2783: <dt>U+0020 SPACE</dt>
2784: <dd>Append the input character to the comment token's data. Stay in
2785: the <a href="#comment-end-space-state">comment end space state</a>.</dd>
2786:
1.333 mike 2787: <dt>U+002D HYPHEN-MINUS (-)</dt>
2788: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
2789:
2790: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2791: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2792: state</a>.</dd>
2793:
1.1 mike 2794: <dt>EOF</dt>
2795: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2796: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
2797: comment in comment end state -->
2798:
2799: <dt>Anything else</dt>
2800: <dd>Append the input character to the comment token's data. Switch
2801: to the <a href="#comment-state">comment state</a>.</dd>
2802:
2803: </dl><h5 id="doctype-state"><span class="secno">9.2.4.25 </span><dfn>DOCTYPE state</dfn></h5>
2804:
2805: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2806:
2807: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2808: <dt>U+000A LINE FEED (LF)</dt>
2809: <dt>U+000C FORM FEED (FF)</dt>
2810: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2811: <dt>U+0020 SPACE</dt>
2812: <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2813:
2814: <dt>EOF</dt>
2815: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2816: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
2817: the EOF character in the <a href="#data-state">data state</a>.</dd>
2818:
2819: <dt>Anything else</dt>
2820: <dd><a href="#parse-error">Parse error</a>. Reconsume the current
2821: character in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2822:
2823: </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.26 </span><dfn>Before DOCTYPE name state</dfn></h5>
2824:
2825: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2826:
2827: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2828: <dt>U+000A LINE FEED (LF)</dt>
2829: <dt>U+000C FORM FEED (FF)</dt>
2830: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2831: <dt>U+0020 SPACE</dt>
2832: <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2833:
2834: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2835: <dd>Create a new DOCTYPE token. Set the token's name to the
2836: lowercase version of the input character (add 0x0020 to the
2837: character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
2838: state</a>.</dd>
2839:
1.333 mike 2840: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2841: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2842: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
2843: the <a href="#data-state">data state</a>.</dd>
2844:
1.1 mike 2845: <dt>EOF</dt>
2846: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2847: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
2848: the EOF character in the <a href="#data-state">data state</a>.</dd>
2849:
2850: <dt>Anything else</dt>
2851: <dd>Create a new DOCTYPE token. Set the token's name to the
2852: <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
2853: state</a>.</dd>
2854:
2855: </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.27 </span><dfn>DOCTYPE name state</dfn></h5>
2856:
2857: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2858:
2859: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2860: <dt>U+000A LINE FEED (LF)</dt>
2861: <dt>U+000C FORM FEED (FF)</dt>
2862: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2863: <dt>U+0020 SPACE</dt>
2864: <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
2865:
2866: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2867: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
2868: state</a>.</dd>
2869:
2870: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2871: <dd>Append the lowercase version of the input character (add 0x0020
2872: to the character's code point) to the current DOCTYPE token's
2873: name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
2874:
2875: <dt>EOF</dt>
2876: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2877: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2878: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2879:
2880: <dt>Anything else</dt>
2881: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
2882: token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
2883:
2884: </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.28 </span><dfn>After DOCTYPE name state</dfn></h5>
2885:
2886: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2887:
2888: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2889: <dt>U+000A LINE FEED (LF)</dt>
2890: <dt>U+000C FORM FEED (FF)</dt>
2891: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2892: <dt>U+0020 SPACE</dt>
2893: <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
2894:
2895: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2896: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
2897: state</a>.</dd>
2898:
2899: <dt>EOF</dt>
2900: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2901: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2902: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2903:
2904: <dt>Anything else</dt>
2905: <dd>
2906:
2907: <p>If the six characters starting from the <a href="#current-input-character">current input
2908: character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
2909: for the word "PUBLIC", then consume those characters and switch to
1.444 mike 2910: the <a href="#after-doctype-public-keyword-state">after DOCTYPE public keyword state</a>.</p>
1.1 mike 2911:
2912: <p>Otherwise, if the six characters starting from the
2913: <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2914: case-insensitive</a> match for the word "SYSTEM", then consume
1.444 mike 2915: those characters and switch to the <a href="#after-doctype-system-keyword-state">after DOCTYPE system
2916: keyword state</a>.</p>
1.1 mike 2917:
2918: <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
2919: DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
2920: the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
2921:
2922: </dd>
2923:
1.444 mike 2924: </dl><h5 id="after-doctype-public-keyword-state"><span class="secno">9.2.4.29 </span><dfn>After DOCTYPE public keyword state</dfn></h5>
2925:
2926: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2927:
2928: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2929: <dt>U+000A LINE FEED (LF)</dt>
2930: <dt>U+000C FORM FEED (FF)</dt>
2931: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2932: <dt>U+0020 SPACE</dt>
2933: <dd>Switch to the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier
2934: state</a>.</dd>
2935:
2936: <dt>EOF</dt>
2937: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2938: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2939: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2940:
2941: <dt>Anything else</dt>
2942: <dd><a href="#parse-error">Parse error</a>. Reconsume the current character in
2943: the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
2944:
2945: </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 2946:
2947: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2948:
2949: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2950: <dt>U+000A LINE FEED (LF)</dt>
2951: <dt>U+000C FORM FEED (FF)</dt>
2952: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2953: <dt>U+0020 SPACE</dt>
2954: <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
2955:
2956: <dt>U+0022 QUOTATION MARK (")</dt>
2957: <dd>Set the DOCTYPE token's public identifier to the empty string
2958: (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
2959: (double-quoted) state</a>.</dd>
2960:
2961: <dt>U+0027 APOSTROPHE (')</dt>
2962: <dd>Set the DOCTYPE token's public identifier to the empty string
2963: (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
2964: (single-quoted) state</a>.</dd>
2965:
2966: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2967: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2968: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2969: token. Switch to the <a href="#data-state">data state</a>.</dd>
2970:
2971: <dt>EOF</dt>
2972: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2973: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2974: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2975:
2976: <dt>Anything else</dt>
2977: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2978: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
2979: DOCTYPE state</a>.</dd>
2980:
1.444 mike 2981: </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 2982:
2983: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2984:
2985: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
2986: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
2987:
2988: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2989: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2990: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2991: token. Switch to the <a href="#data-state">data state</a>.</dd>
2992:
2993: <dt>EOF</dt>
2994: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2995: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2996: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2997:
2998: <dt>Anything else</dt>
2999: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3000: token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
3001: identifier (double-quoted) state</a>.</dd>
3002:
1.444 mike 3003: </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 3004:
3005: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3006:
3007: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
3008: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
3009:
3010: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3011: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3012: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3013: token. Switch to the <a href="#data-state">data state</a>.</dd>
3014:
3015: <dt>EOF</dt>
3016: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3017: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3018: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3019:
3020: <dt>Anything else</dt>
3021: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3022: token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
3023: identifier (single-quoted) state</a>.</dd>
3024:
1.444 mike 3025: </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 3026:
3027: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3028:
3029: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3030: <dt>U+000A LINE FEED (LF)</dt>
3031: <dt>U+000C FORM FEED (FF)</dt>
3032: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3033: <dt>U+0020 SPACE</dt>
1.444 mike 3034: <dd>Switch to the <a href="#between-doctype-public-and-system-identifiers-state">between DOCTYPE public and system identifiers state</a>.</dd>
3035:
3036: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3037: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3038: state</a>.</dd>
3039:
3040: <dt>U+0022 QUOTATION MARK (")</dt>
3041: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
3042: identifier to the empty string (not missing), then switch to the
3043: <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier (double-quoted) state</a>.</dd>
3044:
3045: <dt>U+0027 APOSTROPHE (')</dt>
3046: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
3047: identifier to the empty string (not missing), then switch to the
3048: <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier (single-quoted) state</a>.</dd>
3049:
3050: <dt>EOF</dt>
3051: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3052: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3053: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3054:
3055: <dt>Anything else</dt>
3056: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3057: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3058: DOCTYPE state</a>.</dd>
3059:
3060: </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>
3061:
3062: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3063:
3064: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3065: <dt>U+000A LINE FEED (LF)</dt>
3066: <dt>U+000C FORM FEED (FF)</dt>
3067: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3068: <dt>U+0020 SPACE</dt>
3069: <dd>Stay in the <a href="#between-doctype-public-and-system-identifiers-state">between DOCTYPE public and system identifiers state</a>.</dd>
3070:
3071: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3072: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3073: state</a>.</dd>
1.1 mike 3074:
3075: <dt>U+0022 QUOTATION MARK (")</dt>
3076: <dd>Set the DOCTYPE token's system identifier to the empty string
3077: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
3078: (double-quoted) state</a>.</dd>
3079:
3080: <dt>U+0027 APOSTROPHE (')</dt>
3081: <dd>Set the DOCTYPE token's system identifier to the empty string
3082: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
3083: (single-quoted) state</a>.</dd>
3084:
3085: <dt>EOF</dt>
3086: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3087: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3088: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3089:
3090: <dt>Anything else</dt>
3091: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3092: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3093: DOCTYPE state</a>.</dd>
3094:
1.444 mike 3095: </dl><h5 id="after-doctype-system-keyword-state"><span class="secno">9.2.4.35 </span><dfn>After DOCTYPE system keyword state</dfn></h5>
3096:
3097: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3098:
3099: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3100: <dt>U+000A LINE FEED (LF)</dt>
3101: <dt>U+000C FORM FEED (FF)</dt>
3102: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3103: <dt>U+0020 SPACE</dt>
3104: <dd>Switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier
3105: state</a>.</dd>
3106:
3107: <dt>EOF</dt>
3108: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3109: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3110: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3111:
3112: <dt>Anything else</dt>
3113: <dd><a href="#parse-error">Parse error</a>. Reconsume the current character in
3114: the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
3115:
3116: </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 3117:
3118: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3119:
3120: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3121: <dt>U+000A LINE FEED (LF)</dt>
3122: <dt>U+000C FORM FEED (FF)</dt>
3123: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3124: <dt>U+0020 SPACE</dt>
3125: <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
3126:
3127: <dt>U+0022 QUOTATION MARK (")</dt>
3128: <dd>Set the DOCTYPE token's system identifier to the empty string
3129: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
3130: (double-quoted) state</a>.</dd>
3131:
3132: <dt>U+0027 APOSTROPHE (')</dt>
3133: <dd>Set the DOCTYPE token's system identifier to the empty string
3134: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
3135: (single-quoted) state</a>.</dd>
3136:
3137: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3138: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3139: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3140: token. Switch to the <a href="#data-state">data state</a>.</dd>
3141:
3142: <dt>EOF</dt>
3143: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3144: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3145: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3146:
3147: <dt>Anything else</dt>
3148: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3149: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3150: DOCTYPE state</a>.</dd>
3151:
1.444 mike 3152: </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 3153:
3154: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3155:
3156: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
3157: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
3158:
3159: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3160: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3161: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3162: token. Switch to the <a href="#data-state">data state</a>.</dd>
3163:
3164: <dt>EOF</dt>
3165: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3166: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3167: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3168:
3169: <dt>Anything else</dt>
3170: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3171: token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
3172: identifier (double-quoted) state</a>.</dd>
3173:
1.444 mike 3174: </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 3175:
3176: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3177:
3178: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
3179: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
3180:
3181: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3182: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3183: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3184: token. Switch to the <a href="#data-state">data state</a>.</dd>
3185:
3186: <dt>EOF</dt>
3187: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3188: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3189: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3190:
3191: <dt>Anything else</dt>
3192: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3193: token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
3194: identifier (single-quoted) state</a>.</dd>
3195:
1.444 mike 3196: </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 3197:
3198: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3199:
3200: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3201: <dt>U+000A LINE FEED (LF)</dt>
3202: <dt>U+000C FORM FEED (FF)</dt>
3203: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3204: <dt>U+0020 SPACE</dt>
3205: <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
3206:
3207: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3208: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3209: state</a>.</dd>
3210:
3211: <dt>EOF</dt>
3212: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3213: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3214: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3215:
3216: <dt>Anything else</dt>
3217: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
3218: state</a>. (This does <em>not</em> set the DOCTYPE token's
3219: <i>force-quirks flag</i> to <i>on</i>.)</dd>
3220:
1.444 mike 3221: </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.40 </span><dfn>Bogus DOCTYPE state</dfn></h5>
1.1 mike 3222:
3223: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3224:
3225: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
3226: <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
3227: state</a>.</dd>
3228:
3229: <dt>EOF</dt>
3230: <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
3231: <a href="#data-state">data state</a>.</dd>
3232:
3233: <dt>Anything else</dt>
3234: <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
3235:
1.444 mike 3236: </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.41 </span><dfn>CDATA section state</dfn></h5>
1.1 mike 3237:
3238: <p><i>(This can only happen if the <a href="#content-model-flag">content model
1.91 mike 3239: flag</a> is set to the PCDATA state.)</i></p>
1.1 mike 3240:
3241: <p>Consume every character up to the next occurrence of the three
3242: character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
3243: BRACKET U+003E GREATER-THAN SIGN (<code title="">]]></code>), or the
3244: end of the file (EOF), whichever comes first. Emit a series of
3245: character tokens consisting of all the characters consumed except
3246: the matching three character sequence at the end (if one was found
3247: before the end of the file).</p>
3248:
3249: <p>Switch to the <a href="#data-state">data state</a>.</p>
3250:
3251: <p>If the end of the file was reached, reconsume the EOF
3252: character.</p>
3253:
3254:
3255:
1.444 mike 3256: <h5 id="tokenizing-character-references"><span class="secno">9.2.4.42 </span>Tokenizing character references</h5>
1.1 mike 3257:
3258: <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
3259: reference</dfn>. This definition is used when parsing character
1.299 mike 3260: references <a href="#character-reference-in-data-state" title="character reference in data state">in
1.1 mike 3261: text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
3262: state">in attributes</a>.</p>
3263:
3264: <p>The behavior depends on the identity of the next character (the
3265: one immediately after the U+0026 AMPERSAND character):</p>
3266:
3267: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3268: <dt>U+000A LINE FEED (LF)</dt>
3269: <dt>U+000C FORM FEED (FF)</dt>
3270: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3271: <dt>U+0020 SPACE</dt>
3272: <dt>U+003C LESS-THAN SIGN</dt>
3273: <dt>U+0026 AMPERSAND</dt>
3274: <dt>EOF</dt>
3275: <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
3276:
3277: <dd>Not a character reference. No characters are consumed, and
3278: nothing is returned. (This is not an error, either.)</dd>
3279:
3280:
3281: <dt>U+0023 NUMBER SIGN (#)</dt>
3282:
3283: <dd>
3284:
3285: <p>Consume the U+0023 NUMBER SIGN.</p>
3286:
3287: <p>The behavior further depends on the character after the U+0023
3288: NUMBER SIGN:</p>
3289:
3290: <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
3291: <dt>U+0058 LATIN CAPITAL LETTER X</dt>
3292:
3293: <dd>
3294:
3295: <p>Consume the X.</p>
3296:
3297: <p>Follow the steps below, but using the range of characters
3298: U+0030 DIGIT ZERO through to U+0039 DIGIT NINE, U+0061 LATIN
3299: SMALL LETTER A through to U+0066 LATIN SMALL LETTER F, and
3300: U+0041 LATIN CAPITAL LETTER A, through to U+0046 LATIN CAPITAL
3301: LETTER F (in other words, 0-9, A-F, a-f).</p>
3302:
3303: <p>When it comes to interpreting the number, interpret it as a
3304: hexadecimal number.</p>
3305:
3306: </dd>
3307:
3308:
3309: <dt>Anything else</dt>
3310:
3311: <dd>
3312:
3313: <p>Follow the steps below, but using the range of characters
3314: U+0030 DIGIT ZERO through to U+0039 DIGIT NINE (i.e. just
3315: 0-9).</p>
3316:
3317: <p>When it comes to interpreting the number, interpret it as a
3318: decimal number.</p>
3319:
3320: </dd>
3321:
3322: </dl><p>Consume as many characters as match the range of characters
3323: given above.</p>
3324:
3325: <p>If no characters match the range, then don't consume any
3326: characters (and unconsume the U+0023 NUMBER SIGN character and, if
3327: appropriate, the X character). This is a <a href="#parse-error">parse
3328: error</a>; nothing is returned.</p>
3329:
3330: <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
3331: that too. If it isn't, there is a <a href="#parse-error">parse
3332: error</a>.</p>
3333:
3334: <p>If one or more characters match the range, then take them all
3335: and interpret the string of characters as a number (either
3336: hexadecimal or decimal as appropriate).</p>
3337:
3338: <p>If that number is one of the numbers in the first column of the
3339: following table, then this is a <a href="#parse-error">parse error</a>. Find the
3340: row with that number in the first column, and return a character
3341: token for the Unicode character given in the second column of that
3342: row.</p>
3343:
3344: <table><thead><tr><th>Number </th><th colspan="2">Unicode character
3345: </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
3346: </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
3347: </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN ('€')
3348: </td></tr><tr><td>0x81 </td><td>U+0081 </td><td><control>
3349: </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK ('‚')
3350: </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK ('ƒ')
3351: </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK ('„')
3352: </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS ('…')
3353: </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER ('†')
3354: </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER ('‡')
3355: </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT ('ˆ')
3356: </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN ('‰')
3357: </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON ('Š')
3358: </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK ('‹')
3359: </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE ('Œ')
3360: </td></tr><tr><td>0x8D </td><td>U+008D </td><td><control>
3361: </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON ('Ž')
3362: </td></tr><tr><td>0x8F </td><td>U+008F </td><td><control>
3363: </td></tr><tr><td>0x90 </td><td>U+0090 </td><td><control>
3364: </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK ('‘')
3365: </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK ('’')
3366: </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK ('“')
3367: </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK ('”')
3368: </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET ('•')
3369: </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH ('–')
3370: </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH ('—')
3371: </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE ('˜')
3372: </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN ('™')
3373: </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON ('š')
3374: </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK ('›')
3375: </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE ('œ')
3376: </td></tr><tr><td>0x9D </td><td>U+009D </td><td><control>
3377: </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON ('ž')
3378: </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS ('Ÿ')
1.315 mike 3379: </td></tr></tbody></table><p>Otherwise, if the number is in the range 0xD800 to 0xDFFF<!--
3380: surrogates not allowed; see the comment in the "preprocessing the
3381: input stream" section for details --> or is greater than 0x10FFFF,
3382: then this is a <a href="#parse-error">parse error</a>. Return a U+FFFD
3383: REPLACEMENT CHARACTER.</p>
1.18 mike 3384:
3385: <p>Otherwise, return a character token for the Unicode character
1.1 mike 3386: whose code point is that number.
3387:
3388: <!-- this is the same as the equivalent list in the input stream
3389: section -->
3390: If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
3391: allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
3392: allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
1.315 mike 3393: 0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xFDD0 to
3394: 0xFDEF, or is one of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF,
3395: 0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE,
3396: 0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF,
3397: 0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE,
3398: 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF,
3399: 0x10FFFE, or 0x10FFFF, then this is a <a href="#parse-error">parse
3400: error</a>.</p>
1.1 mike 3401:
3402: </dd>
3403:
3404:
3405: <dt>Anything else</dt>
3406:
3407: <dd>
3408:
3409: <p>Consume the maximum number of characters possible, with the
3410: consumed characters matching one of the identifiers in the first
3411: column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
3412: <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
3413:
3414: <p>If no match can be made, then this is a <a href="#parse-error">parse
3415: error</a>. No characters are consumed, and nothing is
3416: returned.</p>
3417:
3418: <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>
3419:
3420: <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
3421: attribute</a>, and the last character matched is not a U+003B
3422: SEMICOLON (<code title="">;</code>), and the next character is in
3423: the range U+0030 DIGIT ZERO to U+0039 DIGIT NINE, U+0041 LATIN
3424: CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z, or U+0061 LATIN
3425: SMALL LETTER A to U+007A LATIN SMALL LETTER Z, then, for
3426: historical reasons, all the characters that were matched after the
3427: U+0026 AMPERSAND (&) must be unconsumed, and nothing is
3428: returned.</p>
3429:
3430: <p>Otherwise, return a character token for the character
3431: corresponding to the character reference name (as given by the
3432: second column of the <a href="named-character-references.html#named-character-references">named character references</a>
3433: table).</p>
3434:
3435: <div class="example">
3436:
3437: <p>If the markup contains <code title="">I'm &notit; I tell
3438: you</code>, the character reference is parsed as "not", as in,
3439: <code title="">I'm ¬it; I tell you</code>. But if the markup
3440: was <code title="">I'm &notin; I tell you</code>, the
3441: character reference would be parsed as "notin;", resulting in
3442: <code title="">I'm ∉ I tell you</code>.</p>
3443:
3444: </div>
3445:
3446: </dd>
3447:
1.266 mike 3448: </dl></div><div class="impl">
3449:
1.363 mike 3450: <!-- v2: One thing that this doesn't define is handling deeply
3451: nested documents. There are compatibility requirements around that:
3452: you can't throw away the elements altogether, consider Tux made only
3453: with opening <font> elements, one per character. Seems that the best
3454: thing to do is to close some formatting elements from the middle of
3455: the stack when you hit a limit, or something. -->
3456:
1.266 mike 3457: <h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4>
1.1 mike 3458:
3459: <p>The input to the tree construction stage is a sequence of tokens
3460: from the <a href="#tokenization">tokenization</a> stage. The tree construction
3461: stage is associated with a DOM <code>Document</code> object when a
3462: parser is created. The "output" of this stage consists of
3463: dynamically modifying or extending that document's DOM tree.</p>
3464:
3465: <p>This specification does not define when an interactive user agent
3466: has to render the <code>Document</code> so that it is available to
3467: the user, or when it has to begin accepting user input.</p>
3468:
3469: <p>As each token is emitted from the tokenizer, the user agent must
3470: process the token according to the rules given in the section
3471: corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
3472:
3473: <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
3474: character</dfn> into a node, if that node has a child immediately
3475: before where the character is to be inserted, and that child is a
3476: <code>Text</code> node, and that <code>Text</code> node was the last
3477: node that the parser inserted into the document, then the character
3478: must be appended to that <code>Text</code> node; otherwise, a new
3479: <code>Text</code> node whose data is just that character must be
3480: inserted in the appropriate place.</p>
3481:
3482: <div class="example">
3483:
3484: <p>Here are some sample inputs to the parser and the corresponding
3485: number of text nodes that they result in, assuming a user agent
3486: that executes scripts.</p>
3487:
3488: <table><thead><tr><th>Input </th><th>Number of text nodes
3489: </th></tr></thead><tbody><tr><td><pre>A<script>
3490: var script = document.getElementsByTagName('script')[0];
3491: document.body.removeChild(script);
3492: </script>B</pre>
3493: </td><td>Two adjacent text nodes in the document, containing "A" and "B".
3494: </td></tr><tr><td><pre>A<script>
3495: var text = document.createTextNode('B');
3496: document.body.appendChild(text);
3497: </script>C</pre>
3498: </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
3499: </td></tr><tr><td><pre>A<script>
3500: var text = document.getElementsByTagName('script')[0].firstChild;
3501: text.data = 'B';
3502: document.body.appendChild(text);
3503: </script>B</pre>
3504: </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
3505: </td></tr><tr><td><pre>A<table>B<tr>C</tr>C</table></pre>
3506: </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>.)
3507: </td></tr><tr><td><pre>A<table><tr> B</tr> B</table></pre>
3508: </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>.)
3509: </td></tr><tr><td><pre>A<table><tr> B</tr> </em>C</table></pre>
3510: </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.)
3511: </td></tr></tbody></table></div>
3512:
3513: <p id="mutation-during-parsing">DOM mutation events must not fire
3514: for changes caused by the UA parsing the document. (Conceptually,
3515: the parser is not mutating the DOM, it is constructing it.) This
1.159 mike 3516: 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 3517:
3518: <p class="note">Not all of the tag names mentioned below are
3519: conformant tag names in this specification; many are included to
3520: handle legacy content. They still form part of the algorithm that
3521: implementations are required to implement to claim conformance.</p>
3522:
3523: <p class="note">The algorithm described below places no limit on the
3524: depth of the DOM tree generated, or on the length of tag names,
3525: attribute names, attribute values, text nodes, etc. While
3526: implementors are encouraged to avoid arbitrary limits, it is
3527: recognized that <a href="infrastructure.html#hardwareLimitations">practical
1.445 mike 3528: concerns</a> will likely force user agents to impose nesting depth
3529: constraints.</p>
1.1 mike 3530:
3531:
3532: <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5>
3533:
3534: <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
3535: element for the token">create an element for a token</dfn> in a
3536: particular namespace, the UA must create a node implementing the
3537: interface appropriate for the element type corresponding to the tag
3538: name of the token in the given namespace (as given in the
3539: specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
3540: element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
3541: defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
3542: the tag name being the name of that element, with the node being in
3543: the given namespace, and with the attributes on the node being those
3544: given in the given token.</p>
3545:
3546: <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
1.426 mike 3547: namespace</a> that is not defined in this specification (or
3548: <a href="infrastructure.html#other-applicable-specifications">other applicable specifications</a>) is
1.44 mike 3549: <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1 mike 3550: interface is not defined by that namespace's specification must use
3551: the interface <code>Element</code>.</p>
3552:
3553: <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
3554: created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
3555: invoked once the attributes are set. (This initializes the element's
3556: <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
3557: attributes.)</p>
3558:
3559: <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
3560: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
3561: for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
3562: append this node to the <a href="#current-node">current node</a>, and push it onto
3563: the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
3564: <a href="#current-node">current node</a>.</p>
3565:
3566: <p>The steps below may also require that the UA insert an HTML
3567: element in a particular place, in which case the UA must follow the
3568: same steps except that it must insert or append the new node in the
3569: location specified instead of appending it to the <a href="#current-node">current
3570: node</a>. (This happens in particular during the parsing of
3571: tables with invalid content.)</p>
3572:
3573: <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
3574: algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
3575: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
3576: 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
3577: <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
3578: created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
3579: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
3580: inserting it wherever it is to be inserted.</p>
3581:
3582: <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
3583: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
3584: for the token</a> in the given namespace, and then append this
3585: node to the <a href="#current-node">current node</a>, and push it onto the
3586: <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
3587: <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>
3588: whose value is not exactly the same as the element's namespace, that
3589: is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
3590: element has an <code title="">xmlns:xlink</code> attribute in the
3591: <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
3592: Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
3593:
3594: <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
3595: attributes</dfn> for a token, then, if the token has an attribute
3596: named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
3597:
3598: <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
3599: attributes</dfn> for a token, then, for each attribute on the token
3600: whose attribute name is one of the ones in the first column of the
3601: following table, change the attribute's name to the name given in
3602: the corresponding cell in the second column. (This fixes the case of
3603: SVG attributes that are not all lowercase.)</p>
3604:
3605: <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
3606: </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
3607: </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
3608: </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
3609: </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
3610: </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
3611: </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
3612: </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
3613: </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
3614: </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
3615: </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
3616: </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
3617: </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
3618: </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
3619: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
3620: </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
3621: </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
3622: </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
3623: </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
3624: </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
3625: </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
3626: </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
3627: </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
3628: </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
3629: </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
3630: </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
3631: </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
3632: </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
3633: </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
3634: </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
3635: </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
3636: </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
3637: </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
3638: </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
3639: </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
3640: </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
3641: </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
3642: </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
3643: </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
3644: </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
3645: </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
3646: </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
3647: </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
3648: </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
3649: </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
3650: </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
3651: </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
3652: </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
3653: </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
3654: </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
3655: </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
3656: </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
3657: </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
3658: </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
3659: </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
3660: </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
3661: </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
3662: </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
3663: </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
3664: </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
3665: </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
3666: </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
3667: </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
3668: </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
3669: foreign attributes</dfn> for a token, then, if any of the attributes
3670: on the token match the strings given in the first column of the
3671: following table, let the attribute be a namespaced attribute, with
3672: the prefix being the string given in the corresponding cell in the
3673: second column, the local name being the string given in the
3674: corresponding cell in the third column, and the namespace being the
3675: namespace given in the corresponding cell in the fourth
3676: column. (This fixes the use of namespaced attributes, in particular
3677: <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
3678: the <span>XML namespace</span></a>.)</p>
3679:
3680: <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
3681: </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>
3682: </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>
3683: </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>
3684: </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>
3685: </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>
3686: </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>
3687: </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>
3688: </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 -->
3689: </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>
3690: </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>
3691: </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>
3692: </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 3693: </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 3694: <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
3695: following steps. These algorithms are always invoked in response to
3696: a start tag token.</p>
3697:
3698: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
3699:
1.91 mike 3700: <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
3701: text element parsing algorithm</a>, switch the tokenizer's
3702: <a href="#content-model-flag">content model flag</a> to the RAWTEXT state; otherwise the
1.1 mike 3703: algorithm invoked was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing
3704: algorithm</a>, switch the tokenizer's <a href="#content-model-flag">content model
3705: flag</a> to the RCDATA state.</p></li>
3706:
3707: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
3708: <a href="#insertion-mode">insertion mode</a>.</p>
3709:
1.91 mike 3710: </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
3711: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 3712:
3713: </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>
3714:
3715: <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
3716: tags</dfn>, then, while the <a href="#current-node">current node</a> is a
1.422 mike 3717: <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 3718: <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
3719: <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
3720: <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
3721: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
3722: elements</a>.</p>
3723:
3724: <p>If a step requires the UA to generate implied end tags but lists
3725: an element to exclude from the process, then the UA must perform the
3726: above steps as if that element was not in the above list.</p>
3727:
3728:
3729: <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5>
3730:
3731: <p>Foster parenting happens when content is misnested in tables.</p>
3732:
3733: <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
3734: parent">foster parented</dfn>, the node <var title="">node</var>
3735: must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
3736:
3737: <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
3738: 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
3739: elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
3740: such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
3741: the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
3742: case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
3743: element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
1.159 mike 3744: <code><a href="semantics.html#the-html-element-0">html</a></code> element). Otherwise, if there is a
1.1 mike 3745: <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
3746: elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
3747: <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
3748: node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
3749: the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
3750: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
3751:
3752: <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
3753: 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
3754: elements</a>, then <var title="">node</var> must be inserted
3755: immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
3756: the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
3757: element</a></i>; otherwise, <var title="">node</var> must be
3758: <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
3759:
3760:
3761:
3762: <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>
3763:
3764: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
3765: mode: initial">initial</a>", tokens must be handled as follows:</p>
3766:
3767: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
3768: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3769: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3770: <dd>
3771: <p>Ignore the token.</p>
3772: </dd>
3773:
3774: <dt>A comment token</dt>
3775: <dd>
3776: <p>Append a <code>Comment</code> node to the <code>Document</code>
3777: object with the <code title="">data</code> attribute set to the
3778: data given in the comment token.</p>
3779: </dd>
3780:
3781: <dt>A DOCTYPE token</dt>
3782: <dd>
3783:
3784: <p>If the DOCTYPE token's name is not a
3785: <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
3786: missing, or the token's system identifier is neither missing nor a
3787: <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
3788: "<code>about:legacy-compat</code>", and none of the sets of
3789: conditions in the following list are matched, then there is a
3790: <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
3791: following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
3792: permitted DOCTYPE</dfn>.</p>
3793:
3794: <ul><!-- only things that trigger no-quirks mode and were valid in
3795: 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 3796: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3797: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD HTML 4.0//EN</code>", and the
3798: token's system identifier is either missing or the
3799: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
3800:
3801: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3802: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3803: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD HTML 4.01//EN</code>", and the
3804: token's system identifier is either missing or the
3805: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
3806:
3807: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3808: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3809: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD XHTML 1.0 Strict//EN</code>",
3810: and the token's system identifier is the
3811: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
3812:
3813: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3814: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3815: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD XHTML 1.1//EN</code>", and the
3816: token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
3817: string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
3818:
3819: </ul><p>Conformance checkers may, based on the values (including
3820: presence or lack thereof) of the DOCTYPE token's name, public
3821: identifier, or system identifier, switch to a conformance checking
3822: mode for another language (e.g. based on the DOCTYPE token a
3823: conformance checker could recognize that the document is an
1.183 mike 3824: HTML4-era document, and defer to an HTML4 conformance
1.1 mike 3825: checker.)</p>
3826:
3827: <p>Append a <code>DocumentType</code> node to the
3828: <code>Document</code> node, with the <code title="">name</code>
3829: attribute set to the name given in the DOCTYPE token, or the empty
3830: string if the name was missing; the <code title="">publicId</code>
3831: attribute set to the public identifier given in the DOCTYPE token,
3832: or the empty string if the public identifier was missing; the
3833: <code title="">systemId</code> attribute set to the system
3834: identifier given in the DOCTYPE token, or the empty string if the
3835: system identifier was missing; and the other attributes specific
3836: to <code>DocumentType</code> objects set to null and empty lists
3837: as appropriate. Associate the <code>DocumentType</code> node with
3838: the <code>Document</code> object so that it is returned as the
3839: value of the <code title="">doctype</code> attribute of the
3840: <code>Document</code> object.</p>
3841:
3842: <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
3843: one of the conditions in the following list, then set the
3844: <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
3845:
3846: <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
3847: <li> The name is set to anything other than "<code title="">HTML</code>". </li>
3848: <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
3849: <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
3850: <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
3851: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
3852: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
3853: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
3854: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
3855: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
3856: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
3857: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
3858: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
3859: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
3860: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
3861: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
3862: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
3863: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
3864: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
3865: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
3866: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
3867: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
3868: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
3869: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
3870: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
3871: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
3872: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
3873: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
3874: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
3875: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
3876: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
3877: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
3878: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
3879: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
3880: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
3881: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
3882: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
3883: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
3884: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
3885: <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
3886: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
3887: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
3888: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
3889: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
3890: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
3891: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
3892: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
3893: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
3894: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
3895: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
3896: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
3897: <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
3898: <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
3899: <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
3900: <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
3901: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
3902: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
3903: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
3904: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
3905: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
3906: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
3907: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
3908: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
3909: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
3910: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
3911: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
3912: <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
3913: <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
3914: <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
3915: <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
3916: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
3917: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
3918: <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
3919: <li> The public identifier is set to: "<code title="">HTML</code>" </li>
3920: <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
3921: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
3922: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
3923: </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
3924: in the following list, then set the <code>Document</code> to
3925: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
3926:
3927: <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
3928: <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
3929: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
3930: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
3931: </ul><p>The name, system identifier, and public identifier strings must
3932: be compared to the values given in the lists above in an
3933: <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
3934: whose value is the empty string is not considered missing for the
3935: purposes of the conditions above.</p>
3936:
3937: <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>
3938:
3939: </dd>
3940:
3941: <dt>Anything else</dt>
3942: <dd>
3943:
3944: <p><a href="#parse-error">Parse error</a>.</p>
3945:
3946: <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
3947:
3948: <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
3949: reprocess the current token.</p>
3950:
3951: </dd>
3952:
3953: </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>
3954:
3955: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
3956: mode: before html">before html</a>", tokens must be handled as follows:</p>
3957:
3958: <dl class="switch"><dt>A DOCTYPE token</dt>
3959: <dd>
3960: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3961: </dd>
3962:
3963: <dt>A comment token</dt>
3964: <dd>
3965: <p>Append a <code>Comment</code> node to the <code>Document</code>
3966: object with the <code title="">data</code> attribute set to the
3967: data given in the comment token.</p>
3968: </dd>
3969:
3970: <dt>A character token that is one of U+0009 CHARACTER
3971: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3972: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3973: <dd>
3974: <p>Ignore the token.</p>
3975: </dd>
3976:
3977: <dt>A start tag whose tag name is "html"</dt>
3978: <dd>
3979:
3980: <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
3981: namespace</a>. Append it to the <code>Document</code>
3982: object. Put this element in the <a href="#stack-of-open-elements">stack of open
3983: elements</a>.</p>
3984:
3985: <p id="parser-appcache">If the <code>Document</code> is being
3986: loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
3987: <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
3988: has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
3989: then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
3990: attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
3991: 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 3992: algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
3993: any <a href="infrastructure.html#url-fragment" title="url-fragment"><fragment></a> component
3994: removed; otherwise, if there is no such attribute or resolving it
3995: fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
3996: cache selection algorithm</a> with no manifest. The algorithm
3997: must be passed the <code>Document</code> object.</p>
1.1 mike 3998:
3999: <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>
4000:
4001: </dd>
4002:
1.334 mike 4003: <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
4004: <dd>
4005: <p>Act as described in the "anything else" entry below.</p>
4006: </dd>
4007:
4008: <dt>Any other end tag</dt>
4009: <dd>
4010: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4011: </dd>
4012:
1.1 mike 4013: <dt>Anything else</dt>
4014: <dd>
4015:
1.159 mike 4016: <p>Create an <code><a href="semantics.html#the-html-element-0">html</a></code> element. Append it to the
1.1 mike 4017: <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
4018: of open elements</a>.</p>
4019:
4020: <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
4021: context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
4022: algorithm</a> with no manifest, passing it the
4023: <code>Document</code> object.</p>
4024:
4025: <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
4026: reprocess the current token.</p>
4027:
4028: </dd>
4029:
4030: </dl><p>The root element can end up being removed from the
4031: <code>Document</code> object, e.g. by scripts; nothing in particular
4032: happens in such cases, content continues being appended to the nodes
4033: as described in the next section.</p>
4034:
4035:
4036: <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>
4037:
4038: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
4039: mode: before head">before head</a>", tokens must be handled as follows:</p>
4040:
4041: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4042: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4043: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4044: <dd>
4045: <p>Ignore the token.</p> <!-- :-( -->
4046: </dd>
4047:
4048: <dt>A comment token</dt>
4049: <dd>
4050: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4051: node</a> with the <code title="">data</code> attribute set to
4052: the data given in the comment token.</p>
4053: </dd>
4054:
4055: <dt>A DOCTYPE token</dt>
4056: <dd>
4057: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4058: </dd>
4059:
4060: <dt>A start tag whose tag name is "html"</dt>
4061: <dd>
4062: <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
4063: mode</a>.</p>
4064: </dd>
4065:
4066: <dt>A start tag whose tag name is "head"</dt>
4067: <dd>
4068:
4069: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4070:
4071: <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
1.159 mike 4072: to the newly created <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 4073:
4074: <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>
4075:
4076: </dd>
4077:
4078: <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
4079: <dd>
4080:
4081: <p>Act as if a start tag token with the tag name "head" and no
4082: attributes had been seen, then reprocess the current token.</p>
4083:
4084: </dd>
4085:
4086: <dt>Any other end tag</dt>
4087: <dd>
4088:
4089: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4090:
4091: </dd>
4092:
4093: <dt>Anything else</dt>
4094: <dd>
4095:
4096: <p>Act as if a start tag token with the tag name "head" and no
4097: attributes had been seen, then reprocess the current
4098: token.</p>
4099:
4100: </dd>
4101:
4102: </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>
4103:
4104: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
4105: mode: in head">in head</a>", tokens must be handled as follows:</p>
4106:
4107: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4108: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4109: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4110: <dd>
4111: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
4112: the <a href="#current-node">current node</a>.</p>
4113: </dd>
4114:
4115: <dt>A comment token</dt>
4116: <dd>
4117: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4118: node</a> with the <code title="">data</code> attribute set to
4119: the data given in the comment token.</p>
4120: </dd>
4121:
4122: <dt>A DOCTYPE token</dt>
4123: <dd>
4124: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4125: </dd>
4126:
4127: <dt>A start tag whose tag name is "html"</dt>
4128: <dd>
4129: <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
4130: mode</a>.</p>
4131: </dd>
4132:
4133: <dt>A start tag whose tag name is one of: "base", "command",
4134: "link"</dt>
4135: <dd>
4136:
4137: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4138: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4139: elements</a>.</p>
4140:
4141: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4142: token's <i>self-closing flag</i></a>, if it is set.</p>
4143:
4144: </dd>
4145:
4146: <dt>A start tag whose tag name is "meta"</dt>
4147: <dd>
4148:
4149: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4150: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4151: elements</a>.</p>
4152:
4153: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4154: token's <i>self-closing flag</i></a>, if it is set.</p>
4155:
4156: <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
4157: value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
4158: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
4159: encoding</a> to the encoding given by the value of the
4160: <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
4161:
4162: <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
4163: applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
4164: Content-Type</a> to its value returns a supported encoding
4165: <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
4166: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
4167: encoding</a> to the encoding <var title="">encoding</var>.</p>
4168:
4169: </dd>
4170:
4171: <dt>A start tag whose tag name is "title"</dt>
4172: <dd>
4173: <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
4174: </dd>
4175:
4176: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
4177: <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
4178: <dd>
1.91 mike 4179: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 4180: </dd>
4181:
4182: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
4183: <dd>
4184:
4185: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4186:
4187: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
4188: noscript</a>".</p>
4189:
4190: </dd>
4191:
4192: <dt id="scriptTag">A start tag whose tag name is "script"</dt>
4193: <dd>
4194:
4195: <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
4196: <a href="#html-namespace-0">HTML namespace</a>.</p></li>
4197:
4198: <li>
4199:
4200: <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
4201:
4202: <p class="note">This ensures that, if the script is external,
1.159 mike 4203: any <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>
1.1 mike 4204: calls in the script will execute in-line, instead of blowing the
4205: document away, as would happen in most other cases. It also
4206: prevents the script from executing until the end tag is
4207: seen.</p>
4208:
4209: </li>
4210:
4211: <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
4212: fragment parsing algorithm</a>, then mark the
4213: <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
4214: executed"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
4215:
4216: <li><p>Append the new element to the <a href="#current-node">current node</a>
4217: and push it onto the <a href="#stack-of-open-elements">stack of open
4218: elements</a>.</p></li>
4219:
4220: <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
1.91 mike 4221: the RAWTEXT state.</p></li>
1.1 mike 4222:
4223: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
4224: <a href="#insertion-mode">insertion mode</a>.</p>
4225:
1.91 mike 4226: </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
4227: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 4228:
4229: </ol></dd>
4230:
4231: <dt>An end tag whose tag name is "head"</dt>
4232: <dd>
4233:
4234: <p>Pop the <a href="#current-node">current node</a> (which will be the
1.159 mike 4235: <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 4236: elements</a>.</p>
4237:
4238: <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>
4239:
4240: </dd>
4241:
4242: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
4243: <dd>
4244: <p>Act as described in the "anything else" entry below.</p>
4245: </dd>
4246:
4247: <dt>A start tag whose tag name is "head"</dt>
4248: <dt>Any other end tag</dt>
4249: <dd>
4250: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4251: </dd>
4252:
4253: <dt>Anything else</dt>
4254: <dd>
4255:
4256: <!-- can't get here with an EOF and a fragment case -->
4257:
4258: <p>Act as if an end tag token with the tag name "head" had
4259: been seen, and reprocess the current token.</p>
4260:
4261: </dd>
4262:
4263: </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>
4264:
4265: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
4266: mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
4267:
4268: <dl class="switch"><dt>A DOCTYPE token</dt>
4269: <dd>
4270: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4271: </dd>
4272:
4273: <dt>A start tag whose tag name is "html"</dt>
4274: <dd>
4275: <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
4276: mode</a>.</p>
4277: </dd>
4278:
4279: <dt>An end tag whose tag name is "noscript"</dt>
4280: <dd>
4281:
4282: <p>Pop the <a href="#current-node">current node</a> (which will be a
4283: <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
4284: elements</a>; the new <a href="#current-node">current node</a> will be a
1.159 mike 4285: <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 4286:
4287: <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>
4288:
4289: </dd>
4290:
4291: <dt>A character token that is one of U+0009 CHARACTER
4292: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4293: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4294: <dt>A comment token</dt>
4295: <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
4296: <dd>
4297: <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
4298: mode</a>.</p>
4299: </dd>
4300:
4301: <dt>An end tag whose tag name is "br"</dt>
4302: <dd>
4303: <p>Act as described in the "anything else" entry below.</p>
4304: </dd>
4305:
4306: <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
4307: <dt>Any other end tag</dt>
4308: <dd>
4309: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4310: </dd>
4311:
4312: <dt>Anything else</dt>
4313: <dd>
4314:
4315: <!-- can't get here with an EOF and a fragment case -->
4316:
4317: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
4318: name "noscript" had been seen and reprocess the current
4319: token.</p>
4320:
4321: </dd>
4322:
4323: </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>
4324:
4325: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
4326: mode: after head">after head</a>", tokens must be handled as follows:</p>
4327:
4328: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4329: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4330: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4331: <dd>
4332: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
4333: the <a href="#current-node">current node</a>.</p>
4334: </dd>
4335:
4336: <dt>A comment token</dt>
4337: <dd>
4338: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4339: node</a> with the <code title="">data</code> attribute set to
4340: the data given in the comment token.</p>
4341: </dd>
4342:
4343: <dt>A DOCTYPE token</dt>
4344: <dd>
4345: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4346: </dd>
4347:
4348: <dt>A start tag whose tag name is "html"</dt>
4349: <dd>
4350: <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
4351: mode</a>.</p>
4352: </dd>
4353:
4354: <dt>A start tag whose tag name is "body"</dt>
4355: <dd>
4356:
4357: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4358:
4359: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4360:
4361: <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>
4362:
4363: </dd>
4364:
4365: <dt>A start tag whose tag name is "frameset"</dt>
4366: <dd>
4367:
4368: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4369:
4370: <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>
4371:
4372: </dd>
4373:
4374: <dt>A start tag token whose tag name is one of: "base", "link",
4375: "meta", "noframes", "script", "style", "title"</dt>
4376: <dd>
4377:
4378: <p><a href="#parse-error">Parse error</a>.</p>
4379:
4380: <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
4381: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
4382:
4383: <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
4384: mode</a>.</p>
4385:
4386: <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
4387: of open elements</a>.</p>
4388:
4389: <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
4390: pointer</a> cannot be null at this point.</p>
4391:
4392: </dd>
4393:
4394: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
4395: <dd>
4396: <p>Act as described in the "anything else" entry below.</p>
4397: </dd>
4398:
4399: <dt>A start tag whose tag name is "head"</dt>
4400: <dt>Any other end tag</dt>
4401: <dd>
4402: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4403: </dd>
4404:
4405: <dt>Anything else</dt>
4406: <dd>
4407: <p>Act as if a start tag token with the tag name "body" and no
4408: attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
4409: flag</a> back to "ok", and then reprocess the current
4410: token.</p>
4411: </dd>
4412:
4413: </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>
4414:
4415: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
4416: mode: in body">in body</a>", tokens must be handled as follows:</p>
4417:
4418: <dl class="switch"><dt>A character token</dt>
4419: <dd>
4420:
4421: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4422: any.</p>
4423:
4424: <p><a href="#insert-a-character" title="insert a character">Insert the token's
4425: character</a> into the <a href="#current-node">current node</a>.</p>
4426:
4427: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
4428: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
4429: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
4430: flag</a> to "not ok".</p>
4431:
4432: </dd>
4433:
4434: <dt>A comment token</dt>
4435: <dd>
4436: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4437: node</a> with the <code title="">data</code> attribute set to
4438: the data given in the comment token.</p>
4439: </dd>
4440:
4441: <dt>A DOCTYPE token</dt>
4442: <dd>
4443: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4444: </dd>
4445:
4446: <dt>A start tag whose tag name is "html"</dt>
4447: <dd>
4448: <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
4449: check to see if the attribute is already present on the top
4450: element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
4451: add the attribute and its corresponding value to that element.</p>
4452: </dd>
4453:
4454: <dt>A start tag token whose tag name is one of: "base", "command",
4455: "link", "meta", "noframes", "script", "style", "title"</dt>
4456: <dd>
4457: <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
4458: mode</a>.</p>
4459: </dd>
4460:
4461: <dt>A start tag whose tag name is "body"</dt>
4462: <dd>
4463:
4464: <p><a href="#parse-error">Parse error</a>.</p>
4465:
4466: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159 mike 4467: elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1 mike 4468: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
4469: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
4470:
4471: <p>Otherwise, for each attribute on the token, check to see if
1.159 mike 4472: the attribute is already present on the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 4473: element (the second element) on the <a href="#stack-of-open-elements">stack of open
4474: elements</a>. If it is not, add the attribute and its
4475: corresponding value to that element.</p>
4476:
4477: </dd>
4478:
4479: <dt>A start tag whose tag name is "frameset"</dt>
4480: <dd>
4481:
4482: <p><a href="#parse-error">Parse error</a>.</p>
4483:
4484: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159 mike 4485: elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1 mike 4486: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
4487: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
4488:
4489: <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
4490: the token.</p>
4491:
4492: <p>Otherwise, run the following steps:</p>
4493:
4494: <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
4495: elements</a> from its parent node, if it has one.</p></li>
4496:
4497: <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
4498: open elements</a>, from the <a href="#current-node">current node</a> up to,
1.159 mike 4499: but not including, the root <code><a href="semantics.html#the-html-element-0">html</a></code> element.</p>
1.1 mike 4500:
4501: </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
4502: token.</p></li>
4503:
4504: <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>
4505:
4506: </li></ol></dd>
4507:
4508: <dt>An end-of-file token</dt>
4509: <dd>
4510:
4511: <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
1.422 mike 4512: 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>
4513: 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 4514: <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
4515: <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
4516: <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 4517: <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 4518: this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
1.422 mike 4519: fragment cases) -->
1.1 mike 4520:
4521: <p><a href="#stop-parsing">Stop parsing</a>.</p>
4522:
4523: </dd>
4524:
4525: <dt>An end tag whose tag name is "body"</dt>
4526: <dd>
4527:
4528: <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
4529: in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
4530: token.</p>
4531:
4532: <!-- if we get here, the insertion mode here is forcibly "in
4533: body". -->
4534:
4535: <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
1.422 mike 4536: elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
1.1 mike 4537: <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
4538: <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
4539: <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
4540: <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
4541: <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
4542: <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 4543: <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
4544: <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 4545: error</a>.</p> <!-- (some of those are fragment cases, e.g. for
4546: <tbody> you'd have hit the first paragraph since the <body>
1.422 mike 4547: wouldn't be in scope, unless it was a fragment case) -->
1.1 mike 4548:
4549: <!-- If we ever change the frameset-ok flag to an insertion mode,
4550: then we'd have to somehow keep track of its state when we switch
4551: to after-body. -->
4552:
4553: <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>
4554:
4555: </dd>
4556:
4557: <dt>An end tag whose tag name is "html"</dt>
4558: <dd>
4559:
4560: <p>Act as if an end tag with tag name "body" had been seen,
4561: then, if that token wasn't ignored, reprocess the current
4562: token.</p>
4563:
4564: <p class="note">The fake end tag token here can only be
4565: ignored in the <a href="#fragment-case">fragment case</a>.</p>
4566:
4567: </dd>
4568:
4569: <!-- start tags for non-phrasing flow content elements -->
4570:
4571: <!-- the normal ones -->
4572: <dt>A start tag whose tag name is one of: "address", "article",
1.86 mike 4573: "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305 mike 4574: "details", "dir", "div", "dl", "fieldset", "figure", "footer",
4575: "header", "hgroup", "menu", "nav", "ol", "p", "section", "ul"</dt>
1.1 mike 4576: <dd>
4577:
4578: <!-- As of May 2008 this doesn't match any browser exactly, but is
4579: as close to what IE does as I can get without doing the non-tree
4580: DOM nonsense, and thus should actually afford better compatibility
4581: when implemented by the other browsers. -->
4582:
4583: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4584: an element in scope">has a <code>p</code> element in
4585: scope</a>, then act as if an end tag with the tag name
4586: "p" had been seen.</p>
4587:
4588: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4589:
4590: </dd>
4591:
4592: <!-- as normal, but close h1-h6 if it's the current node -->
4593: <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
4594: "h5", "h6"</dt>
4595: <dd>
4596:
4597: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4598: an element in scope">has a <code>p</code> element in
4599: scope</a>, then act as if an end tag with the tag name
4600: "p" had been seen.</p>
4601:
4602: <p>If the <a href="#current-node">current node</a> is an element whose tag name
4603: is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
4604: <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
4605: the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
4606: <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
4607:
4608: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4609:
4610: </dd>
4611:
4612: <!-- as normal, but drops leading newline -->
4613: <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
4614: <dd>
4615:
4616: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4617: an element in scope">has a <code>p</code> element in
4618: scope</a>, then act as if an end tag with the tag name
4619: "p" had been seen.</p>
4620:
4621: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4622:
4623: <p>If the next token is a U+000A LINE FEED (LF) character
4624: token, then ignore that token and move on to the next
4625: one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
4626: ignored as an authoring convenience.)</p>
4627:
4628: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4629:
4630: </dd>
4631:
4632: <!-- as normal, but interacts with the form element pointer -->
4633: <dt>A start tag whose tag name is "form"</dt>
4634: <dd>
4635:
4636: <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
4637: pointer</a> is not null, then this is a <a href="#parse-error">parse
4638: error</a>; ignore the token.</p>
4639:
4640: <p>Otherwise:</p>
4641:
4642: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4643: an element in scope">has a <code>p</code> element in
4644: scope</a>, then act as if an end tag with the tag name
4645: "p" had been seen.</p>
4646:
4647: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
4648: <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
4649: point to the element created.</p>
4650:
4651: </dd>
4652:
4653: <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
4654: <dt>A start tag whose tag name is "li"</dt>
4655: <dd>
4656:
4657: <p>Run the following algorithm:</p>
4658:
4659: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
4660:
4661: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
4662: node</a> (the bottommost node of the stack).</p></li>
4663:
4664: <li><p>If <var title="">node</var> is an <code><a href="semantics.html#the-li-element">li</a></code> element,
4665: then act as if an end tag with the tag name "li" had
4666: been seen, then jump to the last step.</p></li>
4667:
4668: <li><p><i>Loop</i>: If <var title="">node</var> is not in the
4669: <a href="#formatting">formatting</a> category, and is not in the
4670: <a href="#phrasing">phrasing</a> category, and is not an
1.306 mike 4671: <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 4672: element, then jump to the last step.</p></li> <!-- an element
4673: <foo> is in this list if the following markup:
4674:
4675: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
4676:
4677: ...results in the second <li> not being (in any way) a descendant
4678: of the first <li>, or if <foo> is a formatting element that gets
4679: reopened later. -->
4680:
4681: <li><p>Otherwise, set <var title="">node</var> to the previous
4682: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
4683: the step labeled <i>loop</i>.</p></li>
4684:
4685: <li>
4686:
4687: <p>This is the last step.</p>
4688:
4689: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4690: an element in scope">has a <code>p</code> element in
4691: scope</a>, then act as if an end tag with the tag name
4692: "p" had been seen.</p>
4693:
4694: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
4695: token.</p>
4696:
4697: </li>
4698:
4699: </ol></dd>
4700:
4701: <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases -->
1.422 mike 4702: <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
1.1 mike 4703: <dd>
4704:
4705: <p>Run the following algorithm:</p>
4706:
4707: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
4708:
4709: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
4710: node</a> (the bottommost node of the stack).</p></li>
4711:
4712: <li><p><i>Loop</i>: If <var title="">node</var> is a
1.422 mike 4713: <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
4714: tag with the same tag name as <var title="">node</var> had been
4715: seen, then jump to the last step.</p></li>
1.1 mike 4716:
4717: <li><p>If <var title="">node</var> is not in the
4718: <a href="#formatting">formatting</a> category, and is not in the
4719: <a href="#phrasing">phrasing</a> category, and is not an
1.306 mike 4720: <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 4721: element, then jump to the last step.</p></li> <!-- an element
4722: <foo> is in this list if the following markup:
4723:
4724: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
4725:
4726: ...results in the second <dt> not being (in any way) a descendant
4727: of the first <dt>, or if <foo> is a formatting element that gets
4728: reopened later. -->
4729:
4730: <li><p>Otherwise, set <var title="">node</var> to the previous
4731: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
4732: the step labeled <i>loop</i>.</p></li>
4733:
4734: <li>
4735:
4736: <p>This is the last step.</p>
4737:
4738: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4739: an element in scope">has a <code>p</code> element in
4740: scope</a>, then act as if an end tag with the tag name
4741: "p" had been seen.</p>
4742:
4743: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
4744: token.</p>
4745:
4746: </li>
4747:
4748: </ol></dd>
4749:
4750: <!-- same as normal, but effectively ends parsing -->
4751: <dt>A start tag whose tag name is "plaintext"</dt>
4752: <dd>
4753:
4754: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4755: an element in scope">has a <code>p</code> element in
4756: scope</a>, then act as if an end tag with the tag name
4757: "p" had been seen.</p>
4758:
4759: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4760:
4761: <p>Switch the <a href="#content-model-flag">content model flag</a> to the PLAINTEXT
4762: state.</p>
4763:
4764: <p class="note">Once a start tag with the tag name "plaintext"
4765: has been seen, that will be the last token ever seen other
4766: than character tokens (and the end-of-file token), because
4767: there is no way to switch the <a href="#content-model-flag">content model flag</a>
4768: out of the PLAINTEXT state.</p>
4769:
4770: </dd>
4771:
4772: <!-- end tags for non-phrasing flow content elements -->
4773:
4774: <!-- the normal ones -->
4775: <dt>An end tag whose tag name is one of: "address", "article",
1.86 mike 4776: "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305 mike 4777: "details", "dir", "div", "dl", "fieldset", "figure", "footer",
4778: "header", "hgroup", "listing", "menu", "nav", "ol", "pre",
4779: "section", "ul"</dt>
1.1 mike 4780: <dd>
4781:
4782: <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>
4783: with the same tag name as that of the token, then this is a
4784: <a href="#parse-error">parse error</a>; ignore the token.</p>
4785:
4786: <p>Otherwise, run these steps:</p>
4787:
4788: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4789:
4790: <li><p>If the <a href="#current-node">current node</a> is not an element with
4791: the same tag name as that of the token, then this is a
4792: <a href="#parse-error">parse error</a>.</p></li>
4793:
4794: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4795: until an element with the same tag name as the token has been
4796: popped from the stack.</p></li>
4797:
4798: </ol></dd>
4799:
4800: <!-- removes the form element pointer instead of the matching node -->
4801: <dt>An end tag whose tag name is "form"</dt>
4802: <dd>
4803:
4804: <p>Let <var title="">node</var> be the element that the
4805: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
4806: to.</p>
4807:
4808: <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
4809: to null.</p>
4810:
4811: <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
4812: elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
4813: scope">have <var title="">node</var> in scope</a>, then this is
4814: a <a href="#parse-error">parse error</a>; ignore the token.</p>
4815:
4816: <p>Otherwise, run these steps:</p>
4817:
4818: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4819:
4820: <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
4821: error</a>.</p></li>
4822:
4823: <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
4824: open elements</a>.</p></li>
4825:
4826: </ol></dd>
4827:
4828: <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
4829: <dt>An end tag whose tag name is "p"</dt>
4830: <dd>
4831:
4832: <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>
4833: with the same tag name as that of the token, then this is a
4834: <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
4835: "p" had been seen, then reprocess the current token.</p>
4836:
4837: <p>Otherwise, run these steps:</p>
4838:
4839: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
4840: for elements with the same tag name as the token.</p></li>
4841:
4842: <li><p>If the <a href="#current-node">current node</a> is not an element with
4843: the same tag name as that of the token, then this is a
4844: <a href="#parse-error">parse error</a>.</p></li>
4845:
4846: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4847: until an element with the same tag name as the token has been
4848: popped from the stack.</p></li>
4849:
4850: </ol></dd>
4851:
1.234 mike 4852: <!-- as normal, but needs care as the elements have optional tags, and are further scoped by <ol>/<ul> -->
4853: <dt>An end tag whose tag name is "li"</dt>
4854: <dd>
4855:
4856: <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
4857: item scope</a> with the same tag name as that of the token,
4858: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
4859:
4860: <p>Otherwise, run these steps:</p>
4861:
4862: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
4863: for elements with the same tag name as the token.</p></li>
4864:
4865: <li><p>If the <a href="#current-node">current node</a> is not an element with
4866: the same tag name as that of the token, then this is a
4867: <a href="#parse-error">parse error</a>.</p></li>
4868:
4869: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4870: until an element with the same tag name as the token has been
4871: popped from the stack.</p></li>
4872:
4873: </ol></dd>
4874:
1.1 mike 4875: <!-- as normal, but needs care as the elements have optional tags -->
1.422 mike 4876: <dt>An end tag whose tag name is one of: "dd", "dt"</dt>
1.1 mike 4877: <dd>
4878:
4879: <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>
4880: with the same tag name as that of the token, then this is a
4881: <a href="#parse-error">parse error</a>; ignore the token.</p>
4882:
4883: <p>Otherwise, run these steps:</p>
4884:
4885: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
4886: for elements with the same tag name as the token.</p></li>
4887:
4888: <li><p>If the <a href="#current-node">current node</a> is not an element with
4889: the same tag name as that of the token, then this is a
4890: <a href="#parse-error">parse error</a>.</p></li>
4891:
4892: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4893: until an element with the same tag name as the token has been
4894: popped from the stack.</p></li>
4895:
4896: </ol></dd>
4897:
4898: <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
4899: <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
4900: <dd>
4901:
4902: <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>
4903: whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
4904: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
4905:
4906: <p>Otherwise, run these steps:</p>
4907:
4908: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4909:
4910: <li><p>If the <a href="#current-node">current node</a> is not an element with
4911: the same tag name as that of the token, then this is a
4912: <a href="#parse-error">parse error</a>.</p></li>
4913:
4914: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4915: until an element whose tag name is one of "h1", "h2", "h3", "h4",
4916: "h5", or "h6" has been popped from the stack.</p></li>
4917:
4918: </ol></dd>
4919:
4920: <dt>An end tag whose tag name is "sarcasm"</dt>
4921: <dd>
4922: <p>Take a deep breath, then act as described in the "any other end
4923: tag" entry below.</p>
4924: </dd>
4925:
4926: <!-- ADOPTION AGENCY ELEMENTS
4927: Mozilla-only: bdo blink del ins sub sup q
4928: Safari-only: code dfn kbd nobr samp var wbr
4929: Both: a b big em font i s small strike strong tt u -->
4930:
4931: <dt>A start tag whose tag name is "a"</dt>
4932: <dd>
4933:
4934: <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
4935: contains an element whose tag name is "a" between the end of
4936: the list and the last marker on the list (or the start of the
4937: list if there is no marker on the list), then this is a
4938: <a href="#parse-error">parse error</a>; act as if an end tag with the tag
4939: name "a" had been seen, then remove that element from the
4940: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
4941: <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
4942: already remove it (it might not have if the element is not
4943: <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
4944: scope</a>).</p>
4945:
4946: <p class="example">In the non-conforming stream
4947: <code><a href="a">a<table><a href="b">b</table>x</code>,
4948: the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
4949: the second one, and the "x" character would be inside a link
4950: to "b", not to "a". This is despite the fact that the outer
4951: <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
4952: regular <code></a></code> end tag at the start of the table
4953: wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
4954:
4955: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4956: any.</p>
4957:
4958: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
4959: element to the <a href="#list-of-active-formatting-elements">list of active formatting
4960: elements</a>.</p>
4961:
4962: </dd>
4963:
4964: <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
4965: "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
4966: <dd>
4967:
4968: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4969: any.</p>
4970:
4971: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
4972: element to the <a href="#list-of-active-formatting-elements">list of active formatting
4973: elements</a>.</p>
4974:
4975: </dd>
4976:
4977: <dt>A start tag whose tag name is "nobr"</dt>
4978: <dd>
4979:
4980: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4981: any.</p>
4982:
4983: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
4984: element in scope">has a <code>nobr</code> element in scope</a>,
4985: then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
4986: the tag name "nobr" had been seen, then once again
4987: <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
4988: any.</p>
4989:
4990: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
4991: element to the <a href="#list-of-active-formatting-elements">list of active formatting
4992: elements</a>.</p>
4993:
4994: </dd>
4995:
4996: <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
4997: "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
4998: "strike", "strong", "tt", "u"</dt>
4999: <dd>
5000:
5001: <p>Follow these steps:</p>
5002:
5003: <ol><li>
5004:
5005: <p>Let the <var title="">formatting element</var> be the
5006: last element in the <a href="#list-of-active-formatting-elements">list of active formatting
5007: elements</a> that:</p>
5008:
5009: <ul><li>is between the end of the list and the last scope
5010: marker in the list, if any, or the start of the list
5011: otherwise, and</li>
5012:
5013: <li>has the same tag name as the token.</li>
5014:
5015: </ul><p>If there is no such node, or, if that node is also in the
5016: <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
5017: <a href="#parse-error">parse error</a>; ignore the token, and abort these
5018: steps.</p>
5019:
5020: <p>Otherwise, if there is such a node, but that node is not
5021: in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
5022: <a href="#parse-error">parse error</a>; remove the element from the list,
5023: and abort these steps.</p>
5024:
5025: <p>Otherwise, there is a <var title="">formatting
5026: element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
5027: open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
5028: element in scope">in scope</a>. If the element is not the
5029: <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
5030: error</a>. In any case, proceed with the algorithm as
5031: written in the following steps.</p>
5032:
5033: </li>
5034:
5035: <li><p>Let the <var title="">furthest block</var> be the
5036: topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
5037: is lower in the stack than the <var title="">formatting
5038: element</var>, and is not an element in the
5039: <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
5040: categories. There might not be one.</p></li>
5041:
5042: <li><p>If there is no <var title="">furthest block</var>,
5043: then the UA must skip the subsequent steps and instead just
5044: pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
5045: elements</a>, from the <a href="#current-node">current node</a> up to and
5046: including the <var title="">formatting element</var>, and
5047: remove the <var title="">formatting element</var> from the
5048: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
5049:
5050: <li><p>Let the <var title="">common ancestor</var> be the element
5051: immediately above the <var title="">formatting element</var> in the
5052: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
5053:
5054: <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
5055: formatting elements</a> relative to the elements on either
5056: side of it in the list.</p></li>
5057:
5058: <li>
5059:
5060: <p>Let <var title="">node</var> and <var title="">last node</var> be the
5061: <var title="">furthest block</var>. Follow these steps:</p>
5062:
5063: <ol><li>Let <var title="">node</var> be the element immediately
5064: above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
1.436 mike 5065: elements</a>, or if <var title="">node</var> is no longer in
5066: the <a href="#stack-of-open-elements">stack of open elements</a> (e.g. because it got
5067: removed by the next step), the element that was immediately
5068: above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
5069: elements</a> before <var title="">node</var> was
5070: removed.</li>
1.1 mike 5071:
5072: <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
5073: active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
5074: elements</a> and then go back to step 1.</li>
5075:
5076: <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
5077: in the overall algorithm.</li>
5078:
5079: <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
5080: bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
5081: elements</a>.</li>
5082:
5083: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
5084: element <var title="">node</var> was created, replace the entry
5085: for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
5086: formatting elements</a> with an entry for the new element,
5087: replace the entry for <var title="">node</var> in the
5088: <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
5089: element, and let <var title="">node</var> be the new
5090: element.</li>
5091:
5092: <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
5093: parent node if any.</li>
5094:
5095: <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
5096:
5097: <li>Return to step 1 of this inner set of steps.</li>
5098:
5099: </ol></li>
5100:
5101: <li>
5102:
5103: <p>If the <var title="">common ancestor</var> node is a
5104: <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>,
5105: <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,
5106: <a href="#foster-parent">foster parent</a> whatever <var title="">last
5107: node</var> ended up being in the previous step, first removing
5108: it from its previous parent node if any.</p>
5109:
5110: <p>Otherwise, append whatever <var title="">last node</var>
5111: ended up being in the previous step to the <var title="">common
5112: ancestor</var> node, first removing it from its previous parent
5113: node if any.</p>
5114:
5115: </li>
5116:
5117: <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
5118: <var title="">formatting element</var> was created.</p></li>
5119:
5120: <li><p>Take all of the child nodes of the <var title="">furthest
5121: block</var> and append them to the element created in the last
5122: step.</p></li>
5123:
5124: <li><p>Append that new element to the <var title="">furthest
5125: block</var>.</p></li>
5126:
5127: <li><p>Remove the <var title="">formatting element</var> from the
5128: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
5129: new element into the <a href="#list-of-active-formatting-elements">list of active formatting
5130: elements</a> at the position of the aforementioned
5131: bookmark.</p></li>
5132:
5133: <li><p>Remove the <var title="">formatting element</var> from the
5134: <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
5135: into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
5136: the position of the <var title="">furthest block</var> in that
5137: stack.</p></li>
5138:
5139: <li><p>Jump back to step 1 in this series of steps.</p></li>
5140:
1.334 mike 5141: </ol><p class="note">Because of the way this algorithm causes elements
1.304 mike 5142: to change parents, it has been dubbed the "adoption agency
5143: algorithm" (in contrast with other possible algorithms for dealing
5144: with misnested content, which included the "incest algorithm", the
1.1 mike 5145: "secret affair algorithm", and the "Heisenberg algorithm").</p>
5146:
5147: </dd>
5148:
5149: <dt>A start tag whose tag name is "button"</dt>
5150: <dd>
5151:
5152: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5153: an element in scope">has a <code>button</code> element in
5154: scope</a>, then this is a <a href="#parse-error">parse error</a>;
5155: act as if an end tag with the tag name "button" had been seen,
5156: then reprocess the token.</p>
5157:
5158: <p>Otherwise:</p>
5159:
5160: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5161: any.</p>
5162:
5163: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5164:
5165: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5166: formatting elements</a>.</p>
5167:
5168: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5169:
5170: </dd>
5171:
5172: <dt>A start tag token whose tag name is one of: "applet",
5173: "marquee", "object"</dt>
5174: <dd>
5175:
5176: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5177: any.</p>
5178:
5179: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5180:
5181: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5182: formatting elements</a>.</p>
5183:
5184: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5185:
5186: </dd>
5187:
5188: <dt>An end tag token whose tag name is one of: "applet", "button",
5189: "marquee", "object"</dt>
5190: <dd>
5191:
5192: <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>
5193: with the same tag name as that of the token, then this is a
5194: <a href="#parse-error">parse error</a>; ignore the token.</p>
5195:
5196: <p>Otherwise, run these steps:</p>
5197:
5198: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5199:
5200: <li><p>If the <a href="#current-node">current node</a> is not an element with
5201: the same tag name as that of the token, then this is a
5202: <a href="#parse-error">parse error</a>.</p></li>
5203:
5204: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5205: until an element with the same tag name as the token has been
5206: popped from the stack.</p></li>
5207:
5208: <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
5209: last marker</a>.</li>
5210:
5211: </ol></dd>
5212:
5213: <dt>A start tag whose tag name is "table"</dt>
5214: <dd>
5215:
5216: <p>If the <code>Document</code> is <em>not</em> set to
5217: <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
5218: elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
5219: <code>p</code> element in scope</a>, then act as if an end tag
5220: with the tag name "p" had been seen.</p> <!-- i hate myself (this
5221: quirk was basically caused by acid2; if i'd realised we could
5222: change the specs when i wrote acid2, we could have avoided having
5223: any parsing-mode quirks) -Hixie -->
5224:
5225: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5226:
5227: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5228:
5229: <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>
5230:
5231: </dd>
5232:
5233: <dt>A start tag whose tag name is one of: "area", "basefont",
5234: "bgsound", "br", "embed", "img", "input", "keygen", "spacer",
5235: "wbr"</dt>
5236: <dd>
5237:
5238: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5239: any.</p>
5240:
5241: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5242: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5243: elements</a>.</p>
5244:
5245: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5246: token's <i>self-closing flag</i></a>, if it is set.</p>
5247:
5248: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
5249: shouldn't really do it for <area>, <basefont>, <bgsound>, and
5250: <spacer> -->
5251:
5252: </dd>
5253:
5254: <dt>A start tag whose tag name is one of: "param", "source"</dt>
5255: <dd>
5256:
5257: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5258: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5259: elements</a>.</p>
5260:
5261: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5262: token's <i>self-closing flag</i></a>, if it is set.</p>
5263:
5264: </dd>
5265:
5266: <dt>A start tag whose tag name is "hr"</dt>
5267: <dd>
5268:
5269: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5270: an element in scope">has a <code>p</code> element in
5271: scope</a>, then act as if an end tag with the tag name
5272: "p" had been seen.</p>
5273:
5274: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5275: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5276: elements</a>.</p>
5277:
5278: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5279: token's <i>self-closing flag</i></a>, if it is set.</p>
5280:
5281: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5282:
5283: </dd>
5284:
5285: <dt>A start tag whose tag name is "image"</dt>
5286: <dd>
5287: <p><a href="#parse-error">Parse error</a>. Change the token's tag name
5288: to "img" and reprocess it. (Don't ask.)</p> <!-- As of
5289: 2005-12, studies showed that around 0.2% of pages used the
5290: <image> element. -->
5291: </dd>
5292:
5293: <dt id="isindex">A start tag whose tag name is "isindex"</dt>
5294: <dd>
5295:
5296: <p><a href="#parse-error">Parse error</a>.</p>
5297:
5298: <p>If the <a href="#form-element-pointer"><code title="">form</code> element
5299: pointer</a> is not null, then ignore the token.</p>
5300:
5301: <p>Otherwise:</p>
5302:
5303: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5304: token's <i>self-closing flag</i></a>, if it is set.</p> <!--
5305: purely to reduce the number of errors (we don't care if they
5306: included the /, they're not supposed to be including the tag at
5307: all! -->
5308:
5309: <p>Act as if a start tag token with the tag name "form" had been seen.</p>
5310:
5311: <p>If the token has an attribute called "action", set the
5312: <code title="attr-form-action">action</code> attribute on the
5313: resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
5314: "action" attribute of the token.</p>
5315:
5316: <p>Act as if a start tag token with the tag name "hr" had been
5317: seen.</p>
5318:
5319: <p>Act as if a start tag token with the tag name "label" had been
5320: seen.</p>
5321:
5322: <p>Act as if a stream of character tokens had been seen (see below
5323: for what they should say).</p>
5324:
5325: <p>Act as if a start tag token with the tag name "input" had been
5326: seen, with all the attributes from the "isindex" token except
5327: "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
5328: <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
5329:
5330: <p>Act as if a stream of character tokens had been seen (see
5331: below for what they should say).</p>
5332:
5333: <p>Act as if an end tag token with the tag name "label" had been
5334: seen.</p>
5335:
5336: <p>Act as if a start tag token with the tag name "hr" had been
5337: seen.</p>
5338:
5339: <p>Act as if an end tag token with the tag name "form" had been
5340: seen.</p>
5341:
5342: <p>If the token has an attribute with the name "prompt", then the
5343: first stream of characters must be the same string as given in
5344: that attribute, and the second stream of characters must be
5345: empty. Otherwise, the two streams of character tokens together
5346: should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
5347: equivalent of "This is a searchable index. Insert your search
5348: keywords here: (input field)" in the user's preferred
5349: language.</p>
5350:
5351: </dd>
5352:
5353: <dt>A start tag whose tag name is "textarea"</dt>
5354: <dd>
5355:
5356: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
5357: token.</p></li>
5358:
5359: <li><p>If the next token is a U+000A LINE FEED (LF) character
5360: token, then ignore that token and move on to the next
5361: one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
5362: ignored as an authoring convenience.)</p></li>
5363:
5364: <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
5365: the RCDATA state.</p></li>
5366:
5367: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
5368: current <a href="#insertion-mode">insertion mode</a>.</p>
5369:
5370: </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
5371: ok".</p></li>
5372:
1.91 mike 5373: <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
5374: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 5375:
5376: </ol></dd>
5377:
5378: <dt>A start tag whose tag name is "xmp"</dt>
5379: <dd>
5380:
1.233 mike 5381: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5382: an element in scope">has a <code>p</code> element in
5383: scope</a>, then act as if an end tag with the tag name
5384: "p" had been seen.</p>
5385:
1.1 mike 5386: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5387: any.</p>
5388:
5389: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5390:
1.91 mike 5391: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5392:
5393: </dd>
5394:
5395: <dt>A start tag whose tag name is "iframe"</dt>
5396: <dd>
5397:
5398: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5399:
1.91 mike 5400: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5401:
5402: </dd>
5403:
5404: <dt>A start tag whose tag name is "noembed"</dt>
5405: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
5406: <dd>
5407:
1.91 mike 5408: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5409:
5410: </dd>
5411:
5412: <dt>A start tag whose tag name is "select"</dt>
5413: <dd>
5414:
5415: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5416: any.</p>
5417:
5418: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5419:
5420: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5421:
5422: <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>",
5423: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
5424: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
5425: row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
5426: cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
5427: "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
5428: table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
5429: to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
5430:
5431: </dd>
5432:
5433: <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
5434: <dd>
5435:
5436: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5437: element in scope">has an <code>option</code> element in
5438: scope</a>, then act as if an end tag with the tag name "option"
5439: had been seen.</p>
5440:
5441: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5442: any.</p>
5443:
5444: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5445:
5446: </dd>
5447:
5448: <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
5449: <dd>
5450:
5451: <!-- the parsing rules for ruby really don't match IE much at all,
5452: but in practice the markup used is very simple and so strict
5453: compatibility with IE isn't required. For example, as defined
5454: here we get very, very different behaviour than IE for
5455: pathological cases like:
5456:
5457: <ruby><ol><li><p>a<rt>b
5458: <ruby>a<rt>b<p>c
5459:
5460: But in practice most ruby markup falls into these cases:
5461:
5462: <ruby>a<rt>b</ruby>
5463: <ruby>a<rp>b<rt>c<rp>d</ruby>
5464: <ruby>a<rt>b</rt></ruby>
5465: <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
5466:
5467: -->
5468:
5469: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5470: element in scope">has a <code>ruby</code> element in scope</a>,
5471: then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
5472: node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
5473: <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
5474: node</a> up to the node immediately before the bottommost
5475: <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
5476: elements</a>.</p>
5477:
5478: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5479:
5480: </dd>
5481:
5482: <dt>An end tag whose tag name is "br"</dt>
5483: <dd>
5484: <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
5485: the tag name "br" had been seen. Ignore the end tag token.</p>
5486: </dd>
5487:
5488: <dt>A start tag whose tag name is "math"</dt>
5489: <dd>
5490:
5491: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5492: any.</p>
5493:
5494: <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
5495: fixes the case of MathML attributes that are not all
5496: lowercase.)</p>
5497:
5498: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
5499: fixes the use of namespaced attributes, in particular XLink.)</p>
5500:
5501: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
5502: <a href="#mathml-namespace">MathML namespace</a>.</p>
5503:
5504: <!-- If we ever change the frameset-ok flag to an insertion mode,
5505: the following change would be implied, except we'd have to do it
5506: even in the face of a self-closed tag:
5507: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
5508: -->
5509:
5510: <p>If the token has its <i>self-closing flag</i> set, pop the
5511: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5512: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
5513: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
5514:
5515: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
5516: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
5517: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
5518: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
5519: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
5520: foreign content">in foreign content</a>".</p>
5521:
5522: </dd>
5523:
5524: <dt>A start tag whose tag name is "svg"</dt>
5525: <dd>
5526:
5527: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5528: any.</p>
5529:
5530: <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
5531: the case of SVG attributes that are not all lowercase.)</p>
5532:
5533: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
5534: fixes the use of namespaced attributes, in particular XLink in
5535: SVG.)</p>
5536:
5537: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
5538: <a href="#svg-namespace">SVG namespace</a>.</p>
5539:
5540: <!-- If we ever change the frameset-ok flag to an insertion mode,
5541: the following change would be implied, except we'd have to do it
5542: even in the face of a self-closed tag:
5543: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
5544: -->
5545:
5546: <p>If the token has its <i>self-closing flag</i> set, pop the
5547: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5548: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
5549: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
5550:
5551: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
5552: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
5553: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
5554: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
5555: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
5556: foreign content">in foreign content</a>".</p>
5557:
5558: </dd>
5559:
5560: <dt>A start <!--or end--> tag whose tag name is one of: "caption",
5561: "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
5562: "thead", "tr"</dt>
5563: <!--<dt>An end tag whose tag name is one of: "area", "base",
5564: "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
5565: "img", "input", "isindex", "keygen", "link", "meta", "noembed",
5566: "noframes", "param", "script", "select", "source", "spacer",
5567: "style", "table", "textarea", "title", "wbr"</dt>-->
5568: <!--<dt>An end tag whose tag name is "noscript", if the
5569: <span>scripting flag</span> is enabled</dt>-->
5570: <dd>
5571: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5572: <!-- end tags are commented out because since they can never end
5573: up on the stack anyway, the default end tag clause will
5574: automatically handle them. we don't want to have text in the spec
5575: that is just an optimisation, as that detracts from the spec
5576: itself -->
5577: </dd>
5578:
5579: <dt>Any other start tag</dt>
5580: <dd>
5581:
5582: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5583: any.</p>
5584:
5585: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5586:
5587: <p class="note">This element will be a <a href="#phrasing">phrasing</a>
5588: element.</p>
5589:
5590: </dd>
5591:
5592: <dt>Any other end tag</dt>
5593: <dd>
5594:
5595: <p>Run the following steps:</p>
5596:
5597: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
5598: node</a> (the bottommost node of the stack).</p></li>
5599:
5600: <li><p>If <var title="">node</var> has the same tag name as
5601: the end tag token, then:</p>
5602:
5603: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5604:
5605: <li><p>If the tag name of the end tag token does not match
5606: the tag name of the <a href="#current-node">current node</a>, this is a
5607: <a href="#parse-error">parse error</a>.</p></li>
5608:
5609: <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
5610: to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
5611:
5612: </ol></li>
5613:
5614: <li><p>Otherwise, if <var title="">node</var> is in neither the
5615: <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
5616: category, then this is a <a href="#parse-error">parse error</a>; ignore the
5617: token, and abort these steps.</p></li>
5618:
5619: <li><p>Set <var title="">node</var> to the previous entry in the
5620: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
5621:
5622: <li><p>Return to step 2.</p></li>
5623:
5624: </ol></dd>
5625:
1.91 mike 5626: </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 5627:
5628: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.91 mike 5629: mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>", tokens must be
1.1 mike 5630: handled as follows:</p>
5631:
5632: <dl class="switch"><dt>A character token</dt>
5633: <dd>
5634:
5635: <p><a href="#insert-a-character" title="insert a character">Insert the token's
5636: character</a> into the <a href="#current-node">current node</a>.</p>
5637:
5638: </dd>
5639:
5640: <dt>An end-of-file token</dt>
5641: <dd>
5642:
5643: <!-- can't be the fragment case -->
5644: <p><a href="#parse-error">Parse error</a>.</p>
5645:
5646: <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
5647: element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
5648: executed"</a>.</p>
5649:
5650: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5651: elements</a>.</p>
5652:
5653: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5654: insertion mode</a> and reprocess the current token.</p>
5655:
5656: </dd>
5657:
5658: <dt>An end tag whose tag name is "script"</dt>
5659: <dd>
5660:
5661: <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
5662: (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
5663:
5664: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5665: elements</a>.</p>
5666:
5667: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5668: insertion mode</a>.</p>
5669:
5670: <p>Let the <var title="">old insertion point</var> have the
5671: same value as the current <a href="#insertion-point">insertion point</a>. Let
5672: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
5673: input character</a>.</p>
5674:
5675: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
5676: one.</p>
5677:
5678: <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 5679: which might cause <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters
1.1 mike 5680: to be inserted into the tokenizer</a>, and might cause the
5681: tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
5682:
5683: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
5684: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
5685: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
5686:
5687: <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
5688: <a href="#insertion-point">insertion point</a> to its previous value. This value
5689: might be the "undefined" value.)</p>
5690:
5691: <p id="scriptTagParserResumes">At this stage, if there is a
5692: <a href="semantics.html#pending-external-script">pending external script</a>, then:</p>
5693:
5694: <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
5695:
5696: <dd>
5697:
5698: <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
5699: processing of any nested invocations of the tokenizer, yielding
5700: control back to the caller. (Tokenization will resume when the
5701: caller returns to the "outer" tree construction stage.)</p>
5702:
5703: <p class="note">The tree construction stage of this particular
5704: parser is <a href="#nestedParsing">being called reentrantly</a>,
1.159 mike 5705: 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 5706:
5707: </dd>
5708:
5709:
5710: <dt>Otherwise:</dt>
5711:
5712: <dd>
5713:
5714: <p>Follow these steps:</p>
5715:
5716: <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-external-script">pending
5717: external script</a>. There is no longer a <a href="semantics.html#pending-external-script">pending
5718: external script</a>.</p></li>
5719:
5720: <li><p><a href="browsers.html#pause">Pause</a> until the script has <a href="semantics.html#completed-loading">completed
5721: loading</a>.</p></li>
5722:
5723: <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
5724: <a href="#next-input-character">next input character</a>.</p></li>
5725:
5726: <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
5727: by one (it should be zero before this step, so this sets it to
5728: one).</p></li>
5729:
5730: <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute the
5731: script</a>.</p></li>
5732:
5733: <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
5734: by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
5735: zero (which it always should be at this point), then set the
5736: <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
5737:
5738: </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
5739: again.</p></li>
5740:
5741: <li><p>If there is once again a <a href="semantics.html#pending-external-script">pending external
5742: script</a>, then repeat these steps from step 1.</p></li>
5743:
5744: </ol></dd>
5745:
5746: </dl></dd>
5747:
5748: <dt>Any other end tag</dt>
5749: <dd>
5750:
5751: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5752: elements</a>.</p>
5753:
5754: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5755: insertion mode</a>.</p>
5756:
5757: </dd>
5758:
5759: </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>
5760:
5761: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
5762: mode: in table">in table</a>", tokens must be handled as follows:</p>
5763:
5764: <dl class="switch"><dt>A character token</dt>
5765: <dd>
5766:
5767: <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
5768: be an empty list of tokens.</p>
5769:
5770: <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
5771: <a href="#insertion-mode">insertion mode</a>.</p>
5772:
5773: <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
5774: reprocess the token.</p>
5775:
5776: </dd>
5777:
5778: <dt>A comment token</dt>
5779: <dd>
5780: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
5781: node</a> with the <code title="">data</code> attribute set to
5782: the data given in the comment token.</p>
5783: </dd>
5784:
5785: <dt>A DOCTYPE token</dt>
5786: <dd>
5787: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5788: </dd>
5789:
5790: <dt>A start tag whose tag name is "caption"</dt>
5791: <dd>
5792:
5793: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5794: below.)</p>
5795:
5796: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5797: formatting elements</a>.</p>
5798:
5799: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5800: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
5801:
5802: </dd>
5803:
5804: <dt>A start tag whose tag name is "colgroup"</dt>
5805: <dd>
5806:
5807: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5808: below.)</p>
5809:
5810: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5811: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
5812: group</a>".</p>
5813:
5814: </dd>
5815:
5816: <dt>A start tag whose tag name is "col"</dt>
5817: <dd>
5818: <p>Act as if a start tag token with the tag name "colgroup"
5819: had been seen, then reprocess the current token.</p>
5820: </dd>
5821:
5822: <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
5823: <dd>
5824:
5825: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5826: below.)</p>
5827:
5828: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5829: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
5830: body</a>".</p>
5831:
5832: </dd>
5833:
5834: <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
5835: <dd>
5836: <p>Act as if a start tag token with the tag name "tbody" had
5837: been seen, then reprocess the current token.</p>
5838: </dd>
5839:
5840: <dt>A start tag whose tag name is "table"</dt>
5841: <dd>
5842:
5843: <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
5844: the tag name "table" had been seen, then, if that token wasn't
5845: ignored, reprocess the current token.</p>
5846:
5847: <p class="note">The fake end tag token here can only be
5848: ignored in the <a href="#fragment-case">fragment case</a>.</p>
5849:
5850: </dd>
5851:
5852: <dt>An end tag whose tag name is "table"</dt>
5853: <dd>
5854:
5855: <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
5856: scope</a> with the same tag name as the token, this is a
5857: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
5858: case</a>)</p>
5859:
5860: <p>Otherwise:</p>
5861:
5862: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
5863: element has been popped from the stack.</p>
5864:
5865: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
5866:
5867: </dd>
5868:
5869: <dt>An end tag whose tag name is one of: "body", "caption",
5870: "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
5871: "thead", "tr"</dt>
5872: <dd>
5873: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5874: </dd>
5875:
5876: <dt>A start tag whose tag name is one of: "style", "script"</dt>
5877: <dd>
5878:
5879: <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
5880: mode</a>.</p>
5881:
5882: </dd>
5883:
5884: <dt>A start tag whose tag name is "input"</dt>
5885: <dd>
5886:
5887: <p>If the token does not have an attribute with the name "type",
5888: or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
5889: case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
5890: else" entry below.</p>
5891:
5892: <p>Otherwise:</p>
5893:
5894: <p><a href="#parse-error">Parse error</a>.</p>
5895:
5896: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5897:
5898: <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
5899: open elements</a>.</p>
5900:
5901: </dd>
5902:
5903: <dt>An end-of-file token</dt>
5904: <dd>
5905:
5906: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 5907: <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 5908: error</a>.</p>
5909:
5910: <p class="note">It can only be the <a href="#current-node">current node</a> in
5911: the <a href="#fragment-case">fragment case</a>.</p>
5912:
5913: <p><a href="#stop-parsing">Stop parsing</a>.</p>
5914:
5915: </dd>
5916:
5917: <dt>Anything else</dt>
5918: <dd>
5919:
5920: <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
5921: rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
5922: body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
5923: <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
5924: <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
5925: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
5926: into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
5927:
5928: </dd>
5929:
5930: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
5931: back to a table context</dfn>, it means that the UA must, while
5932: 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 5933: element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1 mike 5934: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
5935:
5936: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 5937: <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 5938: case</a>.</p>
5939:
5940:
5941:
5942: <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>
5943:
5944: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
5945: mode: in table text">in table text</a>", tokens must be handled
5946: as follows:</p>
5947:
5948: <dl class="switch"><dt>A character token</dt>
5949: <dd>
5950:
5951: <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
5952: tokens</a></var> list.</p>
5953:
5954: </dd>
5955:
5956:
5957: <dt>Anything else</dt>
5958: <dd>
5959:
5960: <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
5961: tokens</a></var> list are character tokens that are not one of U+0009
5962: CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
5963: (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
5964: reprocess those character tokens using the rules given in the
5965: "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
5966: table">in table</a>" insertion mode.</p>
5967:
5968: <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
5969: characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
5970: tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
5971:
5972: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5973: insertion mode</a> and reprocess the token.</p>
5974:
5975: </dd>
5976:
5977: </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>
5978:
5979: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
5980: mode: in caption">in caption</a>", tokens must be handled as follows:</p>
5981:
5982: <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
5983: <dd>
5984:
5985: <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
5986: scope</a> with the same tag name as the token, this is a
5987: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
5988: case</a>)</p>
5989:
5990: <p>Otherwise:</p>
5991:
5992: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
5993:
5994: <p>Now, if the <a href="#current-node">current node</a> is not a
5995: <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
5996: error</a>.</p>
5997:
5998: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
5999: element has been popped from the stack.</p>
6000:
6001: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
6002: the last marker</a>.</p>
6003:
6004: <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>
6005:
6006: </dd>
6007:
6008: <dt>A start tag whose tag name is one of: "caption", "col",
6009: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
6010: <dt>An end tag whose tag name is "table"</dt>
6011: <dd>
6012:
6013: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
6014: name "caption" had been seen, then, if that token wasn't
6015: ignored, reprocess the current token.</p>
6016:
6017: <p class="note">The fake end tag token here can only be
6018: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6019:
6020: </dd>
6021:
6022: <dt>An end tag whose tag name is one of: "body", "col",
6023: "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
6024: "tr"</dt>
6025: <dd>
6026: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6027: </dd>
6028:
6029: <dt>Anything else</dt>
6030: <dd>
6031: <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
6032: mode</a>.</p>
6033: </dd>
6034:
6035: </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>
6036:
6037: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
6038: mode: in column group">in column group</a>", tokens must be handled as follows:</p>
6039:
6040: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6041: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6042: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6043: <dd>
6044: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6045: the <a href="#current-node">current node</a>.</p>
6046: </dd>
6047:
6048: <dt>A comment token</dt>
6049: <dd>
6050: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6051: node</a> with the <code title="">data</code> attribute set to
6052: the data given in the comment token.</p>
6053: </dd>
6054:
6055: <dt>A DOCTYPE token</dt>
6056: <dd>
6057: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6058: </dd>
6059:
6060: <dt>A start tag whose tag name is "html"</dt>
6061: <dd>
6062: <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
6063: mode</a>.</p>
6064: </dd>
6065:
6066: <dt>A start tag whose tag name is "col"</dt>
6067: <dd>
6068:
6069: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
6070: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6071: elements</a>.</p>
6072:
6073: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6074: token's <i>self-closing flag</i></a>, if it is set.</p>
6075:
6076: </dd>
6077:
6078: <dt>An end tag whose tag name is "colgroup"</dt>
6079: <dd>
6080:
6081: <p>If the <a href="#current-node">current node</a> is the root
1.159 mike 6082: <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 6083: error</a>; ignore the token. (<a href="#fragment-case">fragment
6084: case</a>)</p>
6085:
6086: <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
6087: 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
6088: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
6089: "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
6090:
6091: </dd>
6092:
6093: <dt>An end tag whose tag name is "col"</dt>
6094: <dd>
6095: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6096: </dd>
6097:
6098: <dt>An end-of-file token</dt>
6099: <dd>
6100:
1.159 mike 6101: <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 6102: element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
6103: case</a>)</p>
6104:
6105: <p>Otherwise, act as described in the "anything else" entry
6106: below.</p>
6107:
6108: </dd>
6109:
6110: <dt>Anything else</dt>
6111: <dd>
6112:
6113: <p>Act as if an end tag with the tag name "colgroup" had been
6114: seen, and then, if that token wasn't ignored, reprocess the
6115: current token.</p>
6116:
6117: <p class="note">The fake end tag token here can only be
6118: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6119:
6120: </dd>
6121:
6122: </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>
6123:
6124: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
6125: mode: in table body">in table body</a>", tokens must be handled as follows:</p>
6126:
6127: <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
6128: <dd>
6129:
6130: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6131: context</a>. (See below.)</p>
6132:
6133: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
6134: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
6135: in row">in row</a>".</p>
6136:
6137: </dd>
6138:
6139: <dt>A start tag whose tag name is one of: "th", "td"</dt>
6140: <dd>
6141: <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
6142: the tag name "tr" had been seen, then reprocess the current
6143: token.</p>
6144: </dd>
6145:
6146: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
6147: "thead"</dt>
6148: <dd>
6149:
6150: <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
6151: scope</a> with the same tag name as the token, this is a
6152: <a href="#parse-error">parse error</a>. Ignore the token.</p>
6153:
6154: <p>Otherwise:</p>
6155:
6156: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6157: context</a>. (See below.)</p>
6158:
6159: <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
6160: open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
6161: to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
6162:
6163: </dd>
6164:
6165: <dt>A start tag whose tag name is one of: "caption", "col",
6166: "colgroup", "tbody", "tfoot", "thead"</dt>
6167: <dt>An end tag whose tag name is "table"</dt>
6168: <dd>
6169:
6170: <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
6171: <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
6172: element in table scope</a>, this is a <a href="#parse-error">parse
6173: error</a>. Ignore the token. (<a href="#fragment-case">fragment
6174: case</a>)</p>
6175:
6176: <p>Otherwise:</p>
6177:
6178: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6179: context</a>. (See below.)</p>
6180:
6181: <p>Act as if an end tag with the same tag name as the
6182: <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
6183: been seen, then reprocess the current token.</p>
6184:
6185: </dd>
6186:
6187: <dt>An end tag whose tag name is one of: "body", "caption",
6188: "col", "colgroup", "html", "td", "th", "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-intable" title="insertion mode: in table">in table</a>" <a href="#insertion-mode">insertion
6196: mode</a>.</p>
6197: </dd>
6198:
6199: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
6200: back to a table body context</dfn>, it means that the UA must,
6201: 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 6202: <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 6203: element, pop elements from the <a href="#stack-of-open-elements">stack of open
6204: elements</a>.</p>
6205:
6206: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 6207: <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 6208: case</a>.</p>
6209:
6210:
6211: <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>
6212:
6213: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
6214: mode: in row">in row</a>", tokens must be handled as follows:</p>
6215:
6216: <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
6217: <dd>
6218:
6219: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
6220: context</a>. (See below.)</p>
6221:
6222: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
6223: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
6224: in cell">in cell</a>".</p>
6225:
6226: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
6227: formatting elements</a>.</p>
6228:
6229: </dd>
6230:
6231: <dt>An end tag whose tag name is "tr"</dt>
6232: <dd>
6233:
6234: <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
6235: scope</a> with the same tag name as the token, this is a
6236: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6237: case</a>)</p>
6238:
6239: <p>Otherwise:</p>
6240:
6241: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
6242: context</a>. (See below.)</p>
6243:
6244: <p>Pop the <a href="#current-node">current node</a> (which will be a
6245: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
6246: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
6247: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
6248: body</a>".</p>
6249:
6250: </dd>
6251:
6252: <dt>A start tag whose tag name is one of: "caption", "col",
6253: "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
6254: <dt>An end tag whose tag name is "table"</dt>
6255: <dd>
6256:
6257: <p>Act as if an end tag with the tag name "tr" had been seen,
6258: then, if that token wasn't ignored, reprocess the current
6259: token.</p>
6260:
6261: <p class="note">The fake end tag token here can only be
6262: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6263:
6264: </dd>
6265:
6266: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
6267: "thead"</dt>
6268: <dd>
6269:
6270: <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
6271: scope</a> with the same tag name as the token, this is a
6272: <a href="#parse-error">parse error</a>. Ignore the token.</p>
6273:
6274: <p>Otherwise, act as if an end tag with the tag name "tr" had
6275: been seen, then reprocess the current token.</p>
6276:
6277: </dd>
6278:
6279: <dt>An end tag whose tag name is one of: "body", "caption",
6280: "col", "colgroup", "html", "td", "th"</dt>
6281: <dd>
6282: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6283: </dd>
6284:
6285: <dt>Anything else</dt>
6286: <dd>
6287: <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
6288: mode</a>.</p>
6289: </dd>
6290:
6291: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
6292: back to a table row context</dfn>, it means that the UA must,
6293: 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 6294: element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1 mike 6295: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6296:
6297: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 6298: <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 6299: case</a>.</p>
6300:
6301:
6302: <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>
6303:
6304: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
6305: mode: in cell">in cell</a>", tokens must be handled as follows:</p>
6306:
6307: <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
6308: <dd>
6309:
6310: <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
6311: scope</a> with the same tag name as that of the token, then
6312: this is a <a href="#parse-error">parse error</a> and the token must be
6313: ignored.</p>
6314:
6315: <p>Otherwise:</p>
6316:
6317: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
6318:
6319: <p>Now, if the <a href="#current-node">current node</a> is not an element
6320: with the same tag name as the token, then this is a
6321: <a href="#parse-error">parse error</a>.</p>
6322:
6323: <p>Pop elements from this stack until an element with the same
6324: tag name as the token has been popped from the stack.</p>
6325:
6326: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
6327: the last marker</a>.</p>
6328:
6329: <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
6330: <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
6331: this point.)</p>
6332:
6333: </dd>
6334:
6335: <dt>A start tag whose tag name is one of: "caption", "col",
6336: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
6337: <dd>
6338:
6339: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
6340: <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
6341: a <code>td</code> or <code>th</code> element in table
6342: scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
6343: the token. (<a href="#fragment-case">fragment case</a>)</p>
6344:
6345: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
6346: reprocess the current token.</p>
6347:
6348: </dd>
6349:
6350: <dt>An end tag whose tag name is one of: "body", "caption",
6351: "col", "colgroup", "html"</dt>
6352: <dd>
6353: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6354: </dd>
6355:
6356: <dt>An end tag whose tag name is one of: "table", "tbody",
6357: "tfoot", "thead", "tr"</dt>
6358: <dd>
6359:
6360: <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
6361: scope</a> with the same tag name as that of the token
6362: (which can only happen for "tbody", "tfoot" and "thead", or,
6363: in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
6364: error</a> and the token must be ignored.</p>
6365:
6366: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
6367: reprocess the current token.</p>
6368:
6369: </dd>
6370:
6371: <dt>Anything else</dt>
6372: <dd>
6373: <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
6374: mode</a>.</p>
6375: </dd>
6376:
6377: </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
6378: mean to run the following algorithm:</p>
6379:
6380: <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>
6381: element in table scope</a>, then act as if an end tag token
6382: with the tag name "td" had been seen.</p></li>
6383:
6384: <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
6385: <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
6386: <code>th</code> element in table scope</a>; act as if an end
6387: tag token with the tag name "th" had been seen.</p></li>
6388:
6389: </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
6390: 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
6391: the same time, nor can it have neither when the <a href="#insertion-mode">insertion
6392: mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
6393: cell</a>".</p>
6394:
6395:
6396: <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>
6397:
6398: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
6399: mode: in select">in select</a>", tokens must be handled as follows:</p>
6400:
6401: <dl class="switch"><dt>A character token</dt>
6402: <dd>
6403: <p><a href="#insert-a-character" title="insert a character">Insert the token's
6404: character</a> into the <a href="#current-node">current node</a>.</p>
6405: </dd>
6406:
6407: <dt>A comment token</dt>
6408: <dd>
6409: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6410: node</a> with the <code title="">data</code> attribute set to
6411: the data given in the comment token.</p>
6412: </dd>
6413:
6414: <dt>A DOCTYPE token</dt>
6415: <dd>
6416: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6417: </dd>
6418:
6419: <dt>A start tag whose tag name is "html"</dt>
6420: <dd>
6421: <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
6422: mode</a>.</p>
6423: </dd>
6424:
6425: <dt>A start tag whose tag name is "option"</dt>
6426: <dd>
6427:
6428: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6429: element, act as if an end tag with the tag name "option" had
6430: been seen.</p>
6431:
6432: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6433:
6434: </dd>
6435:
6436: <dt>A start tag whose tag name is "optgroup"</dt>
6437: <dd>
6438:
6439: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6440: element, act as if an end tag with the tag name "option" had
6441: been seen.</p>
6442:
6443: <p>If the <a href="#current-node">current node</a> is an
6444: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
6445: tag name "optgroup" had been seen.</p>
6446:
6447: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6448:
6449: </dd>
6450:
6451: <dt>An end tag whose tag name is "optgroup"</dt>
6452: <dd>
6453:
6454: <p>First, if the <a href="#current-node">current node</a> is an
6455: <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
6456: it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
6457: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
6458: the tag name "option" had been seen.</p>
6459:
6460: <p>If the <a href="#current-node">current node</a> is an
6461: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
6462: <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
6463: <a href="#parse-error">parse error</a>; ignore the token.</p>
6464:
6465: </dd>
6466:
6467: <dt>An end tag whose tag name is "option"</dt>
6468: <dd>
6469:
6470: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6471: element, then pop that node from the <a href="#stack-of-open-elements">stack of open
6472: elements</a>. Otherwise, this is a <a href="#parse-error">parse
6473: error</a>; ignore the token.</p>
6474:
6475: </dd>
6476:
6477: <dt>An end tag whose tag name is "select"</dt>
6478: <dd>
6479:
6480: <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
6481: scope</a> with the same tag name as the token, this is a
6482: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6483: case</a>)</p>
6484:
6485: <p>Otherwise:</p>
6486:
6487: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
6488: until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
6489: stack.</p>
6490:
6491: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
6492:
6493: </dd>
6494:
6495: <dt>A start tag whose tag name is "select"</dt>
6496: <dd>
6497:
6498: <p><a href="#parse-error">Parse error</a>. Act as if the token had been
6499: an end tag with the tag name "select" instead.</p>
6500:
6501: </dd>
6502:
6503: <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
6504: <dd>
1.73 mike 6505:
6506: <p><a href="#parse-error">Parse error</a>.</p>
6507:
1.124 mike 6508: <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>
6509: element in table scope</a>, ignore the token. (<a href="#fragment-case">fragment
6510: case</a>)</p>
1.73 mike 6511:
6512: <p>Otherwise, act as if an end tag with the tag name "select" had
6513: been seen, and reprocess the token.</p>
6514:
1.1 mike 6515: </dd>
6516:
6517: <dt>A start tag token whose tag name is "script"</dt>
6518: <dd>
6519: <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
6520: mode</a>.</p>
6521: </dd>
6522:
6523: <dt>An end-of-file token</dt>
6524: <dd>
6525:
6526: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 6527: <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 6528: error</a>.</p>
6529:
6530: <p class="note">It can only be the <a href="#current-node">current node</a> in
6531: the <a href="#fragment-case">fragment case</a>.</p>
6532:
6533: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6534:
6535: </dd>
6536:
6537: <dt>Anything else</dt>
6538: <dd>
6539: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6540: </dd>
6541:
6542: </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>
6543:
6544: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
6545: mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
6546:
6547: <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
6548: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
6549: <dd>
6550: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
6551: name "select" had been seen, and reprocess the token.</p>
6552: </dd>
6553:
6554: <dt>An end tag whose tag name is one of: "caption", "table",
6555: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
6556: <dd>
6557:
6558: <p><a href="#parse-error">Parse error</a>.</p>
6559:
6560: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
6561: element in table scope</a> with the same tag name as that
6562: of the token, then act as if an end tag with the tag name
6563: "select" had been seen, and reprocess the token. Otherwise,
6564: ignore the token.</p>
6565:
6566: </dd>
6567:
6568: <dt>Anything else</dt>
6569: <dd>
6570: <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
6571: mode</a>.</p>
6572: </dd>
6573:
1.168 mike 6574: </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 6575:
6576: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
6577: mode: in foreign content">in foreign content</a>", tokens must be
6578: handled as follows:</p>
6579:
6580: <dl class="switch"><dt>A character token</dt>
6581: <dd>
6582:
6583: <p><a href="#insert-a-character" title="insert a character">Insert the token's
6584: character</a> into the <a href="#current-node">current node</a>.</p>
6585:
6586: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
6587: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
6588: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
6589: flag</a> to "not ok".</p>
6590:
6591: </dd>
6592:
6593: <dt>A comment token</dt>
6594: <dd>
6595: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6596: node</a> with the <code title="">data</code> attribute set to
6597: the data given in the comment token.</p>
6598: </dd>
6599:
6600: <dt>A DOCTYPE token</dt>
6601: <dd>
6602: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6603: </dd>
6604:
6605: <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>
6606: <dd>
6607:
6608: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6609: elements</a>.</p>
6610:
6611: <p>Let the <var title="">old insertion point</var> have the
6612: same value as the current <a href="#insertion-point">insertion point</a>. Let
6613: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
6614: input character</a>.</p>
6615:
6616: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
6617: one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
6618:
6619: <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
6620: the <code title="">script</code> element</a> according to the SVG
1.187 mike 6621: rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
1.1 mike 6622:
1.159 mike 6623: <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 6624: tokenizer</a>, the parser will not be executed reentrantly,
6625: since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
6626:
6627: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
6628: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
6629: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
6630:
6631: <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
6632: <a href="#insertion-point">insertion point</a> to its previous value. This value
6633: might be the "undefined" value.)</p>
6634:
6635: </dd>
6636:
6637: <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>
6638: <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>
6639: <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>
6640: <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>
6641: <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>
6642: <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>
6643: <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>
6644: <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>
6645: <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>
6646: <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>
6647: <dt>An end tag</dt>
6648: <dd>
6649:
6650: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
6651: <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
6652:
6653: <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
6654: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
1.336 mike 6655: content</a>", but there is no element <a href="#has-an-element-in-scope" title="has an
6656: element in scope">in scope</a> that has a namespace other than
6657: the <a href="#html-namespace-0">HTML namespace</a>, switch the <a href="#insertion-mode">insertion
1.1 mike 6658: mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
6659:
6660: </dd>
6661:
6662: <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
6663: "blockquote", "body"<!--by inspection-->, "br", "center", "code",
1.422 mike 6664: "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
6665: uniformly throughout the parser -->, "em", "embed", "h1", "h2",
6666: "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
1.1 mike 6667: completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
6668: "li", "listing"<!-- so that pre and listing can be handled
6669: uniformly throughout the parser -->, "menu", "meta", "nobr",
6670: "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
6671: the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
6672: "span", "strong", "strike"<!-- so that s and strike can be handled
6673: uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
1.305 mike 6674: "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt> <!-- this
6675: list was determined empirically by studying over 6,000,000,000
1.422 mike 6676: pages that were specifically not XML pages -->
6677: <dt>A start tag whose tag name is "font", if the token has any
6678: attributes named "color", "face", or "size"</dt> <!-- the
6679: attributes here are required so that SVG <font> will go through as
6680: SVG but legacy <font>s won't -->
6681: <dt>An end-of-file token</dt> <dd>
1.1 mike 6682:
6683: <p><a href="#parse-error">Parse error</a>.</p>
6684:
6685: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
6686: the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
6687: namespace</a>.</p>
6688:
6689: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
6690: insertion mode</a>, and reprocess the token.</p>
6691:
6692: </dd>
6693:
6694: <dt>Any other start tag</dt>
6695: <dd>
6696:
6697: <p>If the <a href="#current-node">current node</a> is an element in the
6698: <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
6699: attributes</a> for the token. (This fixes the case of MathML
6700: attributes that are not all lowercase.)</p>
6701:
6702: <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
6703: namespace</a>, and the token's tag name is one of the ones in
6704: the first column of the following table, change the tag name to
6705: the name given in the corresponding cell in the second
6706: column. (This fixes the case of SVG elements that are not all
6707: lowercase.)</p>
6708:
6709: <table><thead><tr><th> Tag name </th><th> Element name
6710: </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
6711: </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
6712: </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
6713: </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
6714: </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
6715: </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
6716: </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
6717: </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
6718: </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
6719: </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
6720: </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
6721: </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
6722: </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
6723: </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
6724: </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
6725: </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
6726: </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
6727: </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
6728: </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
6729: </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
6730: </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
6731: </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
6732: </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
6733: </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
6734: </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
6735: </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
6736: </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
6737: </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
6738: </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
6739: </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
6740: </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
6741: </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
6742: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
6743: </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
6744: </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
6745: <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
6746: </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
6747: </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
6748: namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
6749: token. (This fixes the case of SVG attributes that are not all
6750: lowercase.)</p>
6751:
6752: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
6753: fixes the use of namespaced attributes, in particular XLink in
6754: SVG.)</p>
6755:
6756: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
6757: same namespace as the <a href="#current-node">current node</a>.</p>
6758:
6759: <p>If the token has its <i>self-closing flag</i> set, pop the
6760: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6761: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
6762: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
6763:
6764: </dd>
6765:
6766: </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>
6767:
6768: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
6769: mode: after body">after body</a>", tokens must be handled as follows:</p>
6770:
6771: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6772: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6773: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6774: <dd>
6775: <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
6776: mode</a>.</p>
6777: </dd>
6778:
6779: <dt>A comment token</dt>
6780: <dd>
6781: <p>Append a <code>Comment</code> node to the first element in
1.159 mike 6782: 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 6783: element), with the <code title="">data</code> attribute set to
6784: the data given in the comment token.</p>
6785: </dd>
6786:
6787: <dt>A DOCTYPE token</dt>
6788: <dd>
6789: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6790: </dd>
6791:
6792: <dt>A start tag whose tag name is "html"</dt>
6793: <dd>
6794: <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
6795: mode</a>.</p>
6796: </dd>
6797:
6798: <dt>An end tag whose tag name is "html"</dt>
6799: <dd>
6800:
6801: <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
6802: fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
6803: error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
6804:
6805: <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
6806: body</a>".</p>
6807:
6808: </dd>
6809:
6810: <dt>An end-of-file token</dt>
6811: <dd>
6812: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6813: </dd>
6814:
6815: <dt>Anything else</dt>
6816: <dd>
6817:
6818: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
6819: mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
6820: body</a>" and reprocess the token.</p>
6821:
6822: </dd>
6823:
6824: </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>
6825:
6826: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
6827: mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
6828:
6829: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6830: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6831: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6832: <dd>
6833: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6834: the <a href="#current-node">current node</a>.</p>
6835: </dd>
6836:
6837: <dt>A comment token</dt>
6838: <dd>
6839: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6840: node</a> with the <code title="">data</code> attribute set to
6841: the data given in the comment token.</p>
6842: </dd>
6843:
6844: <dt>A DOCTYPE token</dt>
6845: <dd>
6846: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6847: </dd>
6848:
6849: <dt>A start tag whose tag name is "html"</dt>
6850: <dd>
6851: <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
6852: mode</a>.</p>
6853: </dd>
6854:
6855: <dt>A start tag whose tag name is "frameset"</dt>
6856: <dd>
6857: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6858: </dd>
6859:
6860: <dt>An end tag whose tag name is "frameset"</dt>
6861: <dd>
6862:
6863: <p>If the <a href="#current-node">current node</a> is the root
1.159 mike 6864: <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 6865: error</a>; ignore the token. (<a href="#fragment-case">fragment
6866: case</a>)</p>
6867:
6868: <p>Otherwise, pop the <a href="#current-node">current node</a> from the
6869: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6870:
6871: <p>If the parser was <em>not</em> originally created as part
6872: of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
6873: (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5 mike 6874: node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1 mike 6875: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
6876: frameset</a>".</p>
6877:
6878: </dd>
6879:
6880: <dt>A start tag whose tag name is "frame"</dt>
6881: <dd>
6882:
6883: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
6884: Immediately pop the <a href="#current-node">current node</a> off the
6885: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6886:
6887: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6888: token's <i>self-closing flag</i></a>, if it is set.</p>
6889:
6890: </dd>
6891:
6892: <dt>A start tag whose tag name is "noframes"</dt>
6893: <dd>
6894: <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
6895: mode</a>.</p>
6896: </dd>
6897:
6898: <dt>An end-of-file token</dt>
6899: <dd>
6900:
6901: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 6902: <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 6903: error</a>.</p>
6904:
6905: <p class="note">It can only be the <a href="#current-node">current node</a> in
6906: the <a href="#fragment-case">fragment case</a>.</p>
6907:
6908: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6909:
6910: </dd>
6911:
6912: <dt>Anything else</dt>
6913: <dd>
6914: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6915: </dd>
6916:
6917: </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>
6918:
6919: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
6920: mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
6921:
6922: <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
6923: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6924: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6925: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6926: <dd>
6927: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6928: the <a href="#current-node">current node</a>.</p>
6929: </dd>
6930:
6931: <dt>A comment token</dt>
6932: <dd>
6933: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6934: node</a> with the <code title="">data</code> attribute set to
6935: the data given in the comment token.</p>
6936: </dd>
6937:
6938: <dt>A DOCTYPE token</dt>
6939: <dd>
6940: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6941: </dd>
6942:
6943: <dt>A start tag whose tag name is "html"</dt>
6944: <dd>
6945: <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
6946: mode</a>.</p>
6947: </dd>
6948:
6949: <dt>An end tag whose tag name is "html"</dt>
6950: <dd>
6951: <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
6952: frameset</a>".</p>
6953: </dd>
6954:
6955: <dt>A start tag whose tag name is "noframes"</dt>
6956: <dd>
6957: <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
6958: mode</a>.</p>
6959: </dd>
6960:
6961: <dt>An end-of-file token</dt>
6962: <dd>
6963: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6964: </dd>
6965:
6966: <dt>Anything else</dt>
6967: <dd>
6968: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6969: </dd>
6970:
1.336 mike 6971: </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 6972:
6973: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
6974: mode: after after body">after after body</a>", tokens must be handled as follows:</p>
6975:
6976: <dl class="switch"><dt>A comment token</dt>
6977: <dd>
6978: <p>Append a <code>Comment</code> node to the <code>Document</code>
6979: object with the <code title="">data</code> attribute set to the
6980: data given in the comment token.</p>
6981: </dd>
6982:
6983: <dt>A DOCTYPE token</dt>
6984: <dt>A character token that is one of U+0009 CHARACTER
6985: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6986: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6987: <dt>A start tag whose tag name is "html"</dt>
6988: <dd>
6989: <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
6990: mode</a>.</p>
6991: </dd>
6992:
6993: <dt>An end-of-file token</dt>
6994: <dd>
6995: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6996: </dd>
6997:
6998: <dt>Anything else</dt>
6999: <dd>
7000: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
7001: to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
7002: reprocess the token.</p>
7003: </dd>
7004:
7005: </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>
7006:
7007: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
7008: mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
7009:
7010: <dl class="switch"><dt>A comment token</dt>
7011: <dd>
7012: <p>Append a <code>Comment</code> node to the <code>Document</code>
7013: object with the <code title="">data</code> attribute set to the
7014: data given in the comment token.</p>
7015: </dd>
7016:
7017: <dt>A DOCTYPE token</dt>
7018: <dt>A character token that is one of U+0009 CHARACTER
7019: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7020: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7021: <dt>A start tag whose tag name is "html"</dt>
7022: <dd>
7023: <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
7024: mode</a>.</p>
7025: </dd>
7026:
7027: <dt>An end-of-file token</dt>
7028: <dd>
7029: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7030: </dd>
7031:
7032: <dt>A start tag whose tag name is "noframes"</dt>
7033: <dd>
7034: <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
7035: mode</a>.</p>
7036: </dd>
7037:
7038: <dt>Anything else</dt>
7039: <dd>
7040: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7041: </dd>
7042:
1.266 mike 7043: </dl></div><div class="impl">
7044:
7045: <h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4>
1.1 mike 7046:
7047: <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
7048: the document, the user agent must follow the steps in this
7049: section.</p>
7050:
1.10 mike 7051: <!-- this happens as part of one of the tasks that runs the parser -->
1.1 mike 7052:
1.10 mike 7053: <p>First, the user agent must set the <a href="dom.html#current-document-readiness">current document
7054: readiness</a> to "interactive" and the <a href="#insertion-point">insertion
7055: point</a> to undefined.</p>
7056:
7057: <p>Then, the user agent must then make a list of all the scripts
7058: that are in the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the
7059: document has finished parsing</a>, the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that
7060: will execute asynchronously</a>, and the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts
7061: that will execute as soon as possible</a>. This is the <dfn id="list-of-scripts-pending-after-the-parser-stopped">list
7062: of scripts pending after the parser stopped</dfn>.</p>
7063:
7064: <p>The rules for <a href="semantics.html#when-a-script-completes-loading">when a script completes loading</a> start
7065: applying (script execution is no longer managed by the parser).</p>
1.1 mike 7066:
7067: <p>If any of the scripts in the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will
7068: execute as soon as possible</a> have <a href="semantics.html#completed-loading">completed
7069: loading</a>, or if the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that will execute
7070: asynchronously</a> is not empty and the first script in that list
7071: has <a href="semantics.html#completed-loading">completed loading</a>, then the user agent must act as
7072: if those scripts just completed loading, following the rules given
7073: for that in the <code><a href="semantics.html#script">script</a></code> element definition.</p>
7074:
1.10 mike 7075: <p>If the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the document
7076: has finished parsing</a> is not empty, and the first item in this
7077: list has already <a href="semantics.html#completed-loading">completed loading</a>, then the user agent
7078: must act as if that script just finished loading.</p>
7079:
7080: <p class="note">By this point, there will be no scripts that have
7081: loaded but have not yet been executed.</p>
7082:
7083: <hr><!-- async --><p>Once all the scripts on the <a href="#list-of-scripts-pending-after-the-parser-stopped">list of scripts pending after
7084: the parser stopped</a> have <a href="semantics.html#completed-loading">completed loading</a> and
7085: been <a href="semantics.html#executing-a-script-block" title="executing a script block">executed</a>, the
7086: user agent must <a href="browsers.html#queue-a-task">queue a task</a> to <a href="browsers.html#fire-a-simple-event">fire a simple
1.460 ! mike 7087: event</a> named <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
1.10 mike 7088: <code>Document</code>. (If the list is empty, this happens
7089: immediately.)</p>
1.1 mike 7090:
1.10 mike 7091: <hr><!-- async --><p>Once everything that <dfn id="delay-the-load-event" title="delay the load event">delays the
1.1 mike 7092: load event</dfn> of the document has completed, the user agent must
7093: run the following steps:</p>
7094:
7095: <ol><li><a href="browsers.html#queue-a-task">Queue a task</a> to set the <a href="dom.html#current-document-readiness">current document
7096: readiness</a> to "complete".</li>
7097:
7098: <li>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
7099: 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 7100: simple event</a> named <code title="event-load">load</code> at
1.1 mike 7101: the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
7102: its <code title="dom-event-target">target</code> set to the
7103: <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
7104: <code><a href="browsers.html#window">Window</a></code> object).</li>
7105:
7106: <li>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
7107: 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
7108: <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
7109: <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
7110: current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
7111: must bubble but not be cancelable and has no default action.</li>
7112:
1.407 mike 7113: </ol><p>The <a href="browsers.html#task-source">task source</a> for these <a href="browsers.html#concept-task" title="concept-task">tasks</a> is the <a href="browsers.html#dom-manipulation-task-source">DOM manipulation
1.228 mike 7114: task source</a>.</p>
1.1 mike 7115:
1.266 mike 7116: </div><div class="impl">
1.1 mike 7117:
7118: <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4>
7119:
7120: <p>When an application uses an <a href="#html-parser">HTML parser</a> in
7121: conjunction with an XML pipeline, it is possible that the
7122: constructed DOM is not compatible with the XML tool chain in certain
7123: subtle ways. For example, an XML toolchain might not be able to
7124: represent attributes with the name <code title="">xmlns</code>,
7125: since they conflict with the Namespaces in XML syntax. There is also
7126: some data that the <a href="#html-parser">HTML parser</a> generates that isn't
7127: included in the DOM itself. This section specifies some rules for
7128: handling these issues.</p>
7129:
7130: <p>If the XML API being used doesn't support DOCTYPEs, the tool may
7131: drop DOCTYPEs altogether.</p>
7132:
7133: <p>If the XML API doesn't support attributes in no namespace that
7134: are named "<code title="">xmlns</code>", attributes whose names
7135: start with "<code title="">xmlns:</code>", or attributes in the
7136: <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
7137: attributes.</p>
7138:
7139: <p>The tool may annotate the output with any namespace declarations
7140: required for proper operation.</p>
7141:
7142: <p>If the XML API being used restricts the allowable characters in
7143: the local names of elements and attributes, then the tool may map
7144: all element and attribute local names that the API wouldn't support
7145: to a set of names that <em>are</em> allowed, by replacing any
7146: character that isn't supported with the uppercase letter U and the
7147: six digits of the character's Unicode code point when expressed in
7148: hexadecimal, using digits 0-9 and capital letters A-F as the
7149: symbols, in increasing numeric order.</p>
7150:
7151: <p class="example">For example, the element name <code title="">foo<bar</code>, which can be output by the <a href="#html-parser">HTML
7152: parser</a>, though it is neither a legal HTML element name nor a
7153: well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
7154: element name (though it's still not legal in HTML by any means).</p>
7155:
7156: <p class="example">As another example, consider the attribute
7157: <code>xlink:href</code>. Used on a MathML element, it becomes, after
7158: being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
7159: attribute with a prefix "<code title="">xlink</code>" and a local
7160: name "<code title="">href</code>". However, used on an HTML element,
7161: it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
7162: might not be accepted by an XML API. It could thus get converted,
7163: becoming "<code title="">xlinkU00003Ahref</code>".</p>
7164:
7165: <p class="note">The resulting names from this conversion
7166: conveniently can't clash with any attribute generated by the
7167: <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
7168: those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
7169: algorithm's table.</p>
7170:
7171: <p>If the XML API restricts comments from having two consecutive
7172: U+002D HYPHEN-MINUS characters (--), the tool may insert a single
7173: U+0020 SPACE character between any such offending characters.</p>
7174:
7175: <p>If the XML API restricts comments from ending in a
7176: U+002D HYPHEN-MINUS character (-), the tool may insert a single
7177: U+0020 SPACE character at the end of such comments.</p>
7178:
7179: <p>If the XML API restricts allowed characters in character data,
1.439 mike 7180: attribute values, or comments, the tool may replace any U+000C FORM
7181: FEED (FF) character with a U+0020 SPACE character, and any other
7182: literal non-XML character with a U+FFFD REPLACEMENT CHARACTER.</p>
1.1 mike 7183:
7184: <p>If the tool has no way to convey out-of-band information, then
7185: the tool may drop the following information:</p>
7186:
7187: <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
7188: <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>
7189:
7190: <li>The association between form controls and forms that aren't
7191: their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
7192: <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
7193:
7194: </ul><p class="note">The mutations allowed by this section apply
7195: <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
7196: applied. For example, a <code title=""><a::></code> start tag
7197: will be closed by a <code title=""></a::></code> end tag, and
7198: never by a <code title=""></aU00003AU00003A></code> end tag, even
7199: if the user agent is using the rules above to then generate an
7200: actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
7201:
1.266 mike 7202: </div><div class="impl">
1.1 mike 7203:
1.35 mike 7204: <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 7205:
7206: <p><i>This section is non-normative.</i></p>
7207:
7208: <p>This section examines some erroneous markup and discusses how
7209: the <a href="#html-parser">HTML parser</a> handles these cases.</p>
7210:
7211:
7212: <h5 id="misnested-tags:-b-i-b-i"><span class="secno">9.2.8.1 </span>Misnested tags: <b><i></b></i></h5>
7213:
7214: <p><i>This section is non-normative.</i></p>
7215:
7216: <p>The most-often discussed example of erroneous markup is as
7217: follows:</p>
7218:
7219: <pre><p>1<b>2<i>3</b>4</i>5</p></pre>
7220:
7221: <p>The parsing of this markup is straightforward up to the "3". At
7222: this point, the DOM looks like this:</p>
7223:
1.159 mike 7224: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>Here, the <a href="#stack-of-open-elements">stack of open elements</a> has five elements
7225: 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 7226: <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
7227: formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
7228: <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>
7229:
7230: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
7231: invoked. This is a simple case, in that the <var title="">formatting
7232: element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
7233: <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
1.159 mike 7234: elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element-0">html</a></code>,
7235: <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 7236: active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
7237: DOM tree is unmodified at this point.</p>
7238:
7239: <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
7240: the active formatting elements</a>, in this case just the
7241: <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
7242: for the "4" text node. After the end tag token for the "i" is also
7243: received, and the "5" text node is inserted, the DOM looks as
7244: follows:</p>
7245:
1.159 mike 7246: <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 7247:
7248: <p><i>This section is non-normative.</i></p>
7249:
7250: <p>A case similar to the previous one is the following:</p>
7251:
7252: <pre><b>1<p>2</b>3</p></pre>
7253:
7254: <p>Up to the "2" the parsing here is straightforward:</p>
7255:
1.159 mike 7256: <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 7257: "b" is parsed.</p>
7258:
7259: <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
1.159 mike 7260: elements</a> has four elements on it: <code><a href="semantics.html#the-html-element-0">html</a></code>,
7261: <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 7262: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
7263: <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>
7264:
7265: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
7266: in the previous example. However, in this case, there <em>is</em> a
7267: <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
7268: this time the adoption agency algorithm isn't skipped over.</p>
7269:
1.159 mike 7270: <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 7271: element. A conceptual "bookmark" marks the position of the
7272: <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
7273: elements</a>, but since that list has only one element in it,
7274: it won't have much effect.</p>
7275:
7276: <p>As the algorithm progresses, <var title="">node</var> ends up set
7277: to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
7278: node</var> ends up set to the <var title="">furthest block</var>
7279: (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
7280:
7281: <p>The <var title="">last node</var> gets appended (moved) to the
7282: <var title="">common ancestor</var>, so that the DOM looks like:</p>
7283:
1.159 mike 7284: <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 7285: <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
7286:
1.159 mike 7287: <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 7288: <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
7289:
1.159 mike 7290: <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 7291: active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
7292: elements</a>, so that when the "3" is parsed, it is appended to
7293: the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
7294:
1.159 mike 7295: <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 7296:
7297: <p><i>This section is non-normative.</i></p>
7298:
7299: <p>Error handling in tables is, for historical reasons, especially
7300: strange. For example, consider the following markup:</p>
7301:
7302: <pre><table><strong><b></strong><tr><td>aaa</td></tr><strong>bbb</strong></table>ccc</pre>
7303:
7304: <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
7305: directly inside a table like that, and the parser handles this case
7306: 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
7307: examining the DOM tree as it stands just after the
7308: <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
7309:
1.159 mike 7310: <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 7311: tag has been seen:</p>
7312:
1.159 mike 7313: <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
7314: 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 7315: <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
7316: resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
7317: elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
7318: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
7319: table">in table</a>".</p>
7320:
7321: <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
7322: to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
7323: 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
7324: then handled in a rather straight-forward manner, taking the parser
7325: through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
7326: body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
7327: row</a>" insertion modes, after which the DOM looks as
7328: follows:</p>
7329:
1.159 mike 7330: <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
7331: 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 7332: <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
7333: formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
7334: it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
7335: mode: in row">in row</a>".</p>
7336:
7337: <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
7338: <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
7339: 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
7340: mode</a>).</p>
7341:
1.159 mike 7342: <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 7343: no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
7344: node:</p>
7345:
1.159 mike 7346: <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 7347: handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
1.159 mike 7348: 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 7349: 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
7350: elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
7351: marker having been removed by the "td" end tag token); and the
7352: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
7353: table body">in table body</a>".</p>
7354:
7355: <p>Thus it is that the "bbb" character tokens are found. These
7356: trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
7357: text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
7358: insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
7359: body">in table body</a>"). The character tokens are collected,
7360: and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
7361: seen, they are processed as a group. Since they are not all spaces,
7362: 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,
7363: which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
7364: body</a>" insertion mode but with <a href="#foster-parent" title="foster
7365: parent">foster parenting</a>.</p>
7366:
7367: <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
7368: active formatting elements are reconstructed</a>, a
7369: <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
7370: parent">foster parented</a>, and then the "bbb" text node is
7371: appended to it:</p>
7372:
1.159 mike 7373: <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
7374: <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 7375: <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
7376: this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
7377: formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
7378: and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
7379: mode: in table body">in table body</a>".</p>
7380:
7381: <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
7382: character">space characters</a> instead of "bbb", then those
7383: <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
7384: appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
7385:
7386: <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
7387: tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
7388: elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
7389: but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
7390: elements</a>, so the "ccc" character tokens after the table
7391: result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
7392: time after the table:</p>
7393:
1.159 mike 7394: <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 7395:
7396: <p><i>This section is non-normative.</i></p>
7397:
7398: <p>Consider the following markup, which for this example we will
7399: 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 7400: content of an <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code> in another document with the
1.1 mike 7401: <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
7402:
7403: <pre><div id=a>
7404: <script>
7405: var div = document.getElementById('a');
7406: parent.document.body.appendChild(div);
7407: </script>
7408: <script>
7409: alert(document.URL);
7410: </script>
7411: </div>
7412: <script>
7413: alert(document.URL);
7414: </script></pre>
7415:
7416: <p>Up to the first "script" end tag, before the script is parsed,
7417: the result is relatively straightforward:</p>
7418:
1.306 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="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="">
7420: </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 7421: and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
7422:
1.159 mike 7423: <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 7424: aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
7425: <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
1.306 mike 7426: <code><a href="semantics.html#the-div-element">div</a></code> element</em>.</p>
1.1 mike 7427:
7428: <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
7429: is inserted <em>into the outer <code>Document</code>
7430: object</em>.</p>
7431:
7432: <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
7433: the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
7434: object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
1.159 mike 7435: <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>.</p>
1.1 mike 7436:
7437: <p class="note">This isn't a security problem since the script that
1.306 mike 7438: moves the <code><a href="semantics.html#the-div-element">div</a></code> into the outer <code>Document</code> can
1.1 mike 7439: only do so because they have the two <code>Document</code> object
1.159 mike 7440: have the same <a href="browsers.html#origin">origin</a>.</p>
1.1 mike 7441:
7442: <p>Thus, the first alert says "http://example.com/outer".</p>
7443:
1.306 mike 7444: <p>Once the <code><a href="semantics.html#the-div-element">div</a></code> element's end tag is parsed, the
7445: <code><a href="semantics.html#the-div-element">div</a></code> element is popped off the stack, and so the next
1.1 mike 7446: <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
7447:
1.159 mike 7448: <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 7449:
7450:
7451:
1.215 mike 7452: <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3>
1.1 mike 7453:
7454: <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
7455:
7456: <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
7457:
7458: <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
7459:
7460: <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
7461:
7462: <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
7463:
7464: <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
7465:
7466: <hr><p>Data mining tools and other user agents that perform operations
1.83 mike 7467: on <code><a href="iana-considerations.html#text-html">text/html</a></code> content without running scripts,
1.1 mike 7468: evaluating CSS or XPath expressions, or otherwise exposing the
7469: resulting DOM to arbitrary content, may "support namespaces" by just
7470: asserting that their DOM node analogues are in certain namespaces,
7471: without actually exposing the above strings.</p>
7472:
7473:
7474:
7475:
7476: <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3>
7477:
7478: <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
7479: algorithm</dfn>. The algorithm takes as input a DOM
7480: <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
7481: exception.</p>
7482:
7483: <p class="note">This algorithm serializes the <em>children</em> of
7484: the node being serialized, not the node itself.</p>
7485:
7486: <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
7487: the empty string.</p></li>
7488:
7489: <li>
7490:
7491: <p>For each child node of <var title="">the node</var>, in
7492: <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
7493:
7494: </p><ol><li><p>Let <var title="">current node</var> be the child node
7495: being processed.</p></li>
7496:
7497: <li>
7498:
7499: <p>Append the appropriate string from the following list to
7500: <var title="">s</var>:</p>
7501:
7502: <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
7503:
7504: <dd>
7505:
7506: <p>Append a U+003C LESS-THAN SIGN (<code title=""><</code>)
7507: character, followed by the element's tag name. (For nodes
7508: created by the <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
7509: lowercase.)</p>
7510:
7511: <p>For each attribute that the element has, append a U+0020
7512: SPACE character, the attribute's name (which, for attributes
7513: 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
7514: U+003D EQUALS SIGN (<code title="">=</code>) character, a
7515: U+0022 QUOTATION MARK (<code title="">"</code>)
7516: character, the attribute's value, <a href="#escapingString" title="escaping a
7517: string">escaped as described below</a> in <i>attribute
7518: mode</i>, and a second U+0022 QUOTATION MARK (<code title="">"</code>) character.</p>
7519:
7520: <p>While the exact order of attributes is UA-defined, and may
7521: depend on factors such as the order that the attributes were
7522: given in the original markup, the sort order must be stable,
7523: such that consecutive invocations of this algorithm serialize an
7524: element's attributes in the same order.</p>
7525:
7526: <p>Append a U+003E GREATER-THAN SIGN (<code title="">></code>)
7527: character.</p>
7528:
7529: <p>If <var title="">current node</var> is an
1.5 mike 7530: <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 7531: <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 7532: <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>,
7533: <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>,
7534: <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 7535: <code><a href="obsolete.html#spacer">spacer</a></code>, or <code>wbr</code> element, then
1.1 mike 7536: continue on to the next child node at this point.</p> <!--
7537: also, i guess: image and isindex, but we don't list those
7538: because we don't consider those "elements", more "macros", and
7539: thus we should never serialize them -->
7540:
7541: <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42 mike 7542: <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 7543: a U+000A LINE FEED (LF) character.</p>
7544:
7545: <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
7546: serialization algorithm</a> on the <var title="">current
7547: node</var> element (thus recursing into this algorithm for
7548: 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,
7549: and finally a U+003E GREATER-THAN SIGN (<code title="">></code>) character.</p>
7550:
7551: </dd>
7552:
7553:
7554: <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
7555: node</dt>
7556:
7557: <dd>
7558:
1.19 mike 7559: <p>If the parent of <var title="">current node</var> is a
1.42 mike 7560: <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 7561: <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 7562: <code><a href="obsolete.html#noframes">noframes</a></code>, or <code><a href="obsolete.html#plaintext">plaintext</a></code> element, or
7563: if the parent of <var title="">current node</var> is
7564: <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
7565: node, then append the value of <var title="">current
7566: node</var>'s <code title="">data</code> IDL attribute
7567: literally.</p>
1.1 mike 7568:
7569: <p>Otherwise, append the value of <var title="">current
1.192 mike 7570: node</var>'s <code title="">data</code> IDL attribute, <a href="#escapingString" title="escaping a string">escaped as described
1.1 mike 7571: below</a>.</p>
7572:
7573: </dd>
7574:
7575:
7576: <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
7577:
7578: <dd>
7579:
7580: <p>Append the literal string <code><!--</code> (U+003C
7581: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
1.192 mike 7582: U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1 mike 7583: attribute, followed by the literal string <code>--></code>
7584: (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
7585: SIGN).</p>
7586:
7587: </dd>
7588:
7589:
7590: <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
7591:
7592: <dd>
7593:
7594: <p>Append the literal string <code><?</code> (U+003C
7595: LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
1.192 mike 7596: of <var title="">current node</var>'s <code title="">target</code> IDL attribute, followed by a single
7597: U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1 mike 7598: attribute, followed by a single U+003E GREATER-THAN SIGN
7599: character ('>').</p>
7600:
7601: </dd>
7602:
7603:
7604: <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
7605:
7606: <dd>
7607:
7608: <p>Append the literal string <code><!DOCTYPE</code> (U+003C
7609: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
7610: LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
7611: LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
7612: LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
7613: LETTER E), followed by a space (U+0020 SPACE), followed by the
1.192 mike 7614: value of <var title="">current node</var>'s <code title="">name</code> IDL attribute, followed by the literal
1.1 mike 7615: string <code>></code> (U+003E GREATER-THAN SIGN).</p>
7616:
7617: </dd>
7618:
7619:
7620: </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
7621: occur as children of elements. If, despite this, they somehow do
7622: occur, this algorithm must raise an
7623: <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
7624:
7625: </li>
7626:
7627: </ol></li>
7628:
7629: <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
7630:
7631: </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
7632: purposes of the algorithm above) consists of replacing any
7633: occurrences of the "<code title="">&</code>" character by the
7634: string "<code title="">&amp;</code>", any occurrences of the
7635: U+00A0 NO-BREAK SPACE character by the string "<code title="">&nbsp;</code>", and, if the algorithm was invoked in
7636: 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
7637: 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>
7638:
7639: <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
7640: agent, and are therefore not covered in the algorithm above.</p>
7641:
7642: <p class="note">It is possible that the output of this algorithm, if
7643: parsed with an <a href="#html-parser">HTML parser</a>, will not return the
7644: original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
7645: element to which a <code title="">Comment</code> node has been
7646: appended is serialized and the output is then reparsed, the comment
7647: will end up being displayed in the text field. Similarly, if, as a
7648: result of DOM manipulation, an element contains a comment that
7649: contains the literal string "<code title="">--></code>", then
7650: when the result of serializing the element is parsed, the comment
7651: will be truncated at that point and the rest of the comment will be
7652: interpreted as markup. More examples would be making a
7653: <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
7654: "<code></script></code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
7655: 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
7656: <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
7657: tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
7658:
7659:
7660: <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3>
7661:
7662: <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
7663: algorithm</dfn>. The algorithm optionally takes as input an
7664: <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
7665: parser, as well as <var title="">input</var>, a string to parse, and
7666: returns a list of zero or more nodes.</p>
7667:
7668: <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
7669: in the parser section are parts that only occur if the parser was
7670: created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
7671: with such markings for informational purposes only; such markings
7672: have no normative weight. If it is possible for a condition
7673: described as a <a href="#fragment-case">fragment case</a> to occur even when the
7674: parser wasn't created for the purposes of handling this algorithm,
7675: then that is an error in the specification.</p>
7676:
7677: <ol><li>
7678:
7679: <p>Create a new <code>Document</code> node, and mark it as being
7680: an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
7681:
7682: </li>
7683:
7684: <li>
7685:
7686: <p>If there is a <var title="">context</var> element, and the
7687: <code>Document</code> of the <var title="">context</var> element
7688: is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
7689: 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
7690: the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
7691: mode</a>, then let the <code>Document</code> be in
7692: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
7693: <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
7694:
7695: </li>
7696:
7697: <li>
7698:
7699: <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
7700: the just created <code>Document</code> node.</p>
7701:
7702: </li>
7703:
7704: <li>
7705:
7706: <p>If there is a <var title="">context</var> element, run these
7707: substeps:</p>
7708:
7709: <ol><li>
7710:
7711: <p>Set the <a href="#html-parser">HTML parser</a>'s <a href="#tokenization">tokenization</a>
7712: stage's <a href="#content-model-flag">content model flag</a> according to the <var title="">context</var> element, as follows:</p>
7713:
1.159 mike 7714: <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 7715: element</dt>
7716:
7717: <dd>Set the <a href="#content-model-flag">content model flag</a> to
7718: the RCDATA state.</dd>
7719:
7720:
7721: <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 7722: <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 7723: <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1 mike 7724:
7725: <dd>Set the <a href="#content-model-flag">content model flag</a> to
1.91 mike 7726: the RAWTEXT state.</dd>
1.1 mike 7727:
7728:
7729: <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
7730:
7731: <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, set the
1.91 mike 7732: <a href="#content-model-flag">content model flag</a> to the RAWTEXT
1.1 mike 7733: state. Otherwise, set the <a href="#content-model-flag">content model flag</a> to the
7734: PCDATA state.</dd>
7735:
7736:
1.42 mike 7737: <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1 mike 7738:
7739: <dd>Set the <a href="#content-model-flag">content model flag</a> to
7740: PLAINTEXT.</dd>
7741:
7742:
7743: <dt>Otherwise</dt>
7744:
7745: <dd>Leave the <a href="#content-model-flag">content model flag</a> in the PCDATA
7746: state.</dd>
7747:
7748: </dl></li>
7749:
7750: <li>
7751:
1.159 mike 7752: <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 7753: with no attributes.</p>
7754:
7755: </li>
7756:
7757: <li>
7758:
7759: <p>Append the element <var title="">root</var> to the
7760: <code>Document</code> node created above.</p>
7761:
7762: </li>
7763:
7764: <li>
7765:
7766: <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
7767: it contains just the single element <var title="">root</var>.</p>
7768:
7769: </li>
7770:
7771: <li>
7772:
7773: <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
7774: parser's insertion mode appropriately</a>.</p>
7775:
7776: <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
7777:
7778: </li>
7779:
7780: <li>
7781:
7782: <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
7783: to the nearest node to the <var title="">context</var> element
7784: that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
7785: ancestor chain, and including the element itself, if it is a
7786: <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
7787: <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
7788:
7789: </li>
7790:
7791: </ol></li>
7792:
7793: <li>
7794:
7795: <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
7796: parser</a> just created the <var title="">input</var>. The
7797: encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
7798: <i>irrelevant</i>.</p>
7799:
7800: </li>
7801:
7802: <li>
7803:
7804: <p>Start the parser and let it run until it has consumed all the
7805: characters just inserted into the input stream.</p>
7806:
7807: </li>
7808:
7809: <li>
7810:
7811: <p>If there is a <var title="">context</var> element, return the
7812: child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
7813: order</a>.</p>
7814:
7815: <p>Otherwise, return the children of the <code>Document</code>
7816: object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
7817:
7818: </li>
7819:
1.123 mike 7820: </ol></div></body></html>
Webmaster