Annotation of html5/spec/syntax.html, revision 1.440
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.440 ! mike 226: </nav><p>This is revision 1.3208.</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.352 mike 300: <li>Zero 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>
1303: <i>tentative</i>. In non-legacy environments, the more
1304: comprehensive <code title="">UTF-8</code> encoding is
1305: recommended. Due to its use in legacy content, <code title="">windows-1252</code> is recommended as a default in
1.187 mike 1306: predominantly Western demographics instead.</p></li>
1.1 mike 1307:
1308: </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
1309: be set to the value returned from this algorithm, at the same time
1310: as the user agent uses the returned value to select the decoder to
1311: use for the input stream.</p>
1312:
1313:
1.237 mike 1314: <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 1315:
1.237 mike 1316: <p>User agents must at a minimum support the UTF-8 and Windows-1252
1317: encodings, but may support more.</p>
1318:
1319: <p class="note">It is not unusual for Web browsers to support dozens
1320: if not upwards of a hundred distinct character encodings.</p>
1321:
1.365 mike 1322: <p>User agents must support the <a href="infrastructure.html#preferred-mime-name">preferred MIME name</a> of
1323: every character encoding they support, and should support all the
1324: IANA-registered names and aliases of every character encoding they
1325: support. <a href="references.html#refsIANACHARSET">[IANACHARSET]</a></p>
1.237 mike 1326:
1327: <p>When comparing a string specifying a character encoding with the
1328: name or alias of a character encoding to determine if they are
1329: 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
1330: then perform the comparison in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1331: case-insensitive</a> manner.</p>
1332:
1333: <!-- this bit will be replaced by actual alias registrations in due course -->
1334:
1335: <p>In addition, user agents must support the aliases given in the
1336: following table for every character encoding they support, so that
1337: labels from the first column are treated as equivalent to the labels
1338: given in the corresponding cell from the second column on the same
1339: row.</p>
1340:
1341: <table><caption>Additional character encoding aliases</caption>
1342: <thead><tr><th> Alias </th><th> Corresponding encoding </th><th> References
1343: </th></tr></thead><tbody><tr><td> x-sjis </td><td> windows-31J </td><td>
1344: <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
1345: <a href="references.html#refsWIN31J">[WIN31J]</a>
1346: </td></tr><tr><td> windows-932 </td><td> windows-31J </td><td>
1347: <a href="references.html#refsWIN31J">[WIN31J]</a>
1348: </td></tr><tr><td> x-x-big5 </td><td> Big5 </td><td>
1349: <a href="references.html#refsBIG5">[BIG5]</a>
1350: </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
1351: first column of the following table to either convert content to
1352: Unicode characters or convert Unicode characters to bytes, it must
1353: instead use the encoding given in the cell in the second column of
1354: the same row. When a byte or sequence of bytes is treated
1355: differently due to this encoding aliasing, it is said to have been
1356: <dfn id="misinterpreted-for-compatibility">misinterpreted for compatibility</dfn>.</p>
1357:
1358: <table><caption>Character encoding overrides</caption>
1359: <thead><tr><th> Input encoding </th><th> Replacement encoding </th><th> References
1360: </th></tr></thead><tbody><!-- how about EUC-JP? --><tr><td> EUC-KR </td><td> windows-949 </td><td>
1361: <a href="references.html#refsEUCKR">[EUCKR]</a>
1362: <a href="references.html#refsWIN949">[WIN949]</a>
1363: </td></tr><tr><td> GB2312 </td><td> GBK </td><td>
1364: <a href="references.html#refsRFC1345">[RFC1345]</a>
1365: <a href="references.html#refsGBK">[GBK]</a>
1366: </td></tr><tr><td> GB_2312-80 </td><td> GBK </td><td>
1367: <a href="references.html#refsRFC1345">[RFC1345]</a>
1368: <a href="references.html#refsGBK">[GBK]</a>
1369: </td></tr><tr><td> ISO-8859-1 </td><td> windows-1252 </td><td>
1370: <a href="references.html#refsRFC1345">[RFC1345]</a>
1371: <a href="references.html#refsWIN1252">[WIN1252]</a>
1372: </td></tr><tr><td> ISO-8859-9 </td><td> windows-1254 </td><td>
1373: <a href="references.html#refsRFC1345">[RFC1345]</a>
1374: <a href="references.html#refsWIN1254">[WIN1254]</a>
1375: </td></tr><tr><td> ISO-8859-11 </td><td> windows-874 </td><td>
1376: <a href="references.html#refsISO885911">[ISO885911]</a>
1377: <a href="references.html#refsWIN874">[WIN874]</a>
1378: </td></tr><tr><td> KS_C_5601-1987 </td><td> windows-949 </td><td>
1379: <a href="references.html#refsRFC1345">[RFC1345]</a>
1380: <a href="references.html#refsWIN949">[WIN949]</a>
1381: </td></tr><tr><td> Shift_JIS </td><td> windows-31J </td><td>
1382: <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
1383: <a href="references.html#refsWIN31J">[WIN31J]</a>
1384: </td></tr><tr><td> TIS-620 </td><td> windows-874 </td><td>
1385: <a href="references.html#refsTIS620">[TIS620]</a>
1386: <a href="references.html#refsWIN874">[WIN874]</a>
1387: </td></tr><tr><td> US-ASCII </td><td> windows-1252 </td><td>
1388: <a href="references.html#refsRFC1345">[RFC1345]</a>
1389: <a href="references.html#refsWIN1252">[WIN1252]</a>
1390: </td></tr></tbody></table><p class="note">The requirement to treat certain encodings as other
1391: encodings according to the table above is a <a href="introduction.html#willful-violation">willful
1392: violation</a> of the W3C Character Model specification, motivated
1393: by a desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
1394:
1395: <p>When a user agent is to use the UTF-16 encoding but no BOM has
1396: been found, user agents must default to UTF-16LE.</p>
1397:
1398: <p class="note">The requirement to default UTF-16 to LE rather than
1399: BE is a <a href="introduction.html#willful-violation">willful violation</a> of RFC 2781, motivated by a
1400: desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
1401:
1402: <hr><p>User agents must not support the CESU-8, UTF-7, BOCU-1 and SCSU
1403: 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>
1404:
1405: <p>Support for encodings based on EBCDIC is not recommended. This
1406: encoding is rarely used for publicly-facing Web content.</p>
1407:
1408: <p>Support for UTF-32 is not recommended. This encoding is rarely
1409: used, and frequently implemented incorrectly.</p>
1410:
1411: <p class="note">This specification does not make any attempt to
1412: support EBCDIC-based encodings and UTF-32 in its algorithms; support
1413: and use of these encodings can thus lead to unexpected behavior in
1414: implementations of this specification.</p>
1415:
1416:
1417:
1418: <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.3 </span>Preprocessing the input stream</h5>
1.1 mike 1419:
1420: <p>Given an encoding, the bytes in the input stream must be
1421: converted to Unicode characters for the tokenizer, as described by
1422: the rules for that encoding, except that the leading U+FEFF BYTE
1423: ORDER MARK character, if any, must not be stripped by the encoding
1424: layer (it is stripped by the rule below).</p> <!-- this is to
1425: prevent two leading BOMs from being both stripped, once by the
1426: decoder, and once by the parser -->
1427:
1428: <p>Bytes or sequences of bytes in the original byte stream that
1.393 mike 1429: could not be converted to Unicode code points must be converted to
1430: U+FFFD REPLACEMENT CHARACTERs.</p>
1.1 mike 1431:
1432: <p class="note">Bytes or sequences of bytes in the original byte
1433: stream that did not conform to the encoding specification
1434: (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
1435: errors that conformance checkers are expected to report.</p>
1436:
1.438 mike 1437: <p>Any byte or sequence of bytes in the original byte stream that is
1438: <a href="#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
1.1 mike 1439: error</a>.</p>
1440:
1441: <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
1442: any are present.</p>
1443:
1.300 mike 1444: <p class="note">The requirement to strip a U+FEFF BYTE ORDER MARK
1445: character regardless of whether that character was used to determine
1446: the byte order is a <a href="introduction.html#willful-violation">willful violation</a> of Unicode,
1447: motivated by a desire to increase the resilience of user agents in
1448: the face of naïve transcoders.</p>
1449:
1.316 mike 1450: <p>All U+0000 NULL characters and code points in the range U+D800 to
1.315 mike 1451: U+DFFF<!-- surrogates not allowed e.g. in UTF-8, and we don't want
1452: them to suddenly turn into codepoints when they go through a UTF-16
1453: pipe --> in the input must be replaced by U+FFFD REPLACEMENT
1.316 mike 1454: CHARACTERs. Any occurrences of such characters and code points are
1455: <a href="#parse-error" title="parse error">parse errors</a>.</p>
1.1 mike 1456:
1457: <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
1458: <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
1459: CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
1.315 mike 1460: <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+FDD0
1461: to U+FDEF, and characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF,
1462: U+2FFFE, U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE,
1463: U+5FFFF, U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF,
1464: U+9FFFE, U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE,
1465: U+CFFFF, U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF,
1466: U+10FFFE, and U+10FFFF are <a href="#parse-error" title="parse error">parse
1.316 mike 1467: errors</a>. These are all control characters or permanently
1468: undefined Unicode characters (noncharacters).</p>
1.1 mike 1469:
1470: <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
1471: characters are treated specially. Any CR characters that are
1472: followed by LF characters must be removed, and any CR characters not
1473: followed by LF characters must be converted to LF characters. Thus,
1474: newlines in HTML DOMs are represented by LF characters, and there
1475: are never any CR characters in the input to the
1476: <a href="#tokenization">tokenization</a> stage.</p>
1477:
1478: <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
1479: input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
1480: the <i><a href="#next-input-character">next input character</a></i> is the first character in the
1481: input. The <dfn id="current-input-character">current input character</dfn> is the last character
1482: to have been <i><a href="#consumed">consumed</a></i>.</p>
1483:
1484: <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
1485: character or just before the end of the input stream) where content
1.159 mike 1486: 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 1487: inserted. The insertion point is relative to the position of the
1488: character immediately after it, it is not an absolute offset into
1489: the input stream. Initially, the insertion point is
1.10 mike 1490: undefined.</p>
1.1 mike 1491:
1492: <p>The "EOF" character in the tables below is a conceptual character
1493: representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
1.159 mike 1494: is a <a href="embedded-content-0.html#script-created-parser">script-created parser</a>, then the end of the
1.1 mike 1495: <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
1.159 mike 1496: 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 1497: consumed. Otherwise, the "EOF" character is not a real character in
1498: the stream, but rather the lack of any further characters.</p>
1499:
1500:
1.237 mike 1501: <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.4 </span>Changing the encoding while parsing</h5>
1.1 mike 1502:
1503: <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
1504: encoding</dfn>, it must run the following steps. This might happen
1505: if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
1506: failed to find an encoding, or if it found an encoding that was not
1507: the actual encoding of the file.</p>
1508:
1509: <ol><li>If the new encoding is identical or equivalent to the encoding
1510: that is already being used to interpret the input stream, then set
1511: the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1512: <i>certain</i> and abort these steps. This happens when the
1513: encoding information found in the file matches what the
1514: <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
1515: encoding, and in the second pass through the parser if the first
1516: pass found that the encoding sniffing algorithm described in the
1517: earlier section failed to find the right encoding.</li>
1518:
1519: <li>If the encoding that is already being used to interpret the
1520: input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1521: <i>certain</i> and abort these steps. The new encoding is ignored;
1522: if it was anything but the same encoding, then it would be clearly
1523: incorrect.</li>
1524:
1525: <li>If the new encoding is a UTF-16 encoding, change it to
1526: UTF-8.</li>
1527:
1528: <li>If all the bytes up to the last byte converted by the current
1529: decoder have the same Unicode interpretations in both the current
1530: encoding and the new encoding, and if the user agent supports
1531: changing the converter on the fly, then the user agent may change
1532: to the new converter for the encoding on the fly. Set the
1533: <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
1534: convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1535: <i>certain</i>, and abort these steps.</li>
1536:
1537: <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
1538: <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
1539: browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
1540: sniffing algorithm</a> and instead just set the encoding to the
1541: new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1542: <i>certain</i>. Whenever possible, this should be done without
1543: actually contacting the network layer (the bytes should be
1544: re-parsed from memory), even if, e.g., the document is marked as
1545: not being cacheable. If this is not possible and contacting the
1546: network layer would involve repeating a request that uses a method
1547: other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
1548: equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1549: <i>certain</i> and ignore the new encoding. The resource will be
1550: misinterpreted. User agents may notify the user of the situation,
1551: to aid in application development.</li>
1552:
1.266 mike 1553: </ol></div><div class="impl">
1554:
1555: <h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4>
1.1 mike 1556:
1557: <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5>
1558:
1559: <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
1560: the primary operation of the tree construction stage.</p>
1561:
1562: <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
1563: "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
1564: "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
1565: "<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 1566: "<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 1567: "<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>",
1568: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
1569: "<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
1570: table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
1571: foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
1572: body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
1573: frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
1574: frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
1575: after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
1576: frameset</a>" during the course of the parsing, as described in
1577: the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
1578: how tokens are processed and whether CDATA sections are
1579: supported.</p>
1580:
1581: <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
1582: head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
1583: body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
1584: table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
1585: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
1586: "<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
1587: that the other modes defer to them at various times. When the
1588: algorithm below says that the user agent is to do something
1589: "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
1590: mode", where <var title="">m</var> is one of these modes, the user
1591: agent must use the rules described under the <var title="">m</var>
1592: <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
1593: <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>
1594: to a new value.</p>
1595:
1596: <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.91 mike 1597: 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 1598: <dfn id="original-insertion-mode">original insertion mode</dfn> is also set. This is the
1599: insertion mode to which the tree construction stage will return.</p>
1600:
1601: <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
1602: mode: in foreign content">in foreign content</a>", the
1603: <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
1604: is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
1605: foreign content">in foreign content</a>" mode to handle HTML
1606: (i.e. not foreign) content.</p>
1607:
1608: <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
1609: mode appropriately</dfn>, it means the UA must follow these
1610: steps:</p>
1611:
1612: <ol><li>Let <var title="">last</var> be false.</li>
1613:
1614: <li>Let <var title="">node</var> be the last node in the
1615: <a href="#stack-of-open-elements">stack of open elements</a>.</li>
1616:
1617: <li>If <var title="">node</var> is the first node in the stack of
1618: open elements, then set <var title="">last</var> to true and set
1619: <var title="">node</var> to the <var title="">context</var>
1620: element. (<a href="#fragment-case">fragment case</a>)</li>
1621:
1622: <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
1623: 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
1624: steps. (<a href="#fragment-case">fragment case</a>)</li>
1625:
1626: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
1627: <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
1628: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
1629: mode: in cell">in cell</a>" and abort these steps.</li>
1630:
1631: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
1632: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
1633: mode: in row">in row</a>" and abort these steps.</li>
1634:
1635: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
1636: <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
1637: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
1638: table body">in table body</a>" and abort these steps.</li>
1639:
1640: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
1641: 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
1642: these steps.</li>
1643:
1644: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
1645: 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
1646: abort these steps. (<a href="#fragment-case">fragment case</a>)</li>
1647:
1648: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
1649: 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
1650: steps.</li>
1651:
1652: <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
1653: namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then switch the
1654: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
1655: foreign content">in foreign content</a>", let the
1656: <a href="#secondary-insertion-mode">secondary insertion mode</a> be "<a href="#parsing-main-inbody" title="insertion
1657: mode: in body">in body</a>", and abort these steps.</li>
1658:
1.159 mike 1659: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element-0">head</a></code> element,
1.1 mike 1660: 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
1661: these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- This is only
1662: here for now in case people think that the spec accidentally
1663: omitted it and try to "fix" it. Note that noscript-in-head is also
1664: handled this way. This is all intentional. The only thing it
1665: doesn't handle is the scripting-disabled fragment parsing case for
1666: a <head> element containing a <noscript> which itself contains
1667: something other than a <link> or a <style> element; you'd expect
1668: that to break out of the <noscript> but it doesn't. This is an edge
1669: case that doesn't affect the spec, since the algorithm for fragment
1670: parsing is only used for innerHTML/outerHTML/insertAdjacentHTML(),
1.333 mike 1671: where we know scripting is enabled. -->
1.1 mike 1672:
1.159 mike 1673: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element-0">body</a></code> element,
1.1 mike 1674: 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
1675: steps.</li>
1676:
1.5 mike 1677: <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.1 mike 1678: 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
1679: these steps. (<a href="#fragment-case">fragment case</a>)</li>
1680:
1.159 mike 1681: <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element-0">html</a></code> element,
1.333 mike 1682: then <!--: if the <span><code title="">head</code> element
1683: pointer</span> is null,--> switch the <a href="#insertion-mode">insertion mode</a>
1684: to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before
1685: head</a>"<!--, otherwise, switch the <span>insertion mode</span>
1686: to "<span title="insertion mode: after head">after head</span>".-->
1687: Then, <!-- in either case, --> abort these steps. (<a href="#fragment-case">fragment
1688: case</a>)</li> <!-- if the head element pointer can ever be
1689: non-null when we're going through these steps, we'll need to
1690: uncomment out the commented-out bits -->
1.1 mike 1691:
1692: <li>If <var title="">last</var> is true, then switch the
1693: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
1694: body">in body</a>" and abort these steps. (<a href="#fragment-case">fragment
1695: case</a>)</li>
1696:
1697: <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
1698: elements</a>.</li>
1699:
1700: <li>Return to step 3.</li>
1701:
1702: </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5>
1703:
1704: <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
1705: stack grows downwards; the topmost node on the stack is the first
1706: one added to the stack, and the bottommost node of the stack is the
1707: most recently added node in the stack (notwithstanding when the
1708: stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
1709:
1710: <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
1711: html</a>" <a href="#insertion-mode">insertion mode</a> creates the
1.159 mike 1712: <code><a href="semantics.html#the-html-element-0">html</a></code> root element node, which is then added to the
1.1 mike 1713: stack.</p>
1714:
1715: <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
1.159 mike 1716: elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1 mike 1717: element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
1718: parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
1719: case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
1720: html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
1721:
1.159 mike 1722: <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 1723: node of the stack. It never gets popped off the stack.</p>
1724:
1725: <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
1726: stack.</p>
1727:
1728: <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
1729: element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
1730: 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
1731: open elements</a> (<a href="#fragment-case">fragment case</a>), then the
1732: <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
1.159 mike 1733: of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code> element).</p>
1.1 mike 1734:
1735: <p>Elements in the stack fall into the following categories:</p>
1736:
1737: <dl><dt><dfn id="special">Special</dfn></dt>
1738:
1739: <dd><p>The following HTML elements have varying levels of special
1740: 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>,
1741: <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 1742: <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.159 mike 1743: <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 1744: <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 1745: <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
1.422 mike 1746: <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>,
1747: <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>,
1748: <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>,
1749: <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>,
1750: <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>,
1751: <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>,
1752: <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>,
1753: <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>,
1754: (commented out because this isn't an element that can end up on the
1755: stack, so it doesn't matter) --> <code><a href="text-level-semantics.html#the-img-element">img</a></code>,
1756: <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>,
1757: <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>,
1758: <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>,
1759: <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>,
1760: <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>,
1761: <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>,
1762: <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>,
1763: <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>,
1764: <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>,
1765: <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 1766:
1767: <dt><dfn id="scoping">Scoping</dfn></dt>
1768: <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
1769: an element in scope">scopes</a> for various parts of the
1.5 mike 1770: 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 1771: <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>,
1772: <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 1773: <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
1774:
1775: <dt><dfn id="formatting">Formatting</dfn></dt>
1776: <dd><p>The following HTML elements are those that end up in the
1777: <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 1778: <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>,
1779: <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>,
1780: <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>,
1781: <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
1782: <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1 mike 1783:
1784: <dt><dfn id="phrasing">Phrasing</dfn></dt>
1785: <dd><p>All other elements found while parsing an HTML
1786: document.</p></dd>
1787:
1.234 mike 1788: </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
1789: specific scope</dfn> consisting of a list of element types <var title="">list</var> when the following algorithm terminates in a
1790: match state:</p>
1.1 mike 1791:
1792: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
1793: node</a> (the bottommost node of the stack).</p></li>
1794:
1795: <li><p>If <var title="">node</var> is the target node, terminate in
1796: a match state.</p></li>
1797:
1.234 mike 1798: <li><p>Otherwise, if <var title="">node</var> is one of the element
1799: types in <var title="">list</var>, terminate in a failure
1800: state.</p></li>
1.1 mike 1801:
1802: <li><p>Otherwise, set <var title="">node</var> to the previous
1803: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
1804: 2. (This will never fail, since the loop will always terminate in
1805: the previous step if the top of the stack — an
1.159 mike 1806: <code><a href="semantics.html#the-html-element-0">html</a></code> element — is reached.)</p></li>
1.1 mike 1807:
1.234 mike 1808: </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
1809: it <a href="#has-an-element-in-the-specific-scope">has an element in the specific scope</a> consisting
1810: of the following element types:</p>
1811:
1812: <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
1813: <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
1814: <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.) -->
1815: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
1816: <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
1817: <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
1818: <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
1819: <li><code><a href="obsolete.html#the-marquee-element">marquee</a></code> in the HTML namespace</li>
1820: <li><code><a href="text-level-semantics.html#the-object-element">object</a></code> in the HTML namespace</li>
1821: <li><code title="">foreignObject</code> in the SVG namespace</li>
1822: </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
1823: item scope</dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
1824: scope</a> consisting of the following element types:</p>
1825:
1826: <ul class="brief"><li>All the element types listed above for the <i><a href="#has-an-element-in-scope">has an element
1827: in scope</a></i> algorithm.</li>
1828: <li><code><a href="semantics.html#the-ol-element">ol</a></code> in the HTML namespace</li>
1829: <li><code><a href="semantics.html#the-ul-element">ul</a></code> in the HTML namespace</li>
1830: </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
1831: scope</em></dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
1832: scope</a> consisting of the following element types:</p>
1833:
1834: <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.) -->
1835: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
1836: </ul><p>Nothing happens if at any time any of the elements in the
1.1 mike 1837: <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
1838: or removed from, the <code>Document</code> tree. In particular, the
1839: stack is not changed in this situation. This can cause, amongst
1840: other strange effects, content to be appended to nodes that are no
1841: longer in the DOM.</p>
1842:
1843: <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
1844: the stack is manipulated in a random-access fashion.</p>
1845:
1846:
1847: <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5>
1848:
1849: <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
1850: empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
1851:
1852: <p>The list contains elements in the <a href="#formatting">formatting</a>
1853: category, and scope markers. The scope markers are inserted when
1.159 mike 1854: 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 1855: elements, marquees, table cells, and table captions, and are used to
1.5 mike 1856: prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.159 mike 1857: elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code> elements, marquees, and
1.1 mike 1858: tables.</p>
1859:
1860: <p class="note">The scope markers are unrelated to the concept of an
1861: element being <a href="#has-an-element-in-scope" title="has an element in scope">in
1862: scope</a>.</p>
1863:
1864: <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
1865: elements</a> is associated with the token for which it was
1866: created, so that further elements can be created for that token if
1867: necessary.</p>
1868:
1869: <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
1870: active formatting elements</dfn>, the UA must perform the following
1871: steps:</p>
1872:
1873: <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
1874: elements</a>, then there is nothing to reconstruct; stop this
1875: algorithm.</li>
1876:
1877: <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
1878: active formatting elements</a> is a marker, or if it is an
1879: element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
1880: there is nothing to reconstruct; stop this algorithm.</li>
1881:
1882: <li>Let <var title="">entry</var> be the last (most recently added)
1883: element in the <a href="#list-of-active-formatting-elements">list of active formatting
1884: elements</a>.</li>
1885:
1886: <li>If there are no entries before <var title="">entry</var> in the
1887: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
1888: 8.</li>
1889:
1890: <li>Let <var title="">entry</var> be the entry one earlier than
1891: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
1892: elements</a>.</li>
1893:
1894: <li>If <var title="">entry</var> is neither a marker nor an element
1895: that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
1896: 4.</li>
1897:
1898: <li>Let <var title="">entry</var> be the element one later than
1899: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
1900: elements</a>.</li>
1901:
1902: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
1903: element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
1904:
1905: <li>Append <var title="">new element</var> to the <a href="#current-node">current
1906: node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
1907: elements</a> so that it is the new <a href="#current-node">current
1908: node</a>.</li>
1909:
1910: <li>Replace the entry for <var title="">entry</var> in the list
1911: with an entry for <var title="">new element</var>.</li>
1912:
1913: <li>If the entry for <var title="">new element</var> in the
1914: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
1915: entry in the list, return to step 7.</li>
1916:
1917: </ol><p>This has the effect of reopening all the formatting elements that
1918: were opened in the current body, cell, or caption (whichever is
1919: youngest) that haven't been explicitly closed.</p>
1920:
1921: <p class="note">The way this specification is written, the
1922: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
1923: elements in chronological order with the least recently added
1924: element first and the most recently added element last (except for
1925: while steps 8 to 11 of the above algorithm are being executed, of
1926: course).</p>
1927:
1928: <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
1929: active formatting elements up to the last marker</dfn>, the UA must
1930: perform the following steps:</p>
1931:
1932: <ol><li>Let <var title="">entry</var> be the last (most recently added)
1933: entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
1934:
1935: <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
1936: formatting elements</a>.</li>
1937:
1938: <li>If <var title="">entry</var> was a marker, then stop the
1939: algorithm at this point. The list has been cleared up to the last
1940: marker.</li>
1941:
1942: <li>Go to step 1.</li>
1943:
1944: </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5>
1945:
1946: <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
1947: pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
1948: pointer</dfn> are both null.</p>
1949:
1.159 mike 1950: <p>Once a <code><a href="semantics.html#the-head-element-0">head</a></code> element has been parsed (whether
1.1 mike 1951: implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
1952: element pointer</a> gets set to point to this node.</p>
1953:
1954: <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
1955: points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
1956: whose end tag has not yet been seen. It is used to make form
1957: controls associate with forms in the face of dramatically bad
1958: markup, for historical reasons.</p>
1959:
1960:
1961: <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5>
1962:
1963: <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
1964: <code>Document</code> with which the parser is associated when the
1965: parser was created, and "disabled" otherwise.</p>
1966:
1967: <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
1968: when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
1969: parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
1970: don't execute in that case.</p>
1971:
1972: <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
1973: created. It is set to "not ok" after certain tokens are seen.</p>
1974:
1.266 mike 1975: </div><div class="impl">
1.1 mike 1976:
1.159 mike 1977: <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 1978:
1979: <p>Implementations must act as if they used the following state
1980: machine to tokenize HTML. The state machine must start in the
1981: <a href="#data-state">data state</a>. Most states consume a single character,
1982: which may have various side-effects, and either switches the state
1983: machine to a new state to <em>reconsume</em> the same character, or
1984: switches it to a new state (to consume the next character), or
1985: repeats the same state (to consume the next character). Some states
1986: have more complicated behavior and can consume several characters
1987: before switching to another state.</p>
1988:
1989: <p>The exact behavior of certain states depends on a <dfn id="content-model-flag">content
1990: model flag</dfn> that is set after certain tokens are emitted. The
1.91 mike 1991: 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
1992: state. In the RCDATA and RAWTEXT states, a further <dfn id="escape-flag">escape
1.1 mike 1993: flag</dfn> is used to control the behavior of the tokenizer. It is
1994: either true or false, and initially must be set to the false
1995: state. The <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
1996: elements</a> also affects tokenization.</p>
1997:
1998: <p>The output of the tokenization step is a series of zero or more
1999: of the following tokens: DOCTYPE, start tag, end tag, comment,
2000: character, end-of-file. DOCTYPE tokens have a name, a public
2001: identifier, a system identifier, and a <i>force-quirks
2002: flag</i>. When a DOCTYPE token is created, its name, public
2003: identifier, and system identifier must be marked as missing (which
2004: is a distinct state from the empty string), and the <i>force-quirks
2005: flag</i> must be set to <i>off</i> (its other state is
2006: <i>on</i>). Start and end tag tokens have a tag name, a
2007: <i>self-closing flag</i>, and a list of attributes, each of which
2008: has a name and a value. When a start or end tag token is created,
2009: its <i>self-closing flag</i> must be unset (its other state is that
2010: it be set), and its attributes list must be empty. Comment and
2011: character tokens have data.</p>
2012:
2013: <p>When a token is emitted, it must immediately be handled by the
2014: <a href="#tree-construction">tree construction</a> stage. The tree construction stage
2015: can affect the state of the <a href="#content-model-flag">content model flag</a>, and can
2016: insert additional characters into the stream. (For example, the
2017: <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
1.159 mike 2018: using the <a href="embedded-content-0.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
1.1 mike 2019: characters into the stream being tokenized.)</p>
2020:
2021: <p>When a start tag token is emitted with its <i>self-closing
2022: flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
2023: self-closing flag">acknowledged</dfn> when it is processed by the
2024: tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
2025:
2026: <p>When an end tag token is emitted, the <a href="#content-model-flag">content model
2027: flag</a> must be switched to the PCDATA state.</p>
2028:
2029: <p>When an end tag token is emitted with attributes, that is a
2030: <a href="#parse-error">parse error</a>.</p>
2031:
2032: <p>When an end tag token is emitted with its <i>self-closing
2033: flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
2034:
2035: <p>Before each step of the tokenizer, the user agent must first
2036: check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
2037: tokenizer must abort the processing of any nested invocations of the
2038: tokenizer, yielding control back to the caller. If it is false, then
2039: the user agent may then check to see if either one of the scripts in
2040: the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will execute as soon as
2041: possible</a> or the first script in the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts
2042: that will execute asynchronously</a>, has <a href="semantics.html#completed-loading">completed
2043: loading</a>. If one has, then it must be <a href="semantics.html#executing-a-script-block" title="executing a
2044: script block">executed</a> and removed from its list.</p>
2045:
2046: <p>The tokenizer state machine consists of the states defined in the
2047: following subsections.</p>
2048:
1.333 mike 2049: <!-- Order of the lists below is supposed to be non-error then
2050: error, by unicode, then EOF, ending with "anything else" -->
1.1 mike 2051:
2052: <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5>
2053:
2054: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2055:
2056: <dl class="switch"><dt>U+0026 AMPERSAND (&)</dt>
2057: <dd>When the <a href="#content-model-flag">content model flag</a> is set to one of the
2058: PCDATA or RCDATA states and the <a href="#escape-flag">escape flag</a> is
1.299 mike 2059: false: switch to the <a href="#character-reference-in-data-state">character reference in data
1.56 mike 2060: state</a>.</dd>
2061: <dd>Otherwise: treat it as per the "anything else" entry
2062: below.</dd>
1.1 mike 2063:
2064: <dt>U+002D HYPHEN-MINUS (-)</dt>
2065: <dd>
2066:
2067: <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 2068: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1 mike 2069: is false, and there are at least three characters before this
2070: one in the input stream, and the last four characters in the
2071: input stream, including this one, are U+003C LESS-THAN SIGN,
2072: U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, and U+002D
2073: HYPHEN-MINUS ("<!--"), then set the <a href="#escape-flag">escape flag</a>
2074: to true.</p>
2075:
2076: <p>In any case, emit the input character as a character
2077: token. Stay in the <a href="#data-state">data state</a>.</p>
2078:
2079: </dd>
2080:
2081: <dt>U+003C LESS-THAN SIGN (<)</dt>
2082: <dd>When the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
2083: state: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
2084: <dd>When the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 2085: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1 mike 2086: is false: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
2087: <dd>Otherwise: treat it as per the "anything else" entry
2088: below.</dd>
2089:
2090: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2091: <dd>
2092:
2093: <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 2094: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape
1.1 mike 2095: flag</a> is true, and the last three characters in the input
2096: stream including this one are U+002D HYPHEN-MINUS, U+002D
2097: HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("-->"), set the
2098: <a href="#escape-flag">escape flag</a> to false.</p> <!-- no need to check
2099: that there are enough characters, since you can only run into
2100: this if the flag is true in the first place, which requires four
2101: characters. -->
2102:
2103: <p>In any case, emit the input character as a character
2104: token. Stay in the <a href="#data-state">data state</a>.</p>
2105:
2106: </dd>
2107:
2108: <dt>EOF</dt>
2109: <dd>Emit an end-of-file token.</dd>
2110:
2111: <dt>Anything else</dt>
2112: <dd>Emit the input character as a character token. Stay in the
2113: <a href="#data-state">data state</a>.</dd>
2114:
1.299 mike 2115: </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 2116:
2117: <p><i>(This cannot happen if the <a href="#content-model-flag">content model flag</a>
1.91 mike 2118: is set to the RAWTEXT state.)</i></p>
1.1 mike 2119:
2120: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
2121: <a href="#additional-allowed-character">additional allowed character</a>.</p>
2122:
2123: <p>If nothing is returned, emit a U+0026 AMPERSAND character
2124: token.</p>
2125:
2126: <p>Otherwise, emit the character token that was returned.</p>
2127:
2128: <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
2129:
2130:
2131: <h5 id="tag-open-state"><span class="secno">9.2.4.3 </span><dfn>Tag open state</dfn></h5>
2132:
2133: <p>The behavior of this state depends on the <a href="#content-model-flag">content model
2134: flag</a>.</p>
2135:
2136: <dl><dt>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA
1.91 mike 2137: or RAWTEXT states</dt>
1.1 mike 2138:
2139: <dd>
2140:
2141: <p>Consume the <a href="#next-input-character">next input character</a>. If it is a
2142: U+002F SOLIDUS (/) character, switch to the <a href="#close-tag-open-state">close tag open
2143: state</a>. Otherwise, emit a U+003C LESS-THAN SIGN character
2144: token and reconsume the <a href="#current-input-character">current input character</a> in the
2145: <a href="#data-state">data state</a>.</p>
2146:
2147: </dd>
2148:
2149: <dt>If the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
2150: state</dt>
2151:
2152: <dd>
2153:
2154: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2155:
2156: <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
2157: <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
2158:
2159: <dt>U+002F SOLIDUS (/)</dt>
2160: <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
2161:
2162: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2163: <dd>Create a new start tag token, set its tag name to the
2164: lowercase version of the input character (add 0x0020 to the
2165: character's code point), then switch to the <a href="#tag-name-state">tag name
2166: state</a>. (Don't emit the token yet; further details will
2167: be filled in before it is emitted.)</dd>
2168:
2169: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2170: <dd>Create a new start tag token, set its tag name to the input
2171: character, then switch to the <a href="#tag-name-state">tag name
2172: state</a>. (Don't emit the token yet; further details will
2173: be filled in before it is emitted.)</dd>
2174:
2175: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2176: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2177: character token and a U+003E GREATER-THAN SIGN character
2178: token. Switch to the <a href="#data-state">data state</a>.</dd>
2179:
2180: <dt>U+003F QUESTION MARK (?)</dt>
2181: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2182: comment state</a>.</dd>
2183:
2184: <dt>Anything else</dt>
2185: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2186: character token and reconsume the <a href="#current-input-character">current input character</a> in the
2187: <a href="#data-state">data state</a>.</dd>
2188:
2189: </dl></dd>
2190:
2191: </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.4 </span><dfn>Close tag open state</dfn></h5>
2192:
2193: <p>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA or
1.91 mike 2194: RAWTEXT states but no start tag token has ever been emitted by this
1.1 mike 2195: instance of the tokenizer (<a href="#fragment-case">fragment case</a>), or, if the
1.91 mike 2196: <a href="#content-model-flag">content model flag</a> is set to the RCDATA or RAWTEXT states
1.1 mike 2197: and the next few characters do not match the tag name of the last
2198: start tag token emitted (compared in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2199: case-insensitive</a> manner), or if they do but they are not
2200: immediately followed by one of the following characters:</p>
2201:
2202: <ul class="brief"><li>U+0009 CHARACTER TABULATION</li>
2203: <li>U+000A LINE FEED (LF)</li>
2204: <li>U+000C FORM FEED (FF)</li>
2205: <!--<li>U+000D CARRIAGE RETURN (CR)</li>-->
2206: <li>U+0020 SPACE</li>
2207: <li>U+003E GREATER-THAN SIGN (>)</li>
2208: <li>U+002F SOLIDUS (/)</li>
2209: <li>EOF</li>
2210: </ul><p>...then emit a U+003C LESS-THAN SIGN character token, a U+002F
2211: SOLIDUS character token, and switch to the <a href="#data-state">data state</a>
2212: to process the <a href="#next-input-character">next input character</a>.</p>
2213:
2214: <p>Otherwise, if the <a href="#content-model-flag">content model flag</a> is set to the
2215: PCDATA state, or if the next few characters <em>do</em> match that tag
2216: name, consume the <a href="#next-input-character">next input character</a>:</p>
2217:
2218: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2219: <dd>Create a new end tag token, set its tag name to the lowercase
2220: version of the input character (add 0x0020 to the character's
2221: code point), then switch to the <a href="#tag-name-state">tag name
2222: state</a>. (Don't emit the token yet; further details will be
2223: filled in before it is emitted.)</dd>
2224:
2225: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2226: <dd>Create a new end tag token, set its tag name to the input
2227: character, then switch to the <a href="#tag-name-state">tag name state</a>. (Don't
2228: emit the token yet; further details will be filled in before it
2229: is emitted.)</dd>
2230:
2231: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2232: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
2233: state</a>.</dd>
2234:
2235: <dt>EOF</dt>
2236: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2237: character token and a U+002F SOLIDUS character token. Reconsume
2238: the EOF character in the <a href="#data-state">data state</a>.</dd>
2239:
2240: <dt>Anything else</dt>
2241: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2242: comment state</a>.</dd>
2243:
2244: </dl><h5 id="tag-name-state"><span class="secno">9.2.4.5 </span><dfn>Tag name state</dfn></h5>
2245:
2246: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2247:
2248: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2249: <dt>U+000A LINE FEED (LF)</dt>
2250: <dt>U+000C FORM FEED (FF)</dt>
2251: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2252: <dt>U+0020 SPACE</dt>
2253: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2254:
2255: <dt>U+002F SOLIDUS (/)</dt>
2256: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2257:
2258: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2259: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2260: state</a>.</dd>
2261:
2262: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2263: <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
2264: (add 0x0020 to the character's code point) to the current tag
2265: token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
2266:
2267: <dt>EOF</dt>
2268: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2269: <a href="#data-state">data state</a>.</dd>
2270:
2271: <dt>Anything else</dt>
2272: <dd>Append the <a href="#current-input-character">current input character</a> to the current tag token's
2273: tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
2274:
2275: </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.6 </span><dfn>Before attribute name state</dfn></h5>
2276:
2277: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2278:
2279: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2280: <dt>U+000A LINE FEED (LF)</dt>
2281: <dt>U+000C FORM FEED (FF)</dt>
2282: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2283: <dt>U+0020 SPACE</dt>
2284: <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2285:
2286: <dt>U+002F SOLIDUS (/)</dt>
2287: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2288:
2289: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2290: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2291: state</a>.</dd>
2292:
2293: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2294: <dd>Start a new attribute in the current tag token. Set that
2295: attribute's name to the lowercase version of the <a href="#current-input-character">current input
2296: character</a> (add 0x0020 to the character's code point), and its
2297: value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
2298: state</a>.</dd>
2299:
2300: <dt>U+0022 QUOTATION MARK (")</dt>
2301: <dt>U+0027 APOSTROPHE (')</dt>
2302: <dt>U+003C LESS-THAN SIGN (<)</dt>
2303: <dt>U+003D EQUALS SIGN (=)</dt>
2304: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2305: entry below.</dd>
2306:
2307: <dt>EOF</dt>
2308: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2309: <a href="#data-state">data state</a>.</dd>
2310:
2311: <dt>Anything else</dt>
2312: <dd>Start a new attribute in the current tag token. Set that
2313: attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
2314: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2315: state</a>.</dd>
2316:
2317: </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.7 </span><dfn>Attribute name state</dfn></h5>
2318:
2319: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2320:
2321: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2322: <dt>U+000A LINE FEED (LF)</dt>
2323: <dt>U+000C FORM FEED (FF)</dt>
2324: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2325: <dt>U+0020 SPACE</dt>
2326: <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
2327:
2328: <dt>U+002F SOLIDUS (/)</dt>
2329: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2330:
2331: <dt>U+003D EQUALS SIGN (=)</dt>
2332: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2333:
2334: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2335: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2336: state</a>.</dd>
2337:
2338: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2339: <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
2340: (add 0x0020 to the character's code point) to the current
2341: attribute's name. Stay in the <a href="#attribute-name-state">attribute name
2342: state</a>.</dd>
2343:
2344: <dt>U+0022 QUOTATION MARK (")</dt>
2345: <dt>U+0027 APOSTROPHE (')</dt>
2346: <dt>U+003C LESS-THAN SIGN (<)</dt>
2347: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2348: entry below.</dd>
2349:
2350: <dt>EOF</dt>
2351: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2352: <a href="#data-state">data state</a>.</dd>
2353:
2354: <dt>Anything else</dt>
2355: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2356: name. Stay in the <a href="#attribute-name-state">attribute name state</a>.</dd>
2357:
2358: </dl><p>When the user agent leaves the attribute name state (and before
2359: emitting the tag token, if appropriate), the complete attribute's
2360: name must be compared to the other attributes on the same token;
2361: if there is already an attribute on the token with the exact same
2362: name, then this is a <a href="#parse-error">parse error</a> and the new
2363: attribute must be dropped, along with the value that gets
2364: associated with it (if any).</p>
2365:
2366:
2367: <h5 id="after-attribute-name-state"><span class="secno">9.2.4.8 </span><dfn>After attribute name state</dfn></h5>
2368:
2369: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2370:
2371: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2372: <dt>U+000A LINE FEED (LF)</dt>
2373: <dt>U+000C FORM FEED (FF)</dt>
2374: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2375: <dt>U+0020 SPACE</dt>
2376: <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
2377:
2378: <dt>U+002F SOLIDUS (/)</dt>
2379: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2380:
2381: <dt>U+003D EQUALS SIGN (=)</dt>
2382: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2383:
2384: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2385: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2386: state</a>.</dd>
2387:
2388: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2389: <dd>Start a new attribute in the current tag token. Set that
2390: attribute's name to the lowercase version of the <a href="#current-input-character">current input character</a>
2391: (add 0x0020 to the character's code point), and its value to
2392: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2393: state</a>.</dd>
2394:
2395: <dt>U+0022 QUOTATION MARK (")</dt>
2396: <dt>U+0027 APOSTROPHE (')</dt>
2397: <dt>U+003C LESS-THAN SIGN (<)</dt>
2398: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2399: entry below.</dd>
2400:
2401: <dt>EOF</dt>
2402: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2403: <a href="#data-state">data state</a>.</dd>
2404:
2405: <dt>Anything else</dt>
2406: <dd>Start a new attribute in the current tag token. Set that
2407: attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
2408: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2409: state</a>.</dd>
2410:
2411: </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.9 </span><dfn>Before attribute value state</dfn></h5>
2412:
2413: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2414:
2415: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2416: <dt>U+000A LINE FEED (LF)</dt>
2417: <dt>U+000C FORM FEED (FF)</dt>
2418: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2419: <dt>U+0020 SPACE</dt>
2420: <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2421:
2422: <dt>U+0022 QUOTATION MARK (")</dt>
2423: <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
2424:
2425: <dt>U+0026 AMPERSAND (&)</dt>
2426: <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
2427: and reconsume this input character.</dd>
2428:
2429: <dt>U+0027 APOSTROPHE (')</dt>
2430: <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
2431:
2432: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2433: <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
2434: the <a href="#data-state">data state</a>.</dd>
2435:
2436: <dt>U+003C LESS-THAN SIGN (<)</dt>
2437: <dt>U+003D EQUALS SIGN (=)</dt>
2438: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2439: entry below.</dd>
2440:
2441: <dt>EOF</dt>
2442: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2443: <a href="#data-state">data state</a>.</dd>
2444:
2445: <dt>Anything else</dt>
2446: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2447: attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
2448: state</a>.</dd>
2449:
2450: </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.10 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
2451:
2452: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2453:
2454: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
2455: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
2456: state</a>.</dd>
2457:
2458: <dt>U+0026 AMPERSAND (&)</dt>
2459: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
2460: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2461: being U+0022 QUOTATION MARK (").</dd>
2462:
2463: <dt>EOF</dt>
2464: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2465: <a href="#data-state">data state</a>.</dd>
2466:
2467: <dt>Anything else</dt>
2468: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2469: value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted)
2470: state</a>.</dd>
2471:
2472: </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.11 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
2473:
2474: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2475:
2476: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
2477: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
2478: state</a>.</dd>
2479:
2480: <dt>U+0026 AMPERSAND (&)</dt>
2481: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
2482: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2483: being U+0027 APOSTROPHE (').</dd>
2484:
2485: <dt>EOF</dt>
2486: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2487: <a href="#data-state">data state</a>.</dd>
2488:
2489: <dt>Anything else</dt>
2490: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2491: value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted)
2492: state</a>.</dd>
2493:
2494: </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.12 </span><dfn>Attribute value (unquoted) state</dfn></h5>
2495:
2496: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2497:
2498: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2499: <dt>U+000A LINE FEED (LF)</dt>
2500: <dt>U+000C FORM FEED (FF)</dt>
2501: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2502: <dt>U+0020 SPACE</dt>
2503: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2504:
2505: <dt>U+0026 AMPERSAND (&)</dt>
2506: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
1.299 mike 2507: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2508: being U+003E GREATER-THAN SIGN (>).</dd>
1.1 mike 2509:
2510: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2511: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2512: state</a>.</dd>
2513:
2514: <dt>U+0022 QUOTATION MARK (")</dt>
2515: <dt>U+0027 APOSTROPHE (')</dt>
2516: <dt>U+003C LESS-THAN SIGN (<)</dt>
2517: <dt>U+003D EQUALS SIGN (=)</dt>
2518: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2519: entry below.</dd>
2520:
2521: <dt>EOF</dt>
2522: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2523: <a href="#data-state">data state</a>.</dd>
2524:
2525: <dt>Anything else</dt>
2526: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2527: value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
2528: state</a>.</dd>
2529:
2530: </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>
2531:
2532: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
2533:
2534: <p>If nothing is returned, append a U+0026 AMPERSAND character to
2535: the current attribute's value.</p>
2536:
2537: <p>Otherwise, append the returned character token to the current
2538: attribute's value.</p>
2539:
2540: <p>Finally, switch back to the attribute value state that you were
2541: in when were switched into this state.</p>
2542:
2543:
2544: <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.14 </span><dfn>After attribute value (quoted) state</dfn></h5>
2545:
2546: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2547:
2548: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2549: <dt>U+000A LINE FEED (LF)</dt>
2550: <dt>U+000C FORM FEED (FF)</dt>
2551: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2552: <dt>U+0020 SPACE</dt>
2553: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2554:
2555: <dt>U+002F SOLIDUS (/)</dt>
2556: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2557:
2558: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2559: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2560: state</a>.</dd>
2561:
2562: <dt>EOF</dt>
2563: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2564: <a href="#data-state">data state</a>.</dd>
2565:
2566: <dt>Anything else</dt>
2567: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
2568: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2569:
2570: </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.15 </span><dfn>Self-closing start tag state</dfn></h5>
2571:
2572: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2573:
2574: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2575: <dd>Set the <i>self-closing flag</i> of the current tag
2576: token. Emit the current tag token. Switch to the <a href="#data-state">data
2577: state</a>.</dd>
2578:
2579: <dt>EOF</dt>
2580: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2581: <a href="#data-state">data state</a>.</dd>
2582:
2583: <dt>Anything else</dt>
2584: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
2585: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2586:
2587: </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.16 </span><dfn>Bogus comment state</dfn></h5>
2588:
2589: <p><i>(This can only happen if the <a href="#content-model-flag">content model
2590: flag</a> is set to the PCDATA state.)</i></p>
2591:
2592: <p>Consume every character up to and including the first U+003E
2593: GREATER-THAN SIGN character (>) or the end of the file (EOF),
2594: whichever comes first. Emit a comment token whose data is the
2595: concatenation of all the characters starting from and including
2596: the character that caused the state machine to switch into the
2597: bogus comment state, up to and including the character immediately
2598: before the last consumed character (i.e. up to the character just
2599: before the U+003E or EOF character). (If the comment was started
2600: by the end of the file (EOF), the token is empty.)</p>
2601:
2602: <p>Switch to the <a href="#data-state">data state</a>.</p>
2603:
2604: <p>If the end of the file was reached, reconsume the EOF
2605: character.</p>
2606:
2607:
2608: <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.17 </span><dfn>Markup declaration open state</dfn></h5>
2609:
2610: <p><i>(This can only happen if the <a href="#content-model-flag">content model
2611: flag</a> is set to the PCDATA state.)</i></p>
2612:
2613: <p>If the next two characters are both U+002D HYPHEN-MINUS (-)
2614: characters, consume those two characters, create a comment token
2615: whose data is the empty string, and switch to the <a href="#comment-start-state">comment
2616: start state</a>.</p>
2617:
2618: <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2619: case-insensitive</a> match for the word "DOCTYPE", then consume
2620: those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
2621:
2622: <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
2623: content</a>" and the <a href="#current-node">current node</a> is not an element
2624: in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
2625: an <span>ASCII case-sensitive</span> match for the string "[CDATA["
2626: (the five uppercase letters "CDATA" with a U+005B LEFT SQUARE
2627: BRACKET character before and after), then consume those characters
1.91 mike 2628: and switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1 mike 2629:
2630: <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
2631: <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
2632: consumed, if any, is the first character that will be in the
2633: comment.</p>
2634:
2635:
2636: <h5 id="comment-start-state"><span class="secno">9.2.4.18 </span><dfn>Comment start state</dfn></h5>
2637:
2638: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2639:
2640: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2641: <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
2642:
2643: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2644: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
2645: <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
2646: -->
2647:
2648: <dt>EOF</dt>
2649: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2650: the EOF character in the <a href="#data-state">data state</a>.</dd>
2651:
2652: <dt>Anything else</dt>
2653: <dd>Append the input character to the comment token's
2654: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
2655:
2656: </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.19 </span><dfn>Comment start dash state</dfn></h5>
2657:
2658: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2659:
2660: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2661: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
2662:
2663: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2664: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
2665: the <a href="#data-state">data state</a>.</dd>
2666:
2667: <dt>EOF</dt>
2668: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2669: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2670: in comment end state -->
2671:
2672: <dt>Anything else</dt>
2673: <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
2674: character to the comment token's data. Switch to the
2675: <a href="#comment-state">comment state</a>.</dd>
2676:
2677: </dl><h5 id="comment-state"><span class="secno">9.2.4.20 </span><dfn id="comment">Comment state</dfn></h5>
2678:
2679: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2680:
2681: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2682: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
2683:
2684: <dt>EOF</dt>
2685: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2686: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2687: in comment end state -->
2688:
2689: <dt>Anything else</dt>
2690: <dd>Append the input character to the comment token's data. Stay
2691: in the <a href="#comment-state">comment state</a>.</dd>
2692:
2693: </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.21 </span><dfn>Comment end dash state</dfn></h5>
2694:
2695: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2696:
2697: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2698: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
2699:
2700: <dt>EOF</dt>
2701: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2702: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2703: in comment end state -->
2704:
2705: <dt>Anything else</dt>
2706: <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
2707: character to the comment token's data. Switch to the
2708: <a href="#comment-state">comment state</a>.</dd>
2709:
2710: </dl><h5 id="comment-end-state"><span class="secno">9.2.4.22 </span><dfn>Comment end state</dfn></h5>
2711:
2712: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2713:
2714: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2715: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2716: state</a>.</dd>
2717:
2718: <dt>U+0009 CHARACTER TABULATION</dt>
2719: <dt>U+000A LINE FEED (LF)</dt>
2720: <dt>U+000C FORM FEED (FF)</dt>
2721: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2722: <dt>U+0020 SPACE</dt>
2723: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
2724: characters and the input character to the comment token's
2725: data. Switch to the <a href="#comment-end-space-state">comment end space state</a>.</dd>
2726:
2727: <dt>U+0021 EXCLAMATION MARK (!)</dt>
2728: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
2729: state</a>.</dd>
2730:
1.333 mike 2731: <dt>U+002D HYPHEN-MINUS (-)</dt>
2732: <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
2733: (-) character to the comment token's data. Stay in the
2734: <a href="#comment-end-state">comment end state</a>.</dd>
2735:
1.1 mike 2736: <dt>EOF</dt>
2737: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2738: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
2739: security reasons: otherwise, hostile user could put a <script> in
2740: a comment e.g. in a blog comment and then DOS the server so that
2741: the end tag isn't read, and then the commented <script> tag would
2742: be treated as live code -->
2743:
2744: <dt>Anything else</dt>
2745: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
2746: characters and the input character to the comment token's
2747: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
2748:
2749: </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.23 </span><dfn>Comment end bang state</dfn></h5>
2750:
2751: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2752:
1.333 mike 2753: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
1.1 mike 2754: <dd>Append two U+002D HYPHEN-MINUS (-) characters and a U+0021
2755: EXCLAMATION MARK (!) character to the comment token's data. Switch
2756: to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
2757:
1.333 mike 2758: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2759: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2760: state</a>.</dd>
2761:
1.1 mike 2762: <dt>EOF</dt>
2763: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2764: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
2765: comment in comment end state -->
2766:
2767: <dt>Anything else</dt>
2768: <dd>Append two U+002D HYPHEN-MINUS (-) characters, a U+0021
2769: EXCLAMATION MARK (!) character, and the input character to the
2770: comment token's data. Switch to the <a href="#comment-state">comment
2771: state</a>.</dd>
2772:
2773: </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.24 </span><dfn>Comment end space state</dfn></h5>
2774:
2775: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2776:
1.333 mike 2777: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
1.1 mike 2778: <dt>U+000A LINE FEED (LF)</dt>
2779: <dt>U+000C FORM FEED (FF)</dt>
2780: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2781: <dt>U+0020 SPACE</dt>
2782: <dd>Append the input character to the comment token's data. Stay in
2783: the <a href="#comment-end-space-state">comment end space state</a>.</dd>
2784:
1.333 mike 2785: <dt>U+002D HYPHEN-MINUS (-)</dt>
2786: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
2787:
2788: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2789: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2790: state</a>.</dd>
2791:
1.1 mike 2792: <dt>EOF</dt>
2793: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2794: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
2795: comment in comment end state -->
2796:
2797: <dt>Anything else</dt>
2798: <dd>Append the input character to the comment token's data. Switch
2799: to the <a href="#comment-state">comment state</a>.</dd>
2800:
2801: </dl><h5 id="doctype-state"><span class="secno">9.2.4.25 </span><dfn>DOCTYPE state</dfn></h5>
2802:
2803: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2804:
2805: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2806: <dt>U+000A LINE FEED (LF)</dt>
2807: <dt>U+000C FORM FEED (FF)</dt>
2808: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2809: <dt>U+0020 SPACE</dt>
2810: <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2811:
2812: <dt>EOF</dt>
2813: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2814: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
2815: the EOF character in the <a href="#data-state">data state</a>.</dd>
2816:
2817: <dt>Anything else</dt>
2818: <dd><a href="#parse-error">Parse error</a>. Reconsume the current
2819: character in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2820:
2821: </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.26 </span><dfn>Before DOCTYPE name state</dfn></h5>
2822:
2823: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2824:
2825: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2826: <dt>U+000A LINE FEED (LF)</dt>
2827: <dt>U+000C FORM FEED (FF)</dt>
2828: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2829: <dt>U+0020 SPACE</dt>
2830: <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2831:
2832: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2833: <dd>Create a new DOCTYPE token. Set the token's name to the
2834: lowercase version of the input character (add 0x0020 to the
2835: character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
2836: state</a>.</dd>
2837:
1.333 mike 2838: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2839: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2840: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
2841: the <a href="#data-state">data state</a>.</dd>
2842:
1.1 mike 2843: <dt>EOF</dt>
2844: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2845: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
2846: the EOF character in the <a href="#data-state">data state</a>.</dd>
2847:
2848: <dt>Anything else</dt>
2849: <dd>Create a new DOCTYPE token. Set the token's name to the
2850: <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
2851: state</a>.</dd>
2852:
2853: </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.27 </span><dfn>DOCTYPE name state</dfn></h5>
2854:
2855: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2856:
2857: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2858: <dt>U+000A LINE FEED (LF)</dt>
2859: <dt>U+000C FORM FEED (FF)</dt>
2860: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2861: <dt>U+0020 SPACE</dt>
2862: <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
2863:
2864: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2865: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
2866: state</a>.</dd>
2867:
2868: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2869: <dd>Append the lowercase version of the input character (add 0x0020
2870: to the character's code point) to the current DOCTYPE token's
2871: name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
2872:
2873: <dt>EOF</dt>
2874: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2875: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2876: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2877:
2878: <dt>Anything else</dt>
2879: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
2880: token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
2881:
2882: </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.28 </span><dfn>After DOCTYPE name state</dfn></h5>
2883:
2884: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2885:
2886: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2887: <dt>U+000A LINE FEED (LF)</dt>
2888: <dt>U+000C FORM FEED (FF)</dt>
2889: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2890: <dt>U+0020 SPACE</dt>
2891: <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
2892:
2893: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2894: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
2895: state</a>.</dd>
2896:
2897: <dt>EOF</dt>
2898: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2899: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2900: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2901:
2902: <dt>Anything else</dt>
2903: <dd>
2904:
2905: <p>If the six characters starting from the <a href="#current-input-character">current input
2906: character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
2907: for the word "PUBLIC", then consume those characters and switch to
2908: the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</p>
2909:
2910: <p>Otherwise, if the six characters starting from the
2911: <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2912: case-insensitive</a> match for the word "SYSTEM", then consume
2913: those characters and switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system
2914: identifier state</a>.</p>
2915:
2916: <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
2917: DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
2918: the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
2919:
2920: </dd>
2921:
2922: </dl><h5 id="before-doctype-public-identifier-state"><span class="secno">9.2.4.29 </span><dfn>Before DOCTYPE public identifier state</dfn></h5>
2923:
2924: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2925:
2926: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2927: <dt>U+000A LINE FEED (LF)</dt>
2928: <dt>U+000C FORM FEED (FF)</dt>
2929: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2930: <dt>U+0020 SPACE</dt>
2931: <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
2932:
2933: <dt>U+0022 QUOTATION MARK (")</dt>
2934: <dd>Set the DOCTYPE token's public identifier to the empty string
2935: (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
2936: (double-quoted) state</a>.</dd>
2937:
2938: <dt>U+0027 APOSTROPHE (')</dt>
2939: <dd>Set the DOCTYPE token's public identifier to the empty string
2940: (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
2941: (single-quoted) state</a>.</dd>
2942:
2943: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2944: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2945: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2946: token. Switch to the <a href="#data-state">data state</a>.</dd>
2947:
2948: <dt>EOF</dt>
2949: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2950: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2951: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2952:
2953: <dt>Anything else</dt>
2954: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2955: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
2956: DOCTYPE state</a>.</dd>
2957:
2958: </dl><h5 id="doctype-public-identifier-double-quoted-state"><span class="secno">9.2.4.30 </span><dfn>DOCTYPE public identifier (double-quoted) state</dfn></h5>
2959:
2960: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2961:
2962: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
2963: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
2964:
2965: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2966: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2967: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2968: token. Switch to the <a href="#data-state">data state</a>.</dd>
2969:
2970: <dt>EOF</dt>
2971: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2972: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2973: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2974:
2975: <dt>Anything else</dt>
2976: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
2977: token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
2978: identifier (double-quoted) state</a>.</dd>
2979:
2980: </dl><h5 id="doctype-public-identifier-single-quoted-state"><span class="secno">9.2.4.31 </span><dfn>DOCTYPE public identifier (single-quoted) state</dfn></h5>
2981:
2982: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2983:
2984: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
2985: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
2986:
2987: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2988: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2989: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2990: token. Switch to the <a href="#data-state">data state</a>.</dd>
2991:
2992: <dt>EOF</dt>
2993: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2994: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2995: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2996:
2997: <dt>Anything else</dt>
2998: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
2999: token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
3000: identifier (single-quoted) state</a>.</dd>
3001:
3002: </dl><h5 id="after-doctype-public-identifier-state"><span class="secno">9.2.4.32 </span><dfn>After DOCTYPE public identifier state</dfn></h5>
3003:
3004: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3005:
3006: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3007: <dt>U+000A LINE FEED (LF)</dt>
3008: <dt>U+000C FORM FEED (FF)</dt>
3009: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3010: <dt>U+0020 SPACE</dt>
3011: <dd>Stay in the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
3012:
3013: <dt>U+0022 QUOTATION MARK (")</dt>
3014: <dd>Set the DOCTYPE token's system identifier to the empty string
3015: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
3016: (double-quoted) state</a>.</dd>
3017:
3018: <dt>U+0027 APOSTROPHE (')</dt>
3019: <dd>Set the DOCTYPE token's system identifier to the empty string
3020: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
3021: (single-quoted) state</a>.</dd>
3022:
3023: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3024: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3025: state</a>.</dd>
3026:
3027: <dt>EOF</dt>
3028: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3029: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3030: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3031:
3032: <dt>Anything else</dt>
3033: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3034: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3035: DOCTYPE state</a>.</dd>
3036:
3037: </dl><h5 id="before-doctype-system-identifier-state"><span class="secno">9.2.4.33 </span><dfn>Before DOCTYPE system identifier state</dfn></h5>
3038:
3039: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3040:
3041: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3042: <dt>U+000A LINE FEED (LF)</dt>
3043: <dt>U+000C FORM FEED (FF)</dt>
3044: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3045: <dt>U+0020 SPACE</dt>
3046: <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
3047:
3048: <dt>U+0022 QUOTATION MARK (")</dt>
3049: <dd>Set the DOCTYPE token's system identifier to the empty string
3050: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
3051: (double-quoted) state</a>.</dd>
3052:
3053: <dt>U+0027 APOSTROPHE (')</dt>
3054: <dd>Set the DOCTYPE token's system identifier to the empty string
3055: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
3056: (single-quoted) state</a>.</dd>
3057:
3058: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3059: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3060: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3061: token. Switch to the <a href="#data-state">data state</a>.</dd>
3062:
3063: <dt>EOF</dt>
3064: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3065: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3066: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3067:
3068: <dt>Anything else</dt>
3069: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3070: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3071: DOCTYPE state</a>.</dd>
3072:
3073: </dl><h5 id="doctype-system-identifier-double-quoted-state"><span class="secno">9.2.4.34 </span><dfn>DOCTYPE system identifier (double-quoted) state</dfn></h5>
3074:
3075: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3076:
3077: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
3078: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
3079:
3080: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3081: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3082: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3083: token. Switch to the <a href="#data-state">data 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>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3092: token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
3093: identifier (double-quoted) state</a>.</dd>
3094:
3095: </dl><h5 id="doctype-system-identifier-single-quoted-state"><span class="secno">9.2.4.35 </span><dfn>DOCTYPE system identifier (single-quoted) state</dfn></h5>
3096:
3097: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3098:
3099: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
3100: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
3101:
3102: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3103: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3104: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3105: token. Switch to the <a href="#data-state">data 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>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3114: token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
3115: identifier (single-quoted) state</a>.</dd>
3116:
3117: </dl><h5 id="after-doctype-system-identifier-state"><span class="secno">9.2.4.36 </span><dfn>After DOCTYPE system identifier state</dfn></h5>
3118:
3119: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3120:
3121: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3122: <dt>U+000A LINE FEED (LF)</dt>
3123: <dt>U+000C FORM FEED (FF)</dt>
3124: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3125: <dt>U+0020 SPACE</dt>
3126: <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
3127:
3128: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3129: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3130: state</a>.</dd>
3131:
3132: <dt>EOF</dt>
3133: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3134: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3135: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3136:
3137: <dt>Anything else</dt>
3138: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
3139: state</a>. (This does <em>not</em> set the DOCTYPE token's
3140: <i>force-quirks flag</i> to <i>on</i>.)</dd>
3141:
3142: </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.37 </span><dfn>Bogus DOCTYPE state</dfn></h5>
3143:
3144: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3145:
3146: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
3147: <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
3148: state</a>.</dd>
3149:
3150: <dt>EOF</dt>
3151: <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
3152: <a href="#data-state">data state</a>.</dd>
3153:
3154: <dt>Anything else</dt>
3155: <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
3156:
3157: </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.38 </span><dfn>CDATA section state</dfn></h5>
3158:
3159: <p><i>(This can only happen if the <a href="#content-model-flag">content model
1.91 mike 3160: flag</a> is set to the PCDATA state.)</i></p>
1.1 mike 3161:
3162: <p>Consume every character up to the next occurrence of the three
3163: character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
3164: BRACKET U+003E GREATER-THAN SIGN (<code title="">]]></code>), or the
3165: end of the file (EOF), whichever comes first. Emit a series of
3166: character tokens consisting of all the characters consumed except
3167: the matching three character sequence at the end (if one was found
3168: before the end of the file).</p>
3169:
3170: <p>Switch to the <a href="#data-state">data state</a>.</p>
3171:
3172: <p>If the end of the file was reached, reconsume the EOF
3173: character.</p>
3174:
3175:
3176:
3177: <h5 id="tokenizing-character-references"><span class="secno">9.2.4.39 </span>Tokenizing character references</h5>
3178:
3179: <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
3180: reference</dfn>. This definition is used when parsing character
1.299 mike 3181: references <a href="#character-reference-in-data-state" title="character reference in data state">in
1.1 mike 3182: text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
3183: state">in attributes</a>.</p>
3184:
3185: <p>The behavior depends on the identity of the next character (the
3186: one immediately after the U+0026 AMPERSAND character):</p>
3187:
3188: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3189: <dt>U+000A LINE FEED (LF)</dt>
3190: <dt>U+000C FORM FEED (FF)</dt>
3191: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3192: <dt>U+0020 SPACE</dt>
3193: <dt>U+003C LESS-THAN SIGN</dt>
3194: <dt>U+0026 AMPERSAND</dt>
3195: <dt>EOF</dt>
3196: <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
3197:
3198: <dd>Not a character reference. No characters are consumed, and
3199: nothing is returned. (This is not an error, either.)</dd>
3200:
3201:
3202: <dt>U+0023 NUMBER SIGN (#)</dt>
3203:
3204: <dd>
3205:
3206: <p>Consume the U+0023 NUMBER SIGN.</p>
3207:
3208: <p>The behavior further depends on the character after the U+0023
3209: NUMBER SIGN:</p>
3210:
3211: <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
3212: <dt>U+0058 LATIN CAPITAL LETTER X</dt>
3213:
3214: <dd>
3215:
3216: <p>Consume the X.</p>
3217:
3218: <p>Follow the steps below, but using the range of characters
3219: U+0030 DIGIT ZERO through to U+0039 DIGIT NINE, U+0061 LATIN
3220: SMALL LETTER A through to U+0066 LATIN SMALL LETTER F, and
3221: U+0041 LATIN CAPITAL LETTER A, through to U+0046 LATIN CAPITAL
3222: LETTER F (in other words, 0-9, A-F, a-f).</p>
3223:
3224: <p>When it comes to interpreting the number, interpret it as a
3225: hexadecimal number.</p>
3226:
3227: </dd>
3228:
3229:
3230: <dt>Anything else</dt>
3231:
3232: <dd>
3233:
3234: <p>Follow the steps below, but using the range of characters
3235: U+0030 DIGIT ZERO through to U+0039 DIGIT NINE (i.e. just
3236: 0-9).</p>
3237:
3238: <p>When it comes to interpreting the number, interpret it as a
3239: decimal number.</p>
3240:
3241: </dd>
3242:
3243: </dl><p>Consume as many characters as match the range of characters
3244: given above.</p>
3245:
3246: <p>If no characters match the range, then don't consume any
3247: characters (and unconsume the U+0023 NUMBER SIGN character and, if
3248: appropriate, the X character). This is a <a href="#parse-error">parse
3249: error</a>; nothing is returned.</p>
3250:
3251: <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
3252: that too. If it isn't, there is a <a href="#parse-error">parse
3253: error</a>.</p>
3254:
3255: <p>If one or more characters match the range, then take them all
3256: and interpret the string of characters as a number (either
3257: hexadecimal or decimal as appropriate).</p>
3258:
3259: <p>If that number is one of the numbers in the first column of the
3260: following table, then this is a <a href="#parse-error">parse error</a>. Find the
3261: row with that number in the first column, and return a character
3262: token for the Unicode character given in the second column of that
3263: row.</p>
3264:
3265: <table><thead><tr><th>Number </th><th colspan="2">Unicode character
3266: </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
3267: </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
3268: </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN ('€')
3269: </td></tr><tr><td>0x81 </td><td>U+0081 </td><td><control>
3270: </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK ('‚')
3271: </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK ('ƒ')
3272: </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK ('„')
3273: </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS ('…')
3274: </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER ('†')
3275: </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER ('‡')
3276: </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT ('ˆ')
3277: </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN ('‰')
3278: </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON ('Š')
3279: </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK ('‹')
3280: </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE ('Œ')
3281: </td></tr><tr><td>0x8D </td><td>U+008D </td><td><control>
3282: </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON ('Ž')
3283: </td></tr><tr><td>0x8F </td><td>U+008F </td><td><control>
3284: </td></tr><tr><td>0x90 </td><td>U+0090 </td><td><control>
3285: </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK ('‘')
3286: </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK ('’')
3287: </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK ('“')
3288: </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK ('”')
3289: </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET ('•')
3290: </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH ('–')
3291: </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH ('—')
3292: </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE ('˜')
3293: </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN ('™')
3294: </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON ('š')
3295: </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK ('›')
3296: </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE ('œ')
3297: </td></tr><tr><td>0x9D </td><td>U+009D </td><td><control>
3298: </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON ('ž')
3299: </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS ('Ÿ')
1.315 mike 3300: </td></tr></tbody></table><p>Otherwise, if the number is in the range 0xD800 to 0xDFFF<!--
3301: surrogates not allowed; see the comment in the "preprocessing the
3302: input stream" section for details --> or is greater than 0x10FFFF,
3303: then this is a <a href="#parse-error">parse error</a>. Return a U+FFFD
3304: REPLACEMENT CHARACTER.</p>
1.18 mike 3305:
3306: <p>Otherwise, return a character token for the Unicode character
1.1 mike 3307: whose code point is that number.
3308:
3309: <!-- this is the same as the equivalent list in the input stream
3310: section -->
3311: If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
3312: allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
3313: allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
1.315 mike 3314: 0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xFDD0 to
3315: 0xFDEF, or is one of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF,
3316: 0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE,
3317: 0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF,
3318: 0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE,
3319: 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF,
3320: 0x10FFFE, or 0x10FFFF, then this is a <a href="#parse-error">parse
3321: error</a>.</p>
1.1 mike 3322:
3323: </dd>
3324:
3325:
3326: <dt>Anything else</dt>
3327:
3328: <dd>
3329:
3330: <p>Consume the maximum number of characters possible, with the
3331: consumed characters matching one of the identifiers in the first
3332: column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
3333: <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
3334:
3335: <p>If no match can be made, then this is a <a href="#parse-error">parse
3336: error</a>. No characters are consumed, and nothing is
3337: returned.</p>
3338:
3339: <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>
3340:
3341: <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
3342: attribute</a>, and the last character matched is not a U+003B
3343: SEMICOLON (<code title="">;</code>), and the next character is in
3344: the range U+0030 DIGIT ZERO to U+0039 DIGIT NINE, U+0041 LATIN
3345: CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z, or U+0061 LATIN
3346: SMALL LETTER A to U+007A LATIN SMALL LETTER Z, then, for
3347: historical reasons, all the characters that were matched after the
3348: U+0026 AMPERSAND (&) must be unconsumed, and nothing is
3349: returned.</p>
3350:
3351: <p>Otherwise, return a character token for the character
3352: corresponding to the character reference name (as given by the
3353: second column of the <a href="named-character-references.html#named-character-references">named character references</a>
3354: table).</p>
3355:
3356: <div class="example">
3357:
3358: <p>If the markup contains <code title="">I'm &notit; I tell
3359: you</code>, the character reference is parsed as "not", as in,
3360: <code title="">I'm ¬it; I tell you</code>. But if the markup
3361: was <code title="">I'm &notin; I tell you</code>, the
3362: character reference would be parsed as "notin;", resulting in
3363: <code title="">I'm ∉ I tell you</code>.</p>
3364:
3365: </div>
3366:
3367: </dd>
3368:
1.266 mike 3369: </dl></div><div class="impl">
3370:
1.363 mike 3371: <!-- v2: One thing that this doesn't define is handling deeply
3372: nested documents. There are compatibility requirements around that:
3373: you can't throw away the elements altogether, consider Tux made only
3374: with opening <font> elements, one per character. Seems that the best
3375: thing to do is to close some formatting elements from the middle of
3376: the stack when you hit a limit, or something. -->
3377:
1.266 mike 3378: <h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4>
1.1 mike 3379:
3380: <p>The input to the tree construction stage is a sequence of tokens
3381: from the <a href="#tokenization">tokenization</a> stage. The tree construction
3382: stage is associated with a DOM <code>Document</code> object when a
3383: parser is created. The "output" of this stage consists of
3384: dynamically modifying or extending that document's DOM tree.</p>
3385:
3386: <p>This specification does not define when an interactive user agent
3387: has to render the <code>Document</code> so that it is available to
3388: the user, or when it has to begin accepting user input.</p>
3389:
3390: <p>As each token is emitted from the tokenizer, the user agent must
3391: process the token according to the rules given in the section
3392: corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
3393:
3394: <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
3395: character</dfn> into a node, if that node has a child immediately
3396: before where the character is to be inserted, and that child is a
3397: <code>Text</code> node, and that <code>Text</code> node was the last
3398: node that the parser inserted into the document, then the character
3399: must be appended to that <code>Text</code> node; otherwise, a new
3400: <code>Text</code> node whose data is just that character must be
3401: inserted in the appropriate place.</p>
3402:
3403: <div class="example">
3404:
3405: <p>Here are some sample inputs to the parser and the corresponding
3406: number of text nodes that they result in, assuming a user agent
3407: that executes scripts.</p>
3408:
3409: <table><thead><tr><th>Input </th><th>Number of text nodes
3410: </th></tr></thead><tbody><tr><td><pre>A<script>
3411: var script = document.getElementsByTagName('script')[0];
3412: document.body.removeChild(script);
3413: </script>B</pre>
3414: </td><td>Two adjacent text nodes in the document, containing "A" and "B".
3415: </td></tr><tr><td><pre>A<script>
3416: var text = document.createTextNode('B');
3417: document.body.appendChild(text);
3418: </script>C</pre>
3419: </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
3420: </td></tr><tr><td><pre>A<script>
3421: var text = document.getElementsByTagName('script')[0].firstChild;
3422: text.data = 'B';
3423: document.body.appendChild(text);
3424: </script>B</pre>
3425: </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
3426: </td></tr><tr><td><pre>A<table>B<tr>C</tr>C</table></pre>
3427: </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>.)
3428: </td></tr><tr><td><pre>A<table><tr> B</tr> B</table></pre>
3429: </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>.)
3430: </td></tr><tr><td><pre>A<table><tr> B</tr> </em>C</table></pre>
3431: </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.)
3432: </td></tr></tbody></table></div>
3433:
3434: <p id="mutation-during-parsing">DOM mutation events must not fire
3435: for changes caused by the UA parsing the document. (Conceptually,
3436: the parser is not mutating the DOM, it is constructing it.) This
1.159 mike 3437: 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 3438:
3439: <p class="note">Not all of the tag names mentioned below are
3440: conformant tag names in this specification; many are included to
3441: handle legacy content. They still form part of the algorithm that
3442: implementations are required to implement to claim conformance.</p>
3443:
3444: <p class="note">The algorithm described below places no limit on the
3445: depth of the DOM tree generated, or on the length of tag names,
3446: attribute names, attribute values, text nodes, etc. While
3447: implementors are encouraged to avoid arbitrary limits, it is
3448: recognized that <a href="infrastructure.html#hardwareLimitations">practical
3449: concerns</a> will likely force user agents to impose nesting
3450: depths.</p>
3451:
3452:
3453: <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5>
3454:
3455: <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
3456: element for the token">create an element for a token</dfn> in a
3457: particular namespace, the UA must create a node implementing the
3458: interface appropriate for the element type corresponding to the tag
3459: name of the token in the given namespace (as given in the
3460: specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
3461: element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
3462: defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
3463: the tag name being the name of that element, with the node being in
3464: the given namespace, and with the attributes on the node being those
3465: given in the given token.</p>
3466:
3467: <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
1.426 mike 3468: namespace</a> that is not defined in this specification (or
3469: <a href="infrastructure.html#other-applicable-specifications">other applicable specifications</a>) is
1.44 mike 3470: <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1 mike 3471: interface is not defined by that namespace's specification must use
3472: the interface <code>Element</code>.</p>
3473:
3474: <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
3475: created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
3476: invoked once the attributes are set. (This initializes the element's
3477: <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
3478: attributes.)</p>
3479:
3480: <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
3481: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
3482: for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
3483: append this node to the <a href="#current-node">current node</a>, and push it onto
3484: the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
3485: <a href="#current-node">current node</a>.</p>
3486:
3487: <p>The steps below may also require that the UA insert an HTML
3488: element in a particular place, in which case the UA must follow the
3489: same steps except that it must insert or append the new node in the
3490: location specified instead of appending it to the <a href="#current-node">current
3491: node</a>. (This happens in particular during the parsing of
3492: tables with invalid content.)</p>
3493:
3494: <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
3495: algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
3496: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
3497: 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
3498: <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
3499: created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
3500: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
3501: inserting it wherever it is to be inserted.</p>
3502:
3503: <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
3504: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
3505: for the token</a> in the given namespace, and then append this
3506: node to the <a href="#current-node">current node</a>, and push it onto the
3507: <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
3508: <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>
3509: whose value is not exactly the same as the element's namespace, that
3510: is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
3511: element has an <code title="">xmlns:xlink</code> attribute in the
3512: <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
3513: Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
3514:
3515: <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
3516: attributes</dfn> for a token, then, if the token has an attribute
3517: named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
3518:
3519: <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
3520: attributes</dfn> for a token, then, for each attribute on the token
3521: whose attribute name is one of the ones in the first column of the
3522: following table, change the attribute's name to the name given in
3523: the corresponding cell in the second column. (This fixes the case of
3524: SVG attributes that are not all lowercase.)</p>
3525:
3526: <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
3527: </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
3528: </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
3529: </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
3530: </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
3531: </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
3532: </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
3533: </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
3534: </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
3535: </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
3536: </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
3537: </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
3538: </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
3539: </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
3540: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
3541: </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
3542: </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
3543: </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
3544: </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
3545: </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
3546: </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
3547: </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
3548: </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
3549: </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
3550: </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
3551: </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
3552: </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
3553: </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
3554: </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
3555: </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
3556: </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
3557: </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
3558: </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
3559: </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
3560: </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
3561: </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
3562: </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
3563: </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
3564: </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
3565: </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
3566: </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
3567: </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
3568: </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
3569: </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
3570: </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
3571: </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
3572: </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
3573: </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
3574: </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
3575: </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
3576: </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
3577: </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
3578: </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
3579: </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
3580: </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
3581: </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
3582: </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
3583: </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
3584: </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
3585: </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
3586: </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
3587: </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
3588: </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
3589: </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
3590: foreign attributes</dfn> for a token, then, if any of the attributes
3591: on the token match the strings given in the first column of the
3592: following table, let the attribute be a namespaced attribute, with
3593: the prefix being the string given in the corresponding cell in the
3594: second column, the local name being the string given in the
3595: corresponding cell in the third column, and the namespace being the
3596: namespace given in the corresponding cell in the fourth
3597: column. (This fixes the use of namespaced attributes, in particular
3598: <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
3599: the <span>XML namespace</span></a>.)</p>
3600:
3601: <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
3602: </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>
3603: </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>
3604: </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>
3605: </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>
3606: </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>
3607: </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>
3608: </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>
3609: </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 -->
3610: </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>
3611: </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>
3612: </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>
3613: </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 3614: </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 3615: <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
3616: following steps. These algorithms are always invoked in response to
3617: a start tag token.</p>
3618:
3619: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
3620:
1.91 mike 3621: <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
3622: text element parsing algorithm</a>, switch the tokenizer's
3623: <a href="#content-model-flag">content model flag</a> to the RAWTEXT state; otherwise the
1.1 mike 3624: algorithm invoked was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing
3625: algorithm</a>, switch the tokenizer's <a href="#content-model-flag">content model
3626: flag</a> to the RCDATA state.</p></li>
3627:
3628: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
3629: <a href="#insertion-mode">insertion mode</a>.</p>
3630:
1.91 mike 3631: </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
3632: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 3633:
3634: </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>
3635:
3636: <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
3637: tags</dfn>, then, while the <a href="#current-node">current node</a> is a
1.422 mike 3638: <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 3639: <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
3640: <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
3641: <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
3642: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
3643: elements</a>.</p>
3644:
3645: <p>If a step requires the UA to generate implied end tags but lists
3646: an element to exclude from the process, then the UA must perform the
3647: above steps as if that element was not in the above list.</p>
3648:
3649:
3650: <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5>
3651:
3652: <p>Foster parenting happens when content is misnested in tables.</p>
3653:
3654: <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
3655: parent">foster parented</dfn>, the node <var title="">node</var>
3656: must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
3657:
3658: <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
3659: 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
3660: elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
3661: such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
3662: the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
3663: case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
3664: element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
1.159 mike 3665: <code><a href="semantics.html#the-html-element-0">html</a></code> element). Otherwise, if there is a
1.1 mike 3666: <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
3667: elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
3668: <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
3669: node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
3670: the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
3671: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
3672:
3673: <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
3674: 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
3675: elements</a>, then <var title="">node</var> must be inserted
3676: immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
3677: the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
3678: element</a></i>; otherwise, <var title="">node</var> must be
3679: <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
3680:
3681:
3682:
3683: <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>
3684:
3685: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
3686: mode: initial">initial</a>", tokens must be handled as follows:</p>
3687:
3688: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
3689: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3690: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3691: <dd>
3692: <p>Ignore the token.</p>
3693: </dd>
3694:
3695: <dt>A comment token</dt>
3696: <dd>
3697: <p>Append a <code>Comment</code> node to the <code>Document</code>
3698: object with the <code title="">data</code> attribute set to the
3699: data given in the comment token.</p>
3700: </dd>
3701:
3702: <dt>A DOCTYPE token</dt>
3703: <dd>
3704:
3705: <p>If the DOCTYPE token's name is not a
3706: <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
3707: missing, or the token's system identifier is neither missing nor a
3708: <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
3709: "<code>about:legacy-compat</code>", and none of the sets of
3710: conditions in the following list are matched, then there is a
3711: <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
3712: following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
3713: permitted DOCTYPE</dfn>.</p>
3714:
3715: <ul><!-- only things that trigger no-quirks mode and were valid in
3716: 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 3717: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3718: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD HTML 4.0//EN</code>", and the
3719: token's system identifier is either missing or the
3720: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
3721:
3722: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3723: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3724: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD HTML 4.01//EN</code>", and the
3725: token's system identifier is either missing or the
3726: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
3727:
3728: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3729: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3730: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD XHTML 1.0 Strict//EN</code>",
3731: and the token's system identifier is the
3732: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
3733:
3734: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3735: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3736: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD XHTML 1.1//EN</code>", and the
3737: token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
3738: string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
3739:
3740: </ul><p>Conformance checkers may, based on the values (including
3741: presence or lack thereof) of the DOCTYPE token's name, public
3742: identifier, or system identifier, switch to a conformance checking
3743: mode for another language (e.g. based on the DOCTYPE token a
3744: conformance checker could recognize that the document is an
1.183 mike 3745: HTML4-era document, and defer to an HTML4 conformance
1.1 mike 3746: checker.)</p>
3747:
3748: <p>Append a <code>DocumentType</code> node to the
3749: <code>Document</code> node, with the <code title="">name</code>
3750: attribute set to the name given in the DOCTYPE token, or the empty
3751: string if the name was missing; the <code title="">publicId</code>
3752: attribute set to the public identifier given in the DOCTYPE token,
3753: or the empty string if the public identifier was missing; the
3754: <code title="">systemId</code> attribute set to the system
3755: identifier given in the DOCTYPE token, or the empty string if the
3756: system identifier was missing; and the other attributes specific
3757: to <code>DocumentType</code> objects set to null and empty lists
3758: as appropriate. Associate the <code>DocumentType</code> node with
3759: the <code>Document</code> object so that it is returned as the
3760: value of the <code title="">doctype</code> attribute of the
3761: <code>Document</code> object.</p>
3762:
3763: <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
3764: one of the conditions in the following list, then set the
3765: <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
3766:
3767: <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
3768: <li> The name is set to anything other than "<code title="">HTML</code>". </li>
3769: <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
3770: <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
3771: <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
3772: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
3773: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
3774: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
3775: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
3776: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
3777: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
3778: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
3779: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
3780: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
3781: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
3782: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
3783: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
3784: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
3785: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
3786: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
3787: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
3788: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
3789: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
3790: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
3791: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
3792: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
3793: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
3794: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
3795: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
3796: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
3797: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
3798: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
3799: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
3800: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
3801: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
3802: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
3803: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
3804: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
3805: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
3806: <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
3807: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
3808: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
3809: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
3810: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
3811: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
3812: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
3813: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
3814: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
3815: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
3816: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
3817: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
3818: <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
3819: <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
3820: <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
3821: <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
3822: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
3823: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
3824: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
3825: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
3826: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
3827: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
3828: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
3829: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
3830: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
3831: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
3832: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
3833: <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
3834: <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
3835: <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
3836: <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
3837: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
3838: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
3839: <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
3840: <li> The public identifier is set to: "<code title="">HTML</code>" </li>
3841: <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
3842: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
3843: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
3844: </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
3845: in the following list, then set the <code>Document</code> to
3846: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
3847:
3848: <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
3849: <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
3850: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
3851: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
3852: </ul><p>The name, system identifier, and public identifier strings must
3853: be compared to the values given in the lists above in an
3854: <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
3855: whose value is the empty string is not considered missing for the
3856: purposes of the conditions above.</p>
3857:
3858: <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>
3859:
3860: </dd>
3861:
3862: <dt>Anything else</dt>
3863: <dd>
3864:
3865: <p><a href="#parse-error">Parse error</a>.</p>
3866:
3867: <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
3868:
3869: <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
3870: reprocess the current token.</p>
3871:
3872: </dd>
3873:
3874: </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>
3875:
3876: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
3877: mode: before html">before html</a>", tokens must be handled as follows:</p>
3878:
3879: <dl class="switch"><dt>A DOCTYPE token</dt>
3880: <dd>
3881: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3882: </dd>
3883:
3884: <dt>A comment token</dt>
3885: <dd>
3886: <p>Append a <code>Comment</code> node to the <code>Document</code>
3887: object with the <code title="">data</code> attribute set to the
3888: data given in the comment token.</p>
3889: </dd>
3890:
3891: <dt>A character token that is one of U+0009 CHARACTER
3892: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3893: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3894: <dd>
3895: <p>Ignore the token.</p>
3896: </dd>
3897:
3898: <dt>A start tag whose tag name is "html"</dt>
3899: <dd>
3900:
3901: <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
3902: namespace</a>. Append it to the <code>Document</code>
3903: object. Put this element in the <a href="#stack-of-open-elements">stack of open
3904: elements</a>.</p>
3905:
3906: <p id="parser-appcache">If the <code>Document</code> is being
3907: loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
3908: <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
3909: has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
3910: then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
3911: attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
3912: 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 3913: algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
3914: any <a href="infrastructure.html#url-fragment" title="url-fragment"><fragment></a> component
3915: removed; otherwise, if there is no such attribute or resolving it
3916: fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
3917: cache selection algorithm</a> with no manifest. The algorithm
3918: must be passed the <code>Document</code> object.</p>
1.1 mike 3919:
3920: <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>
3921:
3922: </dd>
3923:
1.334 mike 3924: <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
3925: <dd>
3926: <p>Act as described in the "anything else" entry below.</p>
3927: </dd>
3928:
3929: <dt>Any other end tag</dt>
3930: <dd>
3931: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3932: </dd>
3933:
1.1 mike 3934: <dt>Anything else</dt>
3935: <dd>
3936:
1.159 mike 3937: <p>Create an <code><a href="semantics.html#the-html-element-0">html</a></code> element. Append it to the
1.1 mike 3938: <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
3939: of open elements</a>.</p>
3940:
3941: <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
3942: context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
3943: algorithm</a> with no manifest, passing it the
3944: <code>Document</code> object.</p>
3945:
3946: <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
3947: reprocess the current token.</p>
3948:
3949: </dd>
3950:
3951: </dl><p>The root element can end up being removed from the
3952: <code>Document</code> object, e.g. by scripts; nothing in particular
3953: happens in such cases, content continues being appended to the nodes
3954: as described in the next section.</p>
3955:
3956:
3957: <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>
3958:
3959: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
3960: mode: before head">before head</a>", tokens must be handled as follows:</p>
3961:
3962: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
3963: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3964: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3965: <dd>
3966: <p>Ignore the token.</p> <!-- :-( -->
3967: </dd>
3968:
3969: <dt>A comment token</dt>
3970: <dd>
3971: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
3972: node</a> with the <code title="">data</code> attribute set to
3973: the data given in the comment token.</p>
3974: </dd>
3975:
3976: <dt>A DOCTYPE token</dt>
3977: <dd>
3978: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3979: </dd>
3980:
3981: <dt>A start tag whose tag name is "html"</dt>
3982: <dd>
3983: <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
3984: mode</a>.</p>
3985: </dd>
3986:
3987: <dt>A start tag whose tag name is "head"</dt>
3988: <dd>
3989:
3990: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
3991:
3992: <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
1.159 mike 3993: to the newly created <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 3994:
3995: <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>
3996:
3997: </dd>
3998:
3999: <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
4000: <dd>
4001:
4002: <p>Act as if a start tag token with the tag name "head" and no
4003: attributes had been seen, then reprocess the current token.</p>
4004:
4005: </dd>
4006:
4007: <dt>Any other end tag</dt>
4008: <dd>
4009:
4010: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4011:
4012: </dd>
4013:
4014: <dt>Anything else</dt>
4015: <dd>
4016:
4017: <p>Act as if a start tag token with the tag name "head" and no
4018: attributes had been seen, then reprocess the current
4019: token.</p>
4020:
4021: </dd>
4022:
4023: </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>
4024:
4025: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
4026: mode: in head">in head</a>", tokens must be handled as follows:</p>
4027:
4028: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4029: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4030: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4031: <dd>
4032: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
4033: the <a href="#current-node">current node</a>.</p>
4034: </dd>
4035:
4036: <dt>A comment token</dt>
4037: <dd>
4038: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4039: node</a> with the <code title="">data</code> attribute set to
4040: the data given in the comment token.</p>
4041: </dd>
4042:
4043: <dt>A DOCTYPE token</dt>
4044: <dd>
4045: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4046: </dd>
4047:
4048: <dt>A start tag whose tag name is "html"</dt>
4049: <dd>
4050: <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
4051: mode</a>.</p>
4052: </dd>
4053:
4054: <dt>A start tag whose tag name is one of: "base", "command",
4055: "link"</dt>
4056: <dd>
4057:
4058: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4059: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4060: elements</a>.</p>
4061:
4062: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4063: token's <i>self-closing flag</i></a>, if it is set.</p>
4064:
4065: </dd>
4066:
4067: <dt>A start tag whose tag name is "meta"</dt>
4068: <dd>
4069:
4070: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4071: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4072: elements</a>.</p>
4073:
4074: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4075: token's <i>self-closing flag</i></a>, if it is set.</p>
4076:
4077: <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
4078: value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
4079: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
4080: encoding</a> to the encoding given by the value of the
4081: <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
4082:
4083: <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
4084: applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
4085: Content-Type</a> to its value returns a supported encoding
4086: <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
4087: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
4088: encoding</a> to the encoding <var title="">encoding</var>.</p>
4089:
4090: </dd>
4091:
4092: <dt>A start tag whose tag name is "title"</dt>
4093: <dd>
4094: <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
4095: </dd>
4096:
4097: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
4098: <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
4099: <dd>
1.91 mike 4100: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 4101: </dd>
4102:
4103: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
4104: <dd>
4105:
4106: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4107:
4108: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
4109: noscript</a>".</p>
4110:
4111: </dd>
4112:
4113: <dt id="scriptTag">A start tag whose tag name is "script"</dt>
4114: <dd>
4115:
4116: <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
4117: <a href="#html-namespace-0">HTML namespace</a>.</p></li>
4118:
4119: <li>
4120:
4121: <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
4122:
4123: <p class="note">This ensures that, if the script is external,
1.159 mike 4124: any <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>
1.1 mike 4125: calls in the script will execute in-line, instead of blowing the
4126: document away, as would happen in most other cases. It also
4127: prevents the script from executing until the end tag is
4128: seen.</p>
4129:
4130: </li>
4131:
4132: <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
4133: fragment parsing algorithm</a>, then mark the
4134: <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
4135: executed"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
4136:
4137: <li><p>Append the new element to the <a href="#current-node">current node</a>
4138: and push it onto the <a href="#stack-of-open-elements">stack of open
4139: elements</a>.</p></li>
4140:
4141: <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
1.91 mike 4142: the RAWTEXT state.</p></li>
1.1 mike 4143:
4144: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
4145: <a href="#insertion-mode">insertion mode</a>.</p>
4146:
1.91 mike 4147: </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
4148: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 4149:
4150: </ol></dd>
4151:
4152: <dt>An end tag whose tag name is "head"</dt>
4153: <dd>
4154:
4155: <p>Pop the <a href="#current-node">current node</a> (which will be the
1.159 mike 4156: <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 4157: elements</a>.</p>
4158:
4159: <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>
4160:
4161: </dd>
4162:
4163: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
4164: <dd>
4165: <p>Act as described in the "anything else" entry below.</p>
4166: </dd>
4167:
4168: <dt>A start tag whose tag name is "head"</dt>
4169: <dt>Any other end tag</dt>
4170: <dd>
4171: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4172: </dd>
4173:
4174: <dt>Anything else</dt>
4175: <dd>
4176:
4177: <!-- can't get here with an EOF and a fragment case -->
4178:
4179: <p>Act as if an end tag token with the tag name "head" had
4180: been seen, and reprocess the current token.</p>
4181:
4182: </dd>
4183:
4184: </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>
4185:
4186: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
4187: mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
4188:
4189: <dl class="switch"><dt>A DOCTYPE token</dt>
4190: <dd>
4191: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4192: </dd>
4193:
4194: <dt>A start tag whose tag name is "html"</dt>
4195: <dd>
4196: <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
4197: mode</a>.</p>
4198: </dd>
4199:
4200: <dt>An end tag whose tag name is "noscript"</dt>
4201: <dd>
4202:
4203: <p>Pop the <a href="#current-node">current node</a> (which will be a
4204: <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
4205: elements</a>; the new <a href="#current-node">current node</a> will be a
1.159 mike 4206: <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 4207:
4208: <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>
4209:
4210: </dd>
4211:
4212: <dt>A character token that is one of U+0009 CHARACTER
4213: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4214: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4215: <dt>A comment token</dt>
4216: <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
4217: <dd>
4218: <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
4219: mode</a>.</p>
4220: </dd>
4221:
4222: <dt>An end tag whose tag name is "br"</dt>
4223: <dd>
4224: <p>Act as described in the "anything else" entry below.</p>
4225: </dd>
4226:
4227: <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
4228: <dt>Any other end tag</dt>
4229: <dd>
4230: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4231: </dd>
4232:
4233: <dt>Anything else</dt>
4234: <dd>
4235:
4236: <!-- can't get here with an EOF and a fragment case -->
4237:
4238: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
4239: name "noscript" had been seen and reprocess the current
4240: token.</p>
4241:
4242: </dd>
4243:
4244: </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>
4245:
4246: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
4247: mode: after head">after head</a>", tokens must be handled as follows:</p>
4248:
4249: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4250: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4251: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4252: <dd>
4253: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
4254: the <a href="#current-node">current node</a>.</p>
4255: </dd>
4256:
4257: <dt>A comment token</dt>
4258: <dd>
4259: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4260: node</a> with the <code title="">data</code> attribute set to
4261: the data given in the comment token.</p>
4262: </dd>
4263:
4264: <dt>A DOCTYPE token</dt>
4265: <dd>
4266: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4267: </dd>
4268:
4269: <dt>A start tag whose tag name is "html"</dt>
4270: <dd>
4271: <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
4272: mode</a>.</p>
4273: </dd>
4274:
4275: <dt>A start tag whose tag name is "body"</dt>
4276: <dd>
4277:
4278: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4279:
4280: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4281:
4282: <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>
4283:
4284: </dd>
4285:
4286: <dt>A start tag whose tag name is "frameset"</dt>
4287: <dd>
4288:
4289: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4290:
4291: <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>
4292:
4293: </dd>
4294:
4295: <dt>A start tag token whose tag name is one of: "base", "link",
4296: "meta", "noframes", "script", "style", "title"</dt>
4297: <dd>
4298:
4299: <p><a href="#parse-error">Parse error</a>.</p>
4300:
4301: <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
4302: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
4303:
4304: <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
4305: mode</a>.</p>
4306:
4307: <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
4308: of open elements</a>.</p>
4309:
4310: <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
4311: pointer</a> cannot be null at this point.</p>
4312:
4313: </dd>
4314:
4315: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
4316: <dd>
4317: <p>Act as described in the "anything else" entry below.</p>
4318: </dd>
4319:
4320: <dt>A start tag whose tag name is "head"</dt>
4321: <dt>Any other end tag</dt>
4322: <dd>
4323: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4324: </dd>
4325:
4326: <dt>Anything else</dt>
4327: <dd>
4328: <p>Act as if a start tag token with the tag name "body" and no
4329: attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
4330: flag</a> back to "ok", and then reprocess the current
4331: token.</p>
4332: </dd>
4333:
4334: </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>
4335:
4336: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
4337: mode: in body">in body</a>", tokens must be handled as follows:</p>
4338:
4339: <dl class="switch"><dt>A character token</dt>
4340: <dd>
4341:
4342: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4343: any.</p>
4344:
4345: <p><a href="#insert-a-character" title="insert a character">Insert the token's
4346: character</a> into the <a href="#current-node">current node</a>.</p>
4347:
4348: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
4349: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
4350: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
4351: flag</a> to "not ok".</p>
4352:
4353: </dd>
4354:
4355: <dt>A comment token</dt>
4356: <dd>
4357: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4358: node</a> with the <code title="">data</code> attribute set to
4359: the data given in the comment token.</p>
4360: </dd>
4361:
4362: <dt>A DOCTYPE token</dt>
4363: <dd>
4364: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4365: </dd>
4366:
4367: <dt>A start tag whose tag name is "html"</dt>
4368: <dd>
4369: <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
4370: check to see if the attribute is already present on the top
4371: element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
4372: add the attribute and its corresponding value to that element.</p>
4373: </dd>
4374:
4375: <dt>A start tag token whose tag name is one of: "base", "command",
4376: "link", "meta", "noframes", "script", "style", "title"</dt>
4377: <dd>
4378: <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
4379: mode</a>.</p>
4380: </dd>
4381:
4382: <dt>A start tag whose tag name is "body"</dt>
4383: <dd>
4384:
4385: <p><a href="#parse-error">Parse error</a>.</p>
4386:
4387: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159 mike 4388: elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1 mike 4389: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
4390: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
4391:
4392: <p>Otherwise, for each attribute on the token, check to see if
1.159 mike 4393: the attribute is already present on the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 4394: element (the second element) on the <a href="#stack-of-open-elements">stack of open
4395: elements</a>. If it is not, add the attribute and its
4396: corresponding value to that element.</p>
4397:
4398: </dd>
4399:
4400: <dt>A start tag whose tag name is "frameset"</dt>
4401: <dd>
4402:
4403: <p><a href="#parse-error">Parse error</a>.</p>
4404:
4405: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159 mike 4406: elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1 mike 4407: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
4408: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
4409:
4410: <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
4411: the token.</p>
4412:
4413: <p>Otherwise, run the following steps:</p>
4414:
4415: <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
4416: elements</a> from its parent node, if it has one.</p></li>
4417:
4418: <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
4419: open elements</a>, from the <a href="#current-node">current node</a> up to,
1.159 mike 4420: but not including, the root <code><a href="semantics.html#the-html-element-0">html</a></code> element.</p>
1.1 mike 4421:
4422: </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
4423: token.</p></li>
4424:
4425: <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>
4426:
4427: </li></ol></dd>
4428:
4429: <dt>An end-of-file token</dt>
4430: <dd>
4431:
4432: <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
1.422 mike 4433: 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>
4434: 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 4435: <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
4436: <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
4437: <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 4438: <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 4439: this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
1.422 mike 4440: fragment cases) -->
1.1 mike 4441:
4442: <p><a href="#stop-parsing">Stop parsing</a>.</p>
4443:
4444: </dd>
4445:
4446: <dt>An end tag whose tag name is "body"</dt>
4447: <dd>
4448:
4449: <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
4450: in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
4451: token.</p>
4452:
4453: <!-- if we get here, the insertion mode here is forcibly "in
4454: body". -->
4455:
4456: <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
1.422 mike 4457: elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
1.1 mike 4458: <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
4459: <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
4460: <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
4461: <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
4462: <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
4463: <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 4464: <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
4465: <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 4466: error</a>.</p> <!-- (some of those are fragment cases, e.g. for
4467: <tbody> you'd have hit the first paragraph since the <body>
1.422 mike 4468: wouldn't be in scope, unless it was a fragment case) -->
1.1 mike 4469:
4470: <!-- If we ever change the frameset-ok flag to an insertion mode,
4471: then we'd have to somehow keep track of its state when we switch
4472: to after-body. -->
4473:
4474: <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>
4475:
4476: </dd>
4477:
4478: <dt>An end tag whose tag name is "html"</dt>
4479: <dd>
4480:
4481: <p>Act as if an end tag with tag name "body" had been seen,
4482: then, if that token wasn't ignored, reprocess the current
4483: token.</p>
4484:
4485: <p class="note">The fake end tag token here can only be
4486: ignored in the <a href="#fragment-case">fragment case</a>.</p>
4487:
4488: </dd>
4489:
4490: <!-- start tags for non-phrasing flow content elements -->
4491:
4492: <!-- the normal ones -->
4493: <dt>A start tag whose tag name is one of: "address", "article",
1.86 mike 4494: "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305 mike 4495: "details", "dir", "div", "dl", "fieldset", "figure", "footer",
4496: "header", "hgroup", "menu", "nav", "ol", "p", "section", "ul"</dt>
1.1 mike 4497: <dd>
4498:
4499: <!-- As of May 2008 this doesn't match any browser exactly, but is
4500: as close to what IE does as I can get without doing the non-tree
4501: DOM nonsense, and thus should actually afford better compatibility
4502: when implemented by the other browsers. -->
4503:
4504: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4505: an element in scope">has a <code>p</code> element in
4506: scope</a>, then act as if an end tag with the tag name
4507: "p" had been seen.</p>
4508:
4509: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4510:
4511: </dd>
4512:
4513: <!-- as normal, but close h1-h6 if it's the current node -->
4514: <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
4515: "h5", "h6"</dt>
4516: <dd>
4517:
4518: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4519: an element in scope">has a <code>p</code> element in
4520: scope</a>, then act as if an end tag with the tag name
4521: "p" had been seen.</p>
4522:
4523: <p>If the <a href="#current-node">current node</a> is an element whose tag name
4524: is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
4525: <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
4526: the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
4527: <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
4528:
4529: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4530:
4531: </dd>
4532:
4533: <!-- as normal, but drops leading newline -->
4534: <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
4535: <dd>
4536:
4537: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4538: an element in scope">has a <code>p</code> element in
4539: scope</a>, then act as if an end tag with the tag name
4540: "p" had been seen.</p>
4541:
4542: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4543:
4544: <p>If the next token is a U+000A LINE FEED (LF) character
4545: token, then ignore that token and move on to the next
4546: one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
4547: ignored as an authoring convenience.)</p>
4548:
4549: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4550:
4551: </dd>
4552:
4553: <!-- as normal, but interacts with the form element pointer -->
4554: <dt>A start tag whose tag name is "form"</dt>
4555: <dd>
4556:
4557: <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
4558: pointer</a> is not null, then this is a <a href="#parse-error">parse
4559: error</a>; ignore the token.</p>
4560:
4561: <p>Otherwise:</p>
4562:
4563: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4564: an element in scope">has a <code>p</code> element in
4565: scope</a>, then act as if an end tag with the tag name
4566: "p" had been seen.</p>
4567:
4568: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
4569: <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
4570: point to the element created.</p>
4571:
4572: </dd>
4573:
4574: <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
4575: <dt>A start tag whose tag name is "li"</dt>
4576: <dd>
4577:
4578: <p>Run the following algorithm:</p>
4579:
4580: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
4581:
4582: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
4583: node</a> (the bottommost node of the stack).</p></li>
4584:
4585: <li><p>If <var title="">node</var> is an <code><a href="semantics.html#the-li-element">li</a></code> element,
4586: then act as if an end tag with the tag name "li" had
4587: been seen, then jump to the last step.</p></li>
4588:
4589: <li><p><i>Loop</i>: If <var title="">node</var> is not in the
4590: <a href="#formatting">formatting</a> category, and is not in the
4591: <a href="#phrasing">phrasing</a> category, and is not an
1.306 mike 4592: <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 4593: element, then jump to the last step.</p></li> <!-- an element
4594: <foo> is in this list if the following markup:
4595:
4596: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
4597:
4598: ...results in the second <li> not being (in any way) a descendant
4599: of the first <li>, or if <foo> is a formatting element that gets
4600: reopened later. -->
4601:
4602: <li><p>Otherwise, set <var title="">node</var> to the previous
4603: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
4604: the step labeled <i>loop</i>.</p></li>
4605:
4606: <li>
4607:
4608: <p>This is the last step.</p>
4609:
4610: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4611: an element in scope">has a <code>p</code> element in
4612: scope</a>, then act as if an end tag with the tag name
4613: "p" had been seen.</p>
4614:
4615: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
4616: token.</p>
4617:
4618: </li>
4619:
4620: </ol></dd>
4621:
4622: <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases -->
1.422 mike 4623: <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
1.1 mike 4624: <dd>
4625:
4626: <p>Run the following algorithm:</p>
4627:
4628: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
4629:
4630: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
4631: node</a> (the bottommost node of the stack).</p></li>
4632:
4633: <li><p><i>Loop</i>: If <var title="">node</var> is a
1.422 mike 4634: <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
4635: tag with the same tag name as <var title="">node</var> had been
4636: seen, then jump to the last step.</p></li>
1.1 mike 4637:
4638: <li><p>If <var title="">node</var> is not in the
4639: <a href="#formatting">formatting</a> category, and is not in the
4640: <a href="#phrasing">phrasing</a> category, and is not an
1.306 mike 4641: <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 4642: element, then jump to the last step.</p></li> <!-- an element
4643: <foo> is in this list if the following markup:
4644:
4645: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
4646:
4647: ...results in the second <dt> not being (in any way) a descendant
4648: of the first <dt>, or if <foo> is a formatting element that gets
4649: reopened later. -->
4650:
4651: <li><p>Otherwise, set <var title="">node</var> to the previous
4652: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
4653: the step labeled <i>loop</i>.</p></li>
4654:
4655: <li>
4656:
4657: <p>This is the last step.</p>
4658:
4659: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4660: an element in scope">has a <code>p</code> element in
4661: scope</a>, then act as if an end tag with the tag name
4662: "p" had been seen.</p>
4663:
4664: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
4665: token.</p>
4666:
4667: </li>
4668:
4669: </ol></dd>
4670:
4671: <!-- same as normal, but effectively ends parsing -->
4672: <dt>A start tag whose tag name is "plaintext"</dt>
4673: <dd>
4674:
4675: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4676: an element in scope">has a <code>p</code> element in
4677: scope</a>, then act as if an end tag with the tag name
4678: "p" had been seen.</p>
4679:
4680: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4681:
4682: <p>Switch the <a href="#content-model-flag">content model flag</a> to the PLAINTEXT
4683: state.</p>
4684:
4685: <p class="note">Once a start tag with the tag name "plaintext"
4686: has been seen, that will be the last token ever seen other
4687: than character tokens (and the end-of-file token), because
4688: there is no way to switch the <a href="#content-model-flag">content model flag</a>
4689: out of the PLAINTEXT state.</p>
4690:
4691: </dd>
4692:
4693: <!-- end tags for non-phrasing flow content elements -->
4694:
4695: <!-- the normal ones -->
4696: <dt>An end tag whose tag name is one of: "address", "article",
1.86 mike 4697: "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305 mike 4698: "details", "dir", "div", "dl", "fieldset", "figure", "footer",
4699: "header", "hgroup", "listing", "menu", "nav", "ol", "pre",
4700: "section", "ul"</dt>
1.1 mike 4701: <dd>
4702:
4703: <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>
4704: with the same tag name as that of the token, then this is a
4705: <a href="#parse-error">parse error</a>; ignore the token.</p>
4706:
4707: <p>Otherwise, run these steps:</p>
4708:
4709: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4710:
4711: <li><p>If the <a href="#current-node">current node</a> is not an element with
4712: the same tag name as that of the token, then this is a
4713: <a href="#parse-error">parse error</a>.</p></li>
4714:
4715: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4716: until an element with the same tag name as the token has been
4717: popped from the stack.</p></li>
4718:
4719: </ol></dd>
4720:
4721: <!-- removes the form element pointer instead of the matching node -->
4722: <dt>An end tag whose tag name is "form"</dt>
4723: <dd>
4724:
4725: <p>Let <var title="">node</var> be the element that the
4726: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
4727: to.</p>
4728:
4729: <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
4730: to null.</p>
4731:
4732: <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
4733: elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
4734: scope">have <var title="">node</var> in scope</a>, then this is
4735: a <a href="#parse-error">parse error</a>; ignore the token.</p>
4736:
4737: <p>Otherwise, run these steps:</p>
4738:
4739: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4740:
4741: <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
4742: error</a>.</p></li>
4743:
4744: <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
4745: open elements</a>.</p></li>
4746:
4747: </ol></dd>
4748:
4749: <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
4750: <dt>An end tag whose tag name is "p"</dt>
4751: <dd>
4752:
4753: <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>
4754: with the same tag name as that of the token, then this is a
4755: <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
4756: "p" had been seen, then reprocess the current token.</p>
4757:
4758: <p>Otherwise, run these steps:</p>
4759:
4760: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
4761: for elements with the same tag name as the token.</p></li>
4762:
4763: <li><p>If the <a href="#current-node">current node</a> is not an element with
4764: the same tag name as that of the token, then this is a
4765: <a href="#parse-error">parse error</a>.</p></li>
4766:
4767: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4768: until an element with the same tag name as the token has been
4769: popped from the stack.</p></li>
4770:
4771: </ol></dd>
4772:
1.234 mike 4773: <!-- as normal, but needs care as the elements have optional tags, and are further scoped by <ol>/<ul> -->
4774: <dt>An end tag whose tag name is "li"</dt>
4775: <dd>
4776:
4777: <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
4778: item scope</a> with the same tag name as that of the token,
4779: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
4780:
4781: <p>Otherwise, run these steps:</p>
4782:
4783: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
4784: for elements with the same tag name as the token.</p></li>
4785:
4786: <li><p>If the <a href="#current-node">current node</a> is not an element with
4787: the same tag name as that of the token, then this is a
4788: <a href="#parse-error">parse error</a>.</p></li>
4789:
4790: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4791: until an element with the same tag name as the token has been
4792: popped from the stack.</p></li>
4793:
4794: </ol></dd>
4795:
1.1 mike 4796: <!-- as normal, but needs care as the elements have optional tags -->
1.422 mike 4797: <dt>An end tag whose tag name is one of: "dd", "dt"</dt>
1.1 mike 4798: <dd>
4799:
4800: <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>
4801: with the same tag name as that of the token, then this is a
4802: <a href="#parse-error">parse error</a>; ignore the token.</p>
4803:
4804: <p>Otherwise, run these steps:</p>
4805:
4806: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
4807: for elements with the same tag name as the token.</p></li>
4808:
4809: <li><p>If the <a href="#current-node">current node</a> is not an element with
4810: the same tag name as that of the token, then this is a
4811: <a href="#parse-error">parse error</a>.</p></li>
4812:
4813: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4814: until an element with the same tag name as the token has been
4815: popped from the stack.</p></li>
4816:
4817: </ol></dd>
4818:
4819: <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
4820: <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
4821: <dd>
4822:
4823: <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>
4824: whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
4825: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
4826:
4827: <p>Otherwise, run these steps:</p>
4828:
4829: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4830:
4831: <li><p>If the <a href="#current-node">current node</a> is not an element with
4832: the same tag name as that of the token, then this is a
4833: <a href="#parse-error">parse error</a>.</p></li>
4834:
4835: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4836: until an element whose tag name is one of "h1", "h2", "h3", "h4",
4837: "h5", or "h6" has been popped from the stack.</p></li>
4838:
4839: </ol></dd>
4840:
4841: <dt>An end tag whose tag name is "sarcasm"</dt>
4842: <dd>
4843: <p>Take a deep breath, then act as described in the "any other end
4844: tag" entry below.</p>
4845: </dd>
4846:
4847: <!-- ADOPTION AGENCY ELEMENTS
4848: Mozilla-only: bdo blink del ins sub sup q
4849: Safari-only: code dfn kbd nobr samp var wbr
4850: Both: a b big em font i s small strike strong tt u -->
4851:
4852: <dt>A start tag whose tag name is "a"</dt>
4853: <dd>
4854:
4855: <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
4856: contains an element whose tag name is "a" between the end of
4857: the list and the last marker on the list (or the start of the
4858: list if there is no marker on the list), then this is a
4859: <a href="#parse-error">parse error</a>; act as if an end tag with the tag
4860: name "a" had been seen, then remove that element from the
4861: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
4862: <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
4863: already remove it (it might not have if the element is not
4864: <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
4865: scope</a>).</p>
4866:
4867: <p class="example">In the non-conforming stream
4868: <code><a href="a">a<table><a href="b">b</table>x</code>,
4869: the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
4870: the second one, and the "x" character would be inside a link
4871: to "b", not to "a". This is despite the fact that the outer
4872: <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
4873: regular <code></a></code> end tag at the start of the table
4874: wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
4875:
4876: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4877: any.</p>
4878:
4879: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
4880: element to the <a href="#list-of-active-formatting-elements">list of active formatting
4881: elements</a>.</p>
4882:
4883: </dd>
4884:
4885: <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
4886: "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
4887: <dd>
4888:
4889: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4890: any.</p>
4891:
4892: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
4893: element to the <a href="#list-of-active-formatting-elements">list of active formatting
4894: elements</a>.</p>
4895:
4896: </dd>
4897:
4898: <dt>A start tag whose tag name is "nobr"</dt>
4899: <dd>
4900:
4901: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4902: any.</p>
4903:
4904: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
4905: element in scope">has a <code>nobr</code> element in scope</a>,
4906: then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
4907: the tag name "nobr" had been seen, then once again
4908: <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
4909: any.</p>
4910:
4911: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
4912: element to the <a href="#list-of-active-formatting-elements">list of active formatting
4913: elements</a>.</p>
4914:
4915: </dd>
4916:
4917: <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
4918: "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
4919: "strike", "strong", "tt", "u"</dt>
4920: <dd>
4921:
4922: <p>Follow these steps:</p>
4923:
4924: <ol><li>
4925:
4926: <p>Let the <var title="">formatting element</var> be the
4927: last element in the <a href="#list-of-active-formatting-elements">list of active formatting
4928: elements</a> that:</p>
4929:
4930: <ul><li>is between the end of the list and the last scope
4931: marker in the list, if any, or the start of the list
4932: otherwise, and</li>
4933:
4934: <li>has the same tag name as the token.</li>
4935:
4936: </ul><p>If there is no such node, or, if that node is also in the
4937: <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
4938: <a href="#parse-error">parse error</a>; ignore the token, and abort these
4939: steps.</p>
4940:
4941: <p>Otherwise, if there is such a node, but that node is not
4942: in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
4943: <a href="#parse-error">parse error</a>; remove the element from the list,
4944: and abort these steps.</p>
4945:
4946: <p>Otherwise, there is a <var title="">formatting
4947: element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
4948: open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
4949: element in scope">in scope</a>. If the element is not the
4950: <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
4951: error</a>. In any case, proceed with the algorithm as
4952: written in the following steps.</p>
4953:
4954: </li>
4955:
4956: <li><p>Let the <var title="">furthest block</var> be the
4957: topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
4958: is lower in the stack than the <var title="">formatting
4959: element</var>, and is not an element in the
4960: <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
4961: categories. There might not be one.</p></li>
4962:
4963: <li><p>If there is no <var title="">furthest block</var>,
4964: then the UA must skip the subsequent steps and instead just
4965: pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
4966: elements</a>, from the <a href="#current-node">current node</a> up to and
4967: including the <var title="">formatting element</var>, and
4968: remove the <var title="">formatting element</var> from the
4969: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
4970:
4971: <li><p>Let the <var title="">common ancestor</var> be the element
4972: immediately above the <var title="">formatting element</var> in the
4973: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
4974:
4975: <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
4976: formatting elements</a> relative to the elements on either
4977: side of it in the list.</p></li>
4978:
4979: <li>
4980:
4981: <p>Let <var title="">node</var> and <var title="">last node</var> be the
4982: <var title="">furthest block</var>. Follow these steps:</p>
4983:
4984: <ol><li>Let <var title="">node</var> be the element immediately
4985: above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
1.436 mike 4986: elements</a>, or if <var title="">node</var> is no longer in
4987: the <a href="#stack-of-open-elements">stack of open elements</a> (e.g. because it got
4988: removed by the next step), the element that was immediately
4989: above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
4990: elements</a> before <var title="">node</var> was
4991: removed.</li>
1.1 mike 4992:
4993: <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
4994: active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
4995: elements</a> and then go back to step 1.</li>
4996:
4997: <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
4998: in the overall algorithm.</li>
4999:
5000: <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
5001: bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
5002: elements</a>.</li>
5003:
5004: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
5005: element <var title="">node</var> was created, replace the entry
5006: for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
5007: formatting elements</a> with an entry for the new element,
5008: replace the entry for <var title="">node</var> in the
5009: <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
5010: element, and let <var title="">node</var> be the new
5011: element.</li>
5012:
5013: <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
5014: parent node if any.</li>
5015:
5016: <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
5017:
5018: <li>Return to step 1 of this inner set of steps.</li>
5019:
5020: </ol></li>
5021:
5022: <li>
5023:
5024: <p>If the <var title="">common ancestor</var> node is a
5025: <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>,
5026: <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,
5027: <a href="#foster-parent">foster parent</a> whatever <var title="">last
5028: node</var> ended up being in the previous step, first removing
5029: it from its previous parent node if any.</p>
5030:
5031: <p>Otherwise, append whatever <var title="">last node</var>
5032: ended up being in the previous step to the <var title="">common
5033: ancestor</var> node, first removing it from its previous parent
5034: node if any.</p>
5035:
5036: </li>
5037:
5038: <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
5039: <var title="">formatting element</var> was created.</p></li>
5040:
5041: <li><p>Take all of the child nodes of the <var title="">furthest
5042: block</var> and append them to the element created in the last
5043: step.</p></li>
5044:
5045: <li><p>Append that new element to the <var title="">furthest
5046: block</var>.</p></li>
5047:
5048: <li><p>Remove the <var title="">formatting element</var> from the
5049: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
5050: new element into the <a href="#list-of-active-formatting-elements">list of active formatting
5051: elements</a> at the position of the aforementioned
5052: bookmark.</p></li>
5053:
5054: <li><p>Remove the <var title="">formatting element</var> from the
5055: <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
5056: into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
5057: the position of the <var title="">furthest block</var> in that
5058: stack.</p></li>
5059:
5060: <li><p>Jump back to step 1 in this series of steps.</p></li>
5061:
1.334 mike 5062: </ol><p class="note">Because of the way this algorithm causes elements
1.304 mike 5063: to change parents, it has been dubbed the "adoption agency
5064: algorithm" (in contrast with other possible algorithms for dealing
5065: with misnested content, which included the "incest algorithm", the
1.1 mike 5066: "secret affair algorithm", and the "Heisenberg algorithm").</p>
5067:
5068: </dd>
5069:
5070: <dt>A start tag whose tag name is "button"</dt>
5071: <dd>
5072:
5073: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5074: an element in scope">has a <code>button</code> element in
5075: scope</a>, then this is a <a href="#parse-error">parse error</a>;
5076: act as if an end tag with the tag name "button" had been seen,
5077: then reprocess the token.</p>
5078:
5079: <p>Otherwise:</p>
5080:
5081: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5082: any.</p>
5083:
5084: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5085:
5086: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5087: formatting elements</a>.</p>
5088:
5089: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5090:
5091: </dd>
5092:
5093: <dt>A start tag token whose tag name is one of: "applet",
5094: "marquee", "object"</dt>
5095: <dd>
5096:
5097: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5098: any.</p>
5099:
5100: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5101:
5102: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5103: formatting elements</a>.</p>
5104:
5105: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5106:
5107: </dd>
5108:
5109: <dt>An end tag token whose tag name is one of: "applet", "button",
5110: "marquee", "object"</dt>
5111: <dd>
5112:
5113: <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>
5114: with the same tag name as that of the token, then this is a
5115: <a href="#parse-error">parse error</a>; ignore the token.</p>
5116:
5117: <p>Otherwise, run these steps:</p>
5118:
5119: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5120:
5121: <li><p>If the <a href="#current-node">current node</a> is not an element with
5122: the same tag name as that of the token, then this is a
5123: <a href="#parse-error">parse error</a>.</p></li>
5124:
5125: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5126: until an element with the same tag name as the token has been
5127: popped from the stack.</p></li>
5128:
5129: <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
5130: last marker</a>.</li>
5131:
5132: </ol></dd>
5133:
5134: <dt>A start tag whose tag name is "table"</dt>
5135: <dd>
5136:
5137: <p>If the <code>Document</code> is <em>not</em> set to
5138: <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
5139: elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
5140: <code>p</code> element in scope</a>, then act as if an end tag
5141: with the tag name "p" had been seen.</p> <!-- i hate myself (this
5142: quirk was basically caused by acid2; if i'd realised we could
5143: change the specs when i wrote acid2, we could have avoided having
5144: any parsing-mode quirks) -Hixie -->
5145:
5146: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5147:
5148: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5149:
5150: <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>
5151:
5152: </dd>
5153:
5154: <dt>A start tag whose tag name is one of: "area", "basefont",
5155: "bgsound", "br", "embed", "img", "input", "keygen", "spacer",
5156: "wbr"</dt>
5157: <dd>
5158:
5159: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5160: any.</p>
5161:
5162: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5163: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5164: elements</a>.</p>
5165:
5166: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5167: token's <i>self-closing flag</i></a>, if it is set.</p>
5168:
5169: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
5170: shouldn't really do it for <area>, <basefont>, <bgsound>, and
5171: <spacer> -->
5172:
5173: </dd>
5174:
5175: <dt>A start tag whose tag name is one of: "param", "source"</dt>
5176: <dd>
5177:
5178: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5179: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5180: elements</a>.</p>
5181:
5182: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5183: token's <i>self-closing flag</i></a>, if it is set.</p>
5184:
5185: </dd>
5186:
5187: <dt>A start tag whose tag name is "hr"</dt>
5188: <dd>
5189:
5190: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5191: an element in scope">has a <code>p</code> element in
5192: scope</a>, then act as if an end tag with the tag name
5193: "p" had been seen.</p>
5194:
5195: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5196: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5197: elements</a>.</p>
5198:
5199: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5200: token's <i>self-closing flag</i></a>, if it is set.</p>
5201:
5202: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5203:
5204: </dd>
5205:
5206: <dt>A start tag whose tag name is "image"</dt>
5207: <dd>
5208: <p><a href="#parse-error">Parse error</a>. Change the token's tag name
5209: to "img" and reprocess it. (Don't ask.)</p> <!-- As of
5210: 2005-12, studies showed that around 0.2% of pages used the
5211: <image> element. -->
5212: </dd>
5213:
5214: <dt id="isindex">A start tag whose tag name is "isindex"</dt>
5215: <dd>
5216:
5217: <p><a href="#parse-error">Parse error</a>.</p>
5218:
5219: <p>If the <a href="#form-element-pointer"><code title="">form</code> element
5220: pointer</a> is not null, then ignore the token.</p>
5221:
5222: <p>Otherwise:</p>
5223:
5224: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5225: token's <i>self-closing flag</i></a>, if it is set.</p> <!--
5226: purely to reduce the number of errors (we don't care if they
5227: included the /, they're not supposed to be including the tag at
5228: all! -->
5229:
5230: <p>Act as if a start tag token with the tag name "form" had been seen.</p>
5231:
5232: <p>If the token has an attribute called "action", set the
5233: <code title="attr-form-action">action</code> attribute on the
5234: resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
5235: "action" attribute of the token.</p>
5236:
5237: <p>Act as if a start tag token with the tag name "hr" had been
5238: seen.</p>
5239:
5240: <p>Act as if a start tag token with the tag name "label" had been
5241: seen.</p>
5242:
5243: <p>Act as if a stream of character tokens had been seen (see below
5244: for what they should say).</p>
5245:
5246: <p>Act as if a start tag token with the tag name "input" had been
5247: seen, with all the attributes from the "isindex" token except
5248: "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
5249: <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
5250:
5251: <p>Act as if a stream of character tokens had been seen (see
5252: below for what they should say).</p>
5253:
5254: <p>Act as if an end tag token with the tag name "label" had been
5255: seen.</p>
5256:
5257: <p>Act as if a start tag token with the tag name "hr" had been
5258: seen.</p>
5259:
5260: <p>Act as if an end tag token with the tag name "form" had been
5261: seen.</p>
5262:
5263: <p>If the token has an attribute with the name "prompt", then the
5264: first stream of characters must be the same string as given in
5265: that attribute, and the second stream of characters must be
5266: empty. Otherwise, the two streams of character tokens together
5267: should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
5268: equivalent of "This is a searchable index. Insert your search
5269: keywords here: (input field)" in the user's preferred
5270: language.</p>
5271:
5272: </dd>
5273:
5274: <dt>A start tag whose tag name is "textarea"</dt>
5275: <dd>
5276:
5277: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
5278: token.</p></li>
5279:
5280: <li><p>If the next token is a U+000A LINE FEED (LF) character
5281: token, then ignore that token and move on to the next
5282: one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
5283: ignored as an authoring convenience.)</p></li>
5284:
5285: <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
5286: the RCDATA state.</p></li>
5287:
5288: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
5289: current <a href="#insertion-mode">insertion mode</a>.</p>
5290:
5291: </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
5292: ok".</p></li>
5293:
1.91 mike 5294: <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
5295: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 5296:
5297: </ol></dd>
5298:
5299: <dt>A start tag whose tag name is "xmp"</dt>
5300: <dd>
5301:
1.233 mike 5302: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5303: an element in scope">has a <code>p</code> element in
5304: scope</a>, then act as if an end tag with the tag name
5305: "p" had been seen.</p>
5306:
1.1 mike 5307: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5308: any.</p>
5309:
5310: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5311:
1.91 mike 5312: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5313:
5314: </dd>
5315:
5316: <dt>A start tag whose tag name is "iframe"</dt>
5317: <dd>
5318:
5319: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5320:
1.91 mike 5321: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5322:
5323: </dd>
5324:
5325: <dt>A start tag whose tag name is "noembed"</dt>
5326: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
5327: <dd>
5328:
1.91 mike 5329: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5330:
5331: </dd>
5332:
5333: <dt>A start tag whose tag name is "select"</dt>
5334: <dd>
5335:
5336: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5337: any.</p>
5338:
5339: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5340:
5341: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5342:
5343: <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>",
5344: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
5345: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
5346: row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
5347: cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
5348: "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
5349: table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
5350: to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
5351:
5352: </dd>
5353:
5354: <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
5355: <dd>
5356:
5357: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5358: element in scope">has an <code>option</code> element in
5359: scope</a>, then act as if an end tag with the tag name "option"
5360: had been seen.</p>
5361:
5362: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5363: any.</p>
5364:
5365: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5366:
5367: </dd>
5368:
5369: <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
5370: <dd>
5371:
5372: <!-- the parsing rules for ruby really don't match IE much at all,
5373: but in practice the markup used is very simple and so strict
5374: compatibility with IE isn't required. For example, as defined
5375: here we get very, very different behaviour than IE for
5376: pathological cases like:
5377:
5378: <ruby><ol><li><p>a<rt>b
5379: <ruby>a<rt>b<p>c
5380:
5381: But in practice most ruby markup falls into these cases:
5382:
5383: <ruby>a<rt>b</ruby>
5384: <ruby>a<rp>b<rt>c<rp>d</ruby>
5385: <ruby>a<rt>b</rt></ruby>
5386: <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
5387:
5388: -->
5389:
5390: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5391: element in scope">has a <code>ruby</code> element in scope</a>,
5392: then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
5393: node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
5394: <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
5395: node</a> up to the node immediately before the bottommost
5396: <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
5397: elements</a>.</p>
5398:
5399: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5400:
5401: </dd>
5402:
5403: <dt>An end tag whose tag name is "br"</dt>
5404: <dd>
5405: <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
5406: the tag name "br" had been seen. Ignore the end tag token.</p>
5407: </dd>
5408:
5409: <dt>A start tag whose tag name is "math"</dt>
5410: <dd>
5411:
5412: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5413: any.</p>
5414:
5415: <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
5416: fixes the case of MathML attributes that are not all
5417: lowercase.)</p>
5418:
5419: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
5420: fixes the use of namespaced attributes, in particular XLink.)</p>
5421:
5422: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
5423: <a href="#mathml-namespace">MathML namespace</a>.</p>
5424:
5425: <!-- If we ever change the frameset-ok flag to an insertion mode,
5426: the following change would be implied, except we'd have to do it
5427: even in the face of a self-closed tag:
5428: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
5429: -->
5430:
5431: <p>If the token has its <i>self-closing flag</i> set, pop the
5432: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5433: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
5434: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
5435:
5436: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
5437: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
5438: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
5439: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
5440: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
5441: foreign content">in foreign content</a>".</p>
5442:
5443: </dd>
5444:
5445: <dt>A start tag whose tag name is "svg"</dt>
5446: <dd>
5447:
5448: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5449: any.</p>
5450:
5451: <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
5452: the case of SVG attributes that are not all lowercase.)</p>
5453:
5454: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
5455: fixes the use of namespaced attributes, in particular XLink in
5456: SVG.)</p>
5457:
5458: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
5459: <a href="#svg-namespace">SVG namespace</a>.</p>
5460:
5461: <!-- If we ever change the frameset-ok flag to an insertion mode,
5462: the following change would be implied, except we'd have to do it
5463: even in the face of a self-closed tag:
5464: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
5465: -->
5466:
5467: <p>If the token has its <i>self-closing flag</i> set, pop the
5468: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5469: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
5470: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
5471:
5472: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
5473: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
5474: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
5475: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
5476: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
5477: foreign content">in foreign content</a>".</p>
5478:
5479: </dd>
5480:
5481: <dt>A start <!--or end--> tag whose tag name is one of: "caption",
5482: "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
5483: "thead", "tr"</dt>
5484: <!--<dt>An end tag whose tag name is one of: "area", "base",
5485: "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
5486: "img", "input", "isindex", "keygen", "link", "meta", "noembed",
5487: "noframes", "param", "script", "select", "source", "spacer",
5488: "style", "table", "textarea", "title", "wbr"</dt>-->
5489: <!--<dt>An end tag whose tag name is "noscript", if the
5490: <span>scripting flag</span> is enabled</dt>-->
5491: <dd>
5492: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5493: <!-- end tags are commented out because since they can never end
5494: up on the stack anyway, the default end tag clause will
5495: automatically handle them. we don't want to have text in the spec
5496: that is just an optimisation, as that detracts from the spec
5497: itself -->
5498: </dd>
5499:
5500: <dt>Any other start tag</dt>
5501: <dd>
5502:
5503: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5504: any.</p>
5505:
5506: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5507:
5508: <p class="note">This element will be a <a href="#phrasing">phrasing</a>
5509: element.</p>
5510:
5511: </dd>
5512:
5513: <dt>Any other end tag</dt>
5514: <dd>
5515:
5516: <p>Run the following steps:</p>
5517:
5518: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
5519: node</a> (the bottommost node of the stack).</p></li>
5520:
5521: <li><p>If <var title="">node</var> has the same tag name as
5522: the end tag token, then:</p>
5523:
5524: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5525:
5526: <li><p>If the tag name of the end tag token does not match
5527: the tag name of the <a href="#current-node">current node</a>, this is a
5528: <a href="#parse-error">parse error</a>.</p></li>
5529:
5530: <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
5531: to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
5532:
5533: </ol></li>
5534:
5535: <li><p>Otherwise, if <var title="">node</var> is in neither the
5536: <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
5537: category, then this is a <a href="#parse-error">parse error</a>; ignore the
5538: token, and abort these steps.</p></li>
5539:
5540: <li><p>Set <var title="">node</var> to the previous entry in the
5541: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
5542:
5543: <li><p>Return to step 2.</p></li>
5544:
5545: </ol></dd>
5546:
1.91 mike 5547: </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 5548:
5549: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.91 mike 5550: mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>", tokens must be
1.1 mike 5551: handled as follows:</p>
5552:
5553: <dl class="switch"><dt>A character token</dt>
5554: <dd>
5555:
5556: <p><a href="#insert-a-character" title="insert a character">Insert the token's
5557: character</a> into the <a href="#current-node">current node</a>.</p>
5558:
5559: </dd>
5560:
5561: <dt>An end-of-file token</dt>
5562: <dd>
5563:
5564: <!-- can't be the fragment case -->
5565: <p><a href="#parse-error">Parse error</a>.</p>
5566:
5567: <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
5568: element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
5569: executed"</a>.</p>
5570:
5571: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5572: elements</a>.</p>
5573:
5574: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5575: insertion mode</a> and reprocess the current token.</p>
5576:
5577: </dd>
5578:
5579: <dt>An end tag whose tag name is "script"</dt>
5580: <dd>
5581:
5582: <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
5583: (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
5584:
5585: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5586: elements</a>.</p>
5587:
5588: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5589: insertion mode</a>.</p>
5590:
5591: <p>Let the <var title="">old insertion point</var> have the
5592: same value as the current <a href="#insertion-point">insertion point</a>. Let
5593: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
5594: input character</a>.</p>
5595:
5596: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
5597: one.</p>
5598:
5599: <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 5600: which might cause <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters
1.1 mike 5601: to be inserted into the tokenizer</a>, and might cause the
5602: tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
5603:
5604: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
5605: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
5606: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
5607:
5608: <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
5609: <a href="#insertion-point">insertion point</a> to its previous value. This value
5610: might be the "undefined" value.)</p>
5611:
5612: <p id="scriptTagParserResumes">At this stage, if there is a
5613: <a href="semantics.html#pending-external-script">pending external script</a>, then:</p>
5614:
5615: <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
5616:
5617: <dd>
5618:
5619: <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
5620: processing of any nested invocations of the tokenizer, yielding
5621: control back to the caller. (Tokenization will resume when the
5622: caller returns to the "outer" tree construction stage.)</p>
5623:
5624: <p class="note">The tree construction stage of this particular
5625: parser is <a href="#nestedParsing">being called reentrantly</a>,
1.159 mike 5626: 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 5627:
5628: </dd>
5629:
5630:
5631: <dt>Otherwise:</dt>
5632:
5633: <dd>
5634:
5635: <p>Follow these steps:</p>
5636:
5637: <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-external-script">pending
5638: external script</a>. There is no longer a <a href="semantics.html#pending-external-script">pending
5639: external script</a>.</p></li>
5640:
5641: <li><p><a href="browsers.html#pause">Pause</a> until the script has <a href="semantics.html#completed-loading">completed
5642: loading</a>.</p></li>
5643:
5644: <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
5645: <a href="#next-input-character">next input character</a>.</p></li>
5646:
5647: <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
5648: by one (it should be zero before this step, so this sets it to
5649: one).</p></li>
5650:
5651: <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute the
5652: script</a>.</p></li>
5653:
5654: <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
5655: by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
5656: zero (which it always should be at this point), then set the
5657: <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
5658:
5659: </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
5660: again.</p></li>
5661:
5662: <li><p>If there is once again a <a href="semantics.html#pending-external-script">pending external
5663: script</a>, then repeat these steps from step 1.</p></li>
5664:
5665: </ol></dd>
5666:
5667: </dl></dd>
5668:
5669: <dt>Any other end tag</dt>
5670: <dd>
5671:
5672: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5673: elements</a>.</p>
5674:
5675: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5676: insertion mode</a>.</p>
5677:
5678: </dd>
5679:
5680: </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>
5681:
5682: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
5683: mode: in table">in table</a>", tokens must be handled as follows:</p>
5684:
5685: <dl class="switch"><dt>A character token</dt>
5686: <dd>
5687:
5688: <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
5689: be an empty list of tokens.</p>
5690:
5691: <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
5692: <a href="#insertion-mode">insertion mode</a>.</p>
5693:
5694: <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
5695: reprocess the token.</p>
5696:
5697: </dd>
5698:
5699: <dt>A comment token</dt>
5700: <dd>
5701: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
5702: node</a> with the <code title="">data</code> attribute set to
5703: the data given in the comment token.</p>
5704: </dd>
5705:
5706: <dt>A DOCTYPE token</dt>
5707: <dd>
5708: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5709: </dd>
5710:
5711: <dt>A start tag whose tag name is "caption"</dt>
5712: <dd>
5713:
5714: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5715: below.)</p>
5716:
5717: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5718: formatting elements</a>.</p>
5719:
5720: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5721: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
5722:
5723: </dd>
5724:
5725: <dt>A start tag whose tag name is "colgroup"</dt>
5726: <dd>
5727:
5728: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5729: below.)</p>
5730:
5731: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5732: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
5733: group</a>".</p>
5734:
5735: </dd>
5736:
5737: <dt>A start tag whose tag name is "col"</dt>
5738: <dd>
5739: <p>Act as if a start tag token with the tag name "colgroup"
5740: had been seen, then reprocess the current token.</p>
5741: </dd>
5742:
5743: <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
5744: <dd>
5745:
5746: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5747: below.)</p>
5748:
5749: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5750: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
5751: body</a>".</p>
5752:
5753: </dd>
5754:
5755: <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
5756: <dd>
5757: <p>Act as if a start tag token with the tag name "tbody" had
5758: been seen, then reprocess the current token.</p>
5759: </dd>
5760:
5761: <dt>A start tag whose tag name is "table"</dt>
5762: <dd>
5763:
5764: <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
5765: the tag name "table" had been seen, then, if that token wasn't
5766: ignored, reprocess the current token.</p>
5767:
5768: <p class="note">The fake end tag token here can only be
5769: ignored in the <a href="#fragment-case">fragment case</a>.</p>
5770:
5771: </dd>
5772:
5773: <dt>An end tag whose tag name is "table"</dt>
5774: <dd>
5775:
5776: <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
5777: scope</a> with the same tag name as the token, this is a
5778: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
5779: case</a>)</p>
5780:
5781: <p>Otherwise:</p>
5782:
5783: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
5784: element has been popped from the stack.</p>
5785:
5786: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
5787:
5788: </dd>
5789:
5790: <dt>An end tag whose tag name is one of: "body", "caption",
5791: "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
5792: "thead", "tr"</dt>
5793: <dd>
5794: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5795: </dd>
5796:
5797: <dt>A start tag whose tag name is one of: "style", "script"</dt>
5798: <dd>
5799:
5800: <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
5801: mode</a>.</p>
5802:
5803: </dd>
5804:
5805: <dt>A start tag whose tag name is "input"</dt>
5806: <dd>
5807:
5808: <p>If the token does not have an attribute with the name "type",
5809: or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
5810: case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
5811: else" entry below.</p>
5812:
5813: <p>Otherwise:</p>
5814:
5815: <p><a href="#parse-error">Parse error</a>.</p>
5816:
5817: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5818:
5819: <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
5820: open elements</a>.</p>
5821:
5822: </dd>
5823:
5824: <dt>An end-of-file token</dt>
5825: <dd>
5826:
5827: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 5828: <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 5829: error</a>.</p>
5830:
5831: <p class="note">It can only be the <a href="#current-node">current node</a> in
5832: the <a href="#fragment-case">fragment case</a>.</p>
5833:
5834: <p><a href="#stop-parsing">Stop parsing</a>.</p>
5835:
5836: </dd>
5837:
5838: <dt>Anything else</dt>
5839: <dd>
5840:
5841: <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
5842: rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
5843: body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
5844: <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
5845: <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
5846: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
5847: into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
5848:
5849: </dd>
5850:
5851: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
5852: back to a table context</dfn>, it means that the UA must, while
5853: 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 5854: element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1 mike 5855: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
5856:
5857: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 5858: <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 5859: case</a>.</p>
5860:
5861:
5862:
5863: <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>
5864:
5865: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
5866: mode: in table text">in table text</a>", tokens must be handled
5867: as follows:</p>
5868:
5869: <dl class="switch"><dt>A character token</dt>
5870: <dd>
5871:
5872: <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
5873: tokens</a></var> list.</p>
5874:
5875: </dd>
5876:
5877:
5878: <dt>Anything else</dt>
5879: <dd>
5880:
5881: <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
5882: tokens</a></var> list are character tokens that are not one of U+0009
5883: CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
5884: (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
5885: reprocess those character tokens using the rules given in the
5886: "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
5887: table">in table</a>" insertion mode.</p>
5888:
5889: <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
5890: characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
5891: tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
5892:
5893: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5894: insertion mode</a> and reprocess the token.</p>
5895:
5896: </dd>
5897:
5898: </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>
5899:
5900: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
5901: mode: in caption">in caption</a>", tokens must be handled as follows:</p>
5902:
5903: <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
5904: <dd>
5905:
5906: <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
5907: scope</a> with the same tag name as the token, this is a
5908: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
5909: case</a>)</p>
5910:
5911: <p>Otherwise:</p>
5912:
5913: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
5914:
5915: <p>Now, if the <a href="#current-node">current node</a> is not a
5916: <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
5917: error</a>.</p>
5918:
5919: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
5920: element has been popped from the stack.</p>
5921:
5922: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
5923: the last marker</a>.</p>
5924:
5925: <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>
5926:
5927: </dd>
5928:
5929: <dt>A start tag whose tag name is one of: "caption", "col",
5930: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
5931: <dt>An end tag whose tag name is "table"</dt>
5932: <dd>
5933:
5934: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
5935: name "caption" had been seen, then, if that token wasn't
5936: ignored, reprocess the current token.</p>
5937:
5938: <p class="note">The fake end tag token here can only be
5939: ignored in the <a href="#fragment-case">fragment case</a>.</p>
5940:
5941: </dd>
5942:
5943: <dt>An end tag whose tag name is one of: "body", "col",
5944: "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
5945: "tr"</dt>
5946: <dd>
5947: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5948: </dd>
5949:
5950: <dt>Anything else</dt>
5951: <dd>
5952: <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
5953: mode</a>.</p>
5954: </dd>
5955:
5956: </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>
5957:
5958: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
5959: mode: in column group">in column group</a>", tokens must be handled as follows:</p>
5960:
5961: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
5962: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
5963: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
5964: <dd>
5965: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
5966: the <a href="#current-node">current node</a>.</p>
5967: </dd>
5968:
5969: <dt>A comment token</dt>
5970: <dd>
5971: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
5972: node</a> with the <code title="">data</code> attribute set to
5973: the data given in the comment token.</p>
5974: </dd>
5975:
5976: <dt>A DOCTYPE token</dt>
5977: <dd>
5978: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5979: </dd>
5980:
5981: <dt>A start tag whose tag name is "html"</dt>
5982: <dd>
5983: <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
5984: mode</a>.</p>
5985: </dd>
5986:
5987: <dt>A start tag whose tag name is "col"</dt>
5988: <dd>
5989:
5990: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5991: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5992: elements</a>.</p>
5993:
5994: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5995: token's <i>self-closing flag</i></a>, if it is set.</p>
5996:
5997: </dd>
5998:
5999: <dt>An end tag whose tag name is "colgroup"</dt>
6000: <dd>
6001:
6002: <p>If the <a href="#current-node">current node</a> is the root
1.159 mike 6003: <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 6004: error</a>; ignore the token. (<a href="#fragment-case">fragment
6005: case</a>)</p>
6006:
6007: <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
6008: 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
6009: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
6010: "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
6011:
6012: </dd>
6013:
6014: <dt>An end tag whose tag name is "col"</dt>
6015: <dd>
6016: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6017: </dd>
6018:
6019: <dt>An end-of-file token</dt>
6020: <dd>
6021:
1.159 mike 6022: <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 6023: element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
6024: case</a>)</p>
6025:
6026: <p>Otherwise, act as described in the "anything else" entry
6027: below.</p>
6028:
6029: </dd>
6030:
6031: <dt>Anything else</dt>
6032: <dd>
6033:
6034: <p>Act as if an end tag with the tag name "colgroup" had been
6035: seen, and then, if that token wasn't ignored, reprocess the
6036: current token.</p>
6037:
6038: <p class="note">The fake end tag token here can only be
6039: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6040:
6041: </dd>
6042:
6043: </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>
6044:
6045: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
6046: mode: in table body">in table body</a>", tokens must be handled as follows:</p>
6047:
6048: <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
6049: <dd>
6050:
6051: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6052: context</a>. (See below.)</p>
6053:
6054: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
6055: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
6056: in row">in row</a>".</p>
6057:
6058: </dd>
6059:
6060: <dt>A start tag whose tag name is one of: "th", "td"</dt>
6061: <dd>
6062: <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
6063: the tag name "tr" had been seen, then reprocess the current
6064: token.</p>
6065: </dd>
6066:
6067: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
6068: "thead"</dt>
6069: <dd>
6070:
6071: <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
6072: scope</a> with the same tag name as the token, this is a
6073: <a href="#parse-error">parse error</a>. Ignore the token.</p>
6074:
6075: <p>Otherwise:</p>
6076:
6077: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6078: context</a>. (See below.)</p>
6079:
6080: <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
6081: open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
6082: to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
6083:
6084: </dd>
6085:
6086: <dt>A start tag whose tag name is one of: "caption", "col",
6087: "colgroup", "tbody", "tfoot", "thead"</dt>
6088: <dt>An end tag whose tag name is "table"</dt>
6089: <dd>
6090:
6091: <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
6092: <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
6093: element in table scope</a>, this is a <a href="#parse-error">parse
6094: error</a>. Ignore the token. (<a href="#fragment-case">fragment
6095: case</a>)</p>
6096:
6097: <p>Otherwise:</p>
6098:
6099: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6100: context</a>. (See below.)</p>
6101:
6102: <p>Act as if an end tag with the same tag name as the
6103: <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
6104: been seen, then reprocess the current token.</p>
6105:
6106: </dd>
6107:
6108: <dt>An end tag whose tag name is one of: "body", "caption",
6109: "col", "colgroup", "html", "td", "th", "tr"</dt>
6110: <dd>
6111: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6112: </dd>
6113:
6114: <dt>Anything else</dt>
6115: <dd>
6116: <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
6117: mode</a>.</p>
6118: </dd>
6119:
6120: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
6121: back to a table body context</dfn>, it means that the UA must,
6122: 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 6123: <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 6124: element, pop elements from the <a href="#stack-of-open-elements">stack of open
6125: elements</a>.</p>
6126:
6127: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 6128: <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 6129: case</a>.</p>
6130:
6131:
6132: <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>
6133:
6134: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
6135: mode: in row">in row</a>", tokens must be handled as follows:</p>
6136:
6137: <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
6138: <dd>
6139:
6140: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
6141: context</a>. (See below.)</p>
6142:
6143: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
6144: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
6145: in cell">in cell</a>".</p>
6146:
6147: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
6148: formatting elements</a>.</p>
6149:
6150: </dd>
6151:
6152: <dt>An end tag whose tag name is "tr"</dt>
6153: <dd>
6154:
6155: <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
6156: scope</a> with the same tag name as the token, this is a
6157: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6158: case</a>)</p>
6159:
6160: <p>Otherwise:</p>
6161:
6162: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
6163: context</a>. (See below.)</p>
6164:
6165: <p>Pop the <a href="#current-node">current node</a> (which will be a
6166: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
6167: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
6168: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
6169: body</a>".</p>
6170:
6171: </dd>
6172:
6173: <dt>A start tag whose tag name is one of: "caption", "col",
6174: "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
6175: <dt>An end tag whose tag name is "table"</dt>
6176: <dd>
6177:
6178: <p>Act as if an end tag with the tag name "tr" had been seen,
6179: then, if that token wasn't ignored, reprocess the current
6180: token.</p>
6181:
6182: <p class="note">The fake end tag token here can only be
6183: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6184:
6185: </dd>
6186:
6187: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
6188: "thead"</dt>
6189: <dd>
6190:
6191: <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
6192: scope</a> with the same tag name as the token, this is a
6193: <a href="#parse-error">parse error</a>. Ignore the token.</p>
6194:
6195: <p>Otherwise, act as if an end tag with the tag name "tr" had
6196: been seen, then reprocess the current token.</p>
6197:
6198: </dd>
6199:
6200: <dt>An end tag whose tag name is one of: "body", "caption",
6201: "col", "colgroup", "html", "td", "th"</dt>
6202: <dd>
6203: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6204: </dd>
6205:
6206: <dt>Anything else</dt>
6207: <dd>
6208: <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
6209: mode</a>.</p>
6210: </dd>
6211:
6212: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
6213: back to a table row context</dfn>, it means that the UA must,
6214: 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 6215: element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1 mike 6216: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6217:
6218: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 6219: <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 6220: case</a>.</p>
6221:
6222:
6223: <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>
6224:
6225: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
6226: mode: in cell">in cell</a>", tokens must be handled as follows:</p>
6227:
6228: <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
6229: <dd>
6230:
6231: <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
6232: scope</a> with the same tag name as that of the token, then
6233: this is a <a href="#parse-error">parse error</a> and the token must be
6234: ignored.</p>
6235:
6236: <p>Otherwise:</p>
6237:
6238: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
6239:
6240: <p>Now, if the <a href="#current-node">current node</a> is not an element
6241: with the same tag name as the token, then this is a
6242: <a href="#parse-error">parse error</a>.</p>
6243:
6244: <p>Pop elements from this stack until an element with the same
6245: tag name as the token has been popped from the stack.</p>
6246:
6247: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
6248: the last marker</a>.</p>
6249:
6250: <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
6251: <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
6252: this point.)</p>
6253:
6254: </dd>
6255:
6256: <dt>A start tag whose tag name is one of: "caption", "col",
6257: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
6258: <dd>
6259:
6260: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
6261: <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
6262: a <code>td</code> or <code>th</code> element in table
6263: scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
6264: the token. (<a href="#fragment-case">fragment case</a>)</p>
6265:
6266: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
6267: reprocess the current token.</p>
6268:
6269: </dd>
6270:
6271: <dt>An end tag whose tag name is one of: "body", "caption",
6272: "col", "colgroup", "html"</dt>
6273: <dd>
6274: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6275: </dd>
6276:
6277: <dt>An end tag whose tag name is one of: "table", "tbody",
6278: "tfoot", "thead", "tr"</dt>
6279: <dd>
6280:
6281: <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
6282: scope</a> with the same tag name as that of the token
6283: (which can only happen for "tbody", "tfoot" and "thead", or,
6284: in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
6285: error</a> and the token must be ignored.</p>
6286:
6287: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
6288: reprocess the current token.</p>
6289:
6290: </dd>
6291:
6292: <dt>Anything else</dt>
6293: <dd>
6294: <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
6295: mode</a>.</p>
6296: </dd>
6297:
6298: </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
6299: mean to run the following algorithm:</p>
6300:
6301: <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>
6302: element in table scope</a>, then act as if an end tag token
6303: with the tag name "td" had been seen.</p></li>
6304:
6305: <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
6306: <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
6307: <code>th</code> element in table scope</a>; act as if an end
6308: tag token with the tag name "th" had been seen.</p></li>
6309:
6310: </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
6311: 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
6312: the same time, nor can it have neither when the <a href="#insertion-mode">insertion
6313: mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
6314: cell</a>".</p>
6315:
6316:
6317: <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>
6318:
6319: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
6320: mode: in select">in select</a>", tokens must be handled as follows:</p>
6321:
6322: <dl class="switch"><dt>A character token</dt>
6323: <dd>
6324: <p><a href="#insert-a-character" title="insert a character">Insert the token's
6325: character</a> into the <a href="#current-node">current node</a>.</p>
6326: </dd>
6327:
6328: <dt>A comment token</dt>
6329: <dd>
6330: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6331: node</a> with the <code title="">data</code> attribute set to
6332: the data given in the comment token.</p>
6333: </dd>
6334:
6335: <dt>A DOCTYPE token</dt>
6336: <dd>
6337: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6338: </dd>
6339:
6340: <dt>A start tag whose tag name is "html"</dt>
6341: <dd>
6342: <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
6343: mode</a>.</p>
6344: </dd>
6345:
6346: <dt>A start tag whose tag name is "option"</dt>
6347: <dd>
6348:
6349: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6350: element, act as if an end tag with the tag name "option" had
6351: been seen.</p>
6352:
6353: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6354:
6355: </dd>
6356:
6357: <dt>A start tag whose tag name is "optgroup"</dt>
6358: <dd>
6359:
6360: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6361: element, act as if an end tag with the tag name "option" had
6362: been seen.</p>
6363:
6364: <p>If the <a href="#current-node">current node</a> is an
6365: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
6366: tag name "optgroup" had been seen.</p>
6367:
6368: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6369:
6370: </dd>
6371:
6372: <dt>An end tag whose tag name is "optgroup"</dt>
6373: <dd>
6374:
6375: <p>First, if the <a href="#current-node">current node</a> is an
6376: <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
6377: it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
6378: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
6379: the tag name "option" had been seen.</p>
6380:
6381: <p>If the <a href="#current-node">current node</a> is an
6382: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
6383: <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
6384: <a href="#parse-error">parse error</a>; ignore the token.</p>
6385:
6386: </dd>
6387:
6388: <dt>An end tag whose tag name is "option"</dt>
6389: <dd>
6390:
6391: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6392: element, then pop that node from the <a href="#stack-of-open-elements">stack of open
6393: elements</a>. Otherwise, this is a <a href="#parse-error">parse
6394: error</a>; ignore the token.</p>
6395:
6396: </dd>
6397:
6398: <dt>An end tag whose tag name is "select"</dt>
6399: <dd>
6400:
6401: <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
6402: scope</a> with the same tag name as the token, this is a
6403: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6404: case</a>)</p>
6405:
6406: <p>Otherwise:</p>
6407:
6408: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
6409: until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
6410: stack.</p>
6411:
6412: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
6413:
6414: </dd>
6415:
6416: <dt>A start tag whose tag name is "select"</dt>
6417: <dd>
6418:
6419: <p><a href="#parse-error">Parse error</a>. Act as if the token had been
6420: an end tag with the tag name "select" instead.</p>
6421:
6422: </dd>
6423:
6424: <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
6425: <dd>
1.73 mike 6426:
6427: <p><a href="#parse-error">Parse error</a>.</p>
6428:
1.124 mike 6429: <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>
6430: element in table scope</a>, ignore the token. (<a href="#fragment-case">fragment
6431: case</a>)</p>
1.73 mike 6432:
6433: <p>Otherwise, act as if an end tag with the tag name "select" had
6434: been seen, and reprocess the token.</p>
6435:
1.1 mike 6436: </dd>
6437:
6438: <dt>A start tag token whose tag name is "script"</dt>
6439: <dd>
6440: <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
6441: mode</a>.</p>
6442: </dd>
6443:
6444: <dt>An end-of-file token</dt>
6445: <dd>
6446:
6447: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 6448: <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 6449: error</a>.</p>
6450:
6451: <p class="note">It can only be the <a href="#current-node">current node</a> in
6452: the <a href="#fragment-case">fragment case</a>.</p>
6453:
6454: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6455:
6456: </dd>
6457:
6458: <dt>Anything else</dt>
6459: <dd>
6460: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6461: </dd>
6462:
6463: </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>
6464:
6465: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
6466: mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
6467:
6468: <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
6469: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
6470: <dd>
6471: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
6472: name "select" had been seen, and reprocess the token.</p>
6473: </dd>
6474:
6475: <dt>An end tag whose tag name is one of: "caption", "table",
6476: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
6477: <dd>
6478:
6479: <p><a href="#parse-error">Parse error</a>.</p>
6480:
6481: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
6482: element in table scope</a> with the same tag name as that
6483: of the token, then act as if an end tag with the tag name
6484: "select" had been seen, and reprocess the token. Otherwise,
6485: ignore the token.</p>
6486:
6487: </dd>
6488:
6489: <dt>Anything else</dt>
6490: <dd>
6491: <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
6492: mode</a>.</p>
6493: </dd>
6494:
1.168 mike 6495: </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 6496:
6497: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
6498: mode: in foreign content">in foreign content</a>", tokens must be
6499: handled as follows:</p>
6500:
6501: <dl class="switch"><dt>A character token</dt>
6502: <dd>
6503:
6504: <p><a href="#insert-a-character" title="insert a character">Insert the token's
6505: character</a> into the <a href="#current-node">current node</a>.</p>
6506:
6507: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
6508: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
6509: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
6510: flag</a> to "not ok".</p>
6511:
6512: </dd>
6513:
6514: <dt>A comment token</dt>
6515: <dd>
6516: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6517: node</a> with the <code title="">data</code> attribute set to
6518: the data given in the comment token.</p>
6519: </dd>
6520:
6521: <dt>A DOCTYPE token</dt>
6522: <dd>
6523: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6524: </dd>
6525:
6526: <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>
6527: <dd>
6528:
6529: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6530: elements</a>.</p>
6531:
6532: <p>Let the <var title="">old insertion point</var> have the
6533: same value as the current <a href="#insertion-point">insertion point</a>. Let
6534: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
6535: input character</a>.</p>
6536:
6537: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
6538: one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
6539:
6540: <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
6541: the <code title="">script</code> element</a> according to the SVG
1.187 mike 6542: rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
1.1 mike 6543:
1.159 mike 6544: <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 6545: tokenizer</a>, the parser will not be executed reentrantly,
6546: since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
6547:
6548: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
6549: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
6550: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
6551:
6552: <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
6553: <a href="#insertion-point">insertion point</a> to its previous value. This value
6554: might be the "undefined" value.)</p>
6555:
6556: </dd>
6557:
6558: <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>
6559: <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>
6560: <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>
6561: <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>
6562: <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>
6563: <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>
6564: <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>
6565: <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>
6566: <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>
6567: <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>
6568: <dt>An end tag</dt>
6569: <dd>
6570:
6571: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
6572: <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
6573:
6574: <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
6575: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
1.336 mike 6576: content</a>", but there is no element <a href="#has-an-element-in-scope" title="has an
6577: element in scope">in scope</a> that has a namespace other than
6578: the <a href="#html-namespace-0">HTML namespace</a>, switch the <a href="#insertion-mode">insertion
1.1 mike 6579: mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
6580:
6581: </dd>
6582:
6583: <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
6584: "blockquote", "body"<!--by inspection-->, "br", "center", "code",
1.422 mike 6585: "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
6586: uniformly throughout the parser -->, "em", "embed", "h1", "h2",
6587: "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
1.1 mike 6588: completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
6589: "li", "listing"<!-- so that pre and listing can be handled
6590: uniformly throughout the parser -->, "menu", "meta", "nobr",
6591: "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
6592: the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
6593: "span", "strong", "strike"<!-- so that s and strike can be handled
6594: uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
1.305 mike 6595: "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt> <!-- this
6596: list was determined empirically by studying over 6,000,000,000
1.422 mike 6597: pages that were specifically not XML pages -->
6598: <dt>A start tag whose tag name is "font", if the token has any
6599: attributes named "color", "face", or "size"</dt> <!-- the
6600: attributes here are required so that SVG <font> will go through as
6601: SVG but legacy <font>s won't -->
6602: <dt>An end-of-file token</dt> <dd>
1.1 mike 6603:
6604: <p><a href="#parse-error">Parse error</a>.</p>
6605:
6606: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
6607: the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
6608: namespace</a>.</p>
6609:
6610: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
6611: insertion mode</a>, and reprocess the token.</p>
6612:
6613: </dd>
6614:
6615: <dt>Any other start tag</dt>
6616: <dd>
6617:
6618: <p>If the <a href="#current-node">current node</a> is an element in the
6619: <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
6620: attributes</a> for the token. (This fixes the case of MathML
6621: attributes that are not all lowercase.)</p>
6622:
6623: <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
6624: namespace</a>, and the token's tag name is one of the ones in
6625: the first column of the following table, change the tag name to
6626: the name given in the corresponding cell in the second
6627: column. (This fixes the case of SVG elements that are not all
6628: lowercase.)</p>
6629:
6630: <table><thead><tr><th> Tag name </th><th> Element name
6631: </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
6632: </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
6633: </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
6634: </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
6635: </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
6636: </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
6637: </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
6638: </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
6639: </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
6640: </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
6641: </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
6642: </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
6643: </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
6644: </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
6645: </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
6646: </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
6647: </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
6648: </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
6649: </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
6650: </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
6651: </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
6652: </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
6653: </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
6654: </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
6655: </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
6656: </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
6657: </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
6658: </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
6659: </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
6660: </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
6661: </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
6662: </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
6663: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
6664: </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
6665: </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
6666: <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
6667: </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
6668: </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
6669: namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
6670: token. (This fixes the case of SVG attributes that are not all
6671: lowercase.)</p>
6672:
6673: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
6674: fixes the use of namespaced attributes, in particular XLink in
6675: SVG.)</p>
6676:
6677: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
6678: same namespace as the <a href="#current-node">current node</a>.</p>
6679:
6680: <p>If the token has its <i>self-closing flag</i> set, pop the
6681: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6682: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
6683: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
6684:
6685: </dd>
6686:
6687: </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>
6688:
6689: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
6690: mode: after body">after body</a>", tokens must be handled as follows:</p>
6691:
6692: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6693: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6694: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6695: <dd>
6696: <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
6697: mode</a>.</p>
6698: </dd>
6699:
6700: <dt>A comment token</dt>
6701: <dd>
6702: <p>Append a <code>Comment</code> node to the first element in
1.159 mike 6703: 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 6704: element), with the <code title="">data</code> attribute set to
6705: the data given in the comment token.</p>
6706: </dd>
6707:
6708: <dt>A DOCTYPE token</dt>
6709: <dd>
6710: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6711: </dd>
6712:
6713: <dt>A start tag whose tag name is "html"</dt>
6714: <dd>
6715: <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
6716: mode</a>.</p>
6717: </dd>
6718:
6719: <dt>An end tag whose tag name is "html"</dt>
6720: <dd>
6721:
6722: <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
6723: fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
6724: error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
6725:
6726: <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
6727: body</a>".</p>
6728:
6729: </dd>
6730:
6731: <dt>An end-of-file token</dt>
6732: <dd>
6733: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6734: </dd>
6735:
6736: <dt>Anything else</dt>
6737: <dd>
6738:
6739: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
6740: mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
6741: body</a>" and reprocess the token.</p>
6742:
6743: </dd>
6744:
6745: </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>
6746:
6747: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
6748: mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
6749:
6750: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6751: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6752: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6753: <dd>
6754: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6755: the <a href="#current-node">current node</a>.</p>
6756: </dd>
6757:
6758: <dt>A comment token</dt>
6759: <dd>
6760: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6761: node</a> with the <code title="">data</code> attribute set to
6762: the data given in the comment token.</p>
6763: </dd>
6764:
6765: <dt>A DOCTYPE token</dt>
6766: <dd>
6767: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6768: </dd>
6769:
6770: <dt>A start tag whose tag name is "html"</dt>
6771: <dd>
6772: <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
6773: mode</a>.</p>
6774: </dd>
6775:
6776: <dt>A start tag whose tag name is "frameset"</dt>
6777: <dd>
6778: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6779: </dd>
6780:
6781: <dt>An end tag whose tag name is "frameset"</dt>
6782: <dd>
6783:
6784: <p>If the <a href="#current-node">current node</a> is the root
1.159 mike 6785: <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 6786: error</a>; ignore the token. (<a href="#fragment-case">fragment
6787: case</a>)</p>
6788:
6789: <p>Otherwise, pop the <a href="#current-node">current node</a> from the
6790: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6791:
6792: <p>If the parser was <em>not</em> originally created as part
6793: of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
6794: (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5 mike 6795: node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1 mike 6796: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
6797: frameset</a>".</p>
6798:
6799: </dd>
6800:
6801: <dt>A start tag whose tag name is "frame"</dt>
6802: <dd>
6803:
6804: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
6805: Immediately pop the <a href="#current-node">current node</a> off the
6806: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6807:
6808: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6809: token's <i>self-closing flag</i></a>, if it is set.</p>
6810:
6811: </dd>
6812:
6813: <dt>A start tag whose tag name is "noframes"</dt>
6814: <dd>
6815: <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
6816: mode</a>.</p>
6817: </dd>
6818:
6819: <dt>An end-of-file token</dt>
6820: <dd>
6821:
6822: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 6823: <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 6824: error</a>.</p>
6825:
6826: <p class="note">It can only be the <a href="#current-node">current node</a> in
6827: the <a href="#fragment-case">fragment case</a>.</p>
6828:
6829: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6830:
6831: </dd>
6832:
6833: <dt>Anything else</dt>
6834: <dd>
6835: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6836: </dd>
6837:
6838: </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>
6839:
6840: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
6841: mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
6842:
6843: <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
6844: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6845: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6846: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6847: <dd>
6848: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6849: the <a href="#current-node">current node</a>.</p>
6850: </dd>
6851:
6852: <dt>A comment token</dt>
6853: <dd>
6854: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6855: node</a> with the <code title="">data</code> attribute set to
6856: the data given in the comment token.</p>
6857: </dd>
6858:
6859: <dt>A DOCTYPE token</dt>
6860: <dd>
6861: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6862: </dd>
6863:
6864: <dt>A start tag whose tag name is "html"</dt>
6865: <dd>
6866: <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
6867: mode</a>.</p>
6868: </dd>
6869:
6870: <dt>An end tag whose tag name is "html"</dt>
6871: <dd>
6872: <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
6873: frameset</a>".</p>
6874: </dd>
6875:
6876: <dt>A start tag whose tag name is "noframes"</dt>
6877: <dd>
6878: <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
6879: mode</a>.</p>
6880: </dd>
6881:
6882: <dt>An end-of-file token</dt>
6883: <dd>
6884: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6885: </dd>
6886:
6887: <dt>Anything else</dt>
6888: <dd>
6889: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6890: </dd>
6891:
1.336 mike 6892: </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 6893:
6894: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
6895: mode: after after body">after after body</a>", tokens must be handled as follows:</p>
6896:
6897: <dl class="switch"><dt>A comment token</dt>
6898: <dd>
6899: <p>Append a <code>Comment</code> node to the <code>Document</code>
6900: object with the <code title="">data</code> attribute set to the
6901: data given in the comment token.</p>
6902: </dd>
6903:
6904: <dt>A DOCTYPE token</dt>
6905: <dt>A character token that is one of U+0009 CHARACTER
6906: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6907: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6908: <dt>A start tag whose tag name is "html"</dt>
6909: <dd>
6910: <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
6911: mode</a>.</p>
6912: </dd>
6913:
6914: <dt>An end-of-file token</dt>
6915: <dd>
6916: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6917: </dd>
6918:
6919: <dt>Anything else</dt>
6920: <dd>
6921: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
6922: to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
6923: reprocess the token.</p>
6924: </dd>
6925:
6926: </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>
6927:
6928: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
6929: mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
6930:
6931: <dl class="switch"><dt>A comment token</dt>
6932: <dd>
6933: <p>Append a <code>Comment</code> node to the <code>Document</code>
6934: object with the <code title="">data</code> attribute set to the
6935: data given in the comment token.</p>
6936: </dd>
6937:
6938: <dt>A DOCTYPE token</dt>
6939: <dt>A character token that is one of U+0009 CHARACTER
6940: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6941: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6942: <dt>A start tag whose tag name is "html"</dt>
6943: <dd>
6944: <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
6945: mode</a>.</p>
6946: </dd>
6947:
6948: <dt>An end-of-file token</dt>
6949: <dd>
6950: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6951: </dd>
6952:
6953: <dt>A start tag whose tag name is "noframes"</dt>
6954: <dd>
6955: <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
6956: mode</a>.</p>
6957: </dd>
6958:
6959: <dt>Anything else</dt>
6960: <dd>
6961: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6962: </dd>
6963:
1.266 mike 6964: </dl></div><div class="impl">
6965:
6966: <h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4>
1.1 mike 6967:
6968: <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
6969: the document, the user agent must follow the steps in this
6970: section.</p>
6971:
1.10 mike 6972: <!-- this happens as part of one of the tasks that runs the parser -->
1.1 mike 6973:
1.10 mike 6974: <p>First, the user agent must set the <a href="dom.html#current-document-readiness">current document
6975: readiness</a> to "interactive" and the <a href="#insertion-point">insertion
6976: point</a> to undefined.</p>
6977:
6978: <p>Then, the user agent must then make a list of all the scripts
6979: 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
6980: document has finished parsing</a>, the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that
6981: will execute asynchronously</a>, and the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts
6982: that will execute as soon as possible</a>. This is the <dfn id="list-of-scripts-pending-after-the-parser-stopped">list
6983: of scripts pending after the parser stopped</dfn>.</p>
6984:
6985: <p>The rules for <a href="semantics.html#when-a-script-completes-loading">when a script completes loading</a> start
6986: applying (script execution is no longer managed by the parser).</p>
1.1 mike 6987:
6988: <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
6989: execute as soon as possible</a> have <a href="semantics.html#completed-loading">completed
6990: loading</a>, or if the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that will execute
6991: asynchronously</a> is not empty and the first script in that list
6992: has <a href="semantics.html#completed-loading">completed loading</a>, then the user agent must act as
6993: if those scripts just completed loading, following the rules given
6994: for that in the <code><a href="semantics.html#script">script</a></code> element definition.</p>
6995:
1.10 mike 6996: <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
6997: has finished parsing</a> is not empty, and the first item in this
6998: list has already <a href="semantics.html#completed-loading">completed loading</a>, then the user agent
6999: must act as if that script just finished loading.</p>
7000:
7001: <p class="note">By this point, there will be no scripts that have
7002: loaded but have not yet been executed.</p>
7003:
7004: <hr><!-- async --><p>Once all the scripts on the <a href="#list-of-scripts-pending-after-the-parser-stopped">list of scripts pending after
7005: the parser stopped</a> have <a href="semantics.html#completed-loading">completed loading</a> and
7006: been <a href="semantics.html#executing-a-script-block" title="executing a script block">executed</a>, the
7007: 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
7008: event</a> called <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
7009: <code>Document</code>. (If the list is empty, this happens
7010: immediately.)</p>
1.1 mike 7011:
1.10 mike 7012: <hr><!-- async --><p>Once everything that <dfn id="delay-the-load-event" title="delay the load event">delays the
1.1 mike 7013: load event</dfn> of the document has completed, the user agent must
7014: run the following steps:</p>
7015:
7016: <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
7017: readiness</a> to "complete".</li>
7018:
7019: <li>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
7020: 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.394 mike 7021: simple event</a> called <code title="event-load">load</code> at
1.1 mike 7022: the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
7023: its <code title="dom-event-target">target</code> set to the
7024: <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
7025: <code><a href="browsers.html#window">Window</a></code> object).</li>
7026:
7027: <li>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
7028: 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
7029: <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
7030: <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
7031: current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
7032: must bubble but not be cancelable and has no default action.</li>
7033:
1.407 mike 7034: </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 7035: task source</a>.</p>
1.1 mike 7036:
1.266 mike 7037: </div><div class="impl">
1.1 mike 7038:
7039: <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4>
7040:
7041: <p>When an application uses an <a href="#html-parser">HTML parser</a> in
7042: conjunction with an XML pipeline, it is possible that the
7043: constructed DOM is not compatible with the XML tool chain in certain
7044: subtle ways. For example, an XML toolchain might not be able to
7045: represent attributes with the name <code title="">xmlns</code>,
7046: since they conflict with the Namespaces in XML syntax. There is also
7047: some data that the <a href="#html-parser">HTML parser</a> generates that isn't
7048: included in the DOM itself. This section specifies some rules for
7049: handling these issues.</p>
7050:
7051: <p>If the XML API being used doesn't support DOCTYPEs, the tool may
7052: drop DOCTYPEs altogether.</p>
7053:
7054: <p>If the XML API doesn't support attributes in no namespace that
7055: are named "<code title="">xmlns</code>", attributes whose names
7056: start with "<code title="">xmlns:</code>", or attributes in the
7057: <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
7058: attributes.</p>
7059:
7060: <p>The tool may annotate the output with any namespace declarations
7061: required for proper operation.</p>
7062:
7063: <p>If the XML API being used restricts the allowable characters in
7064: the local names of elements and attributes, then the tool may map
7065: all element and attribute local names that the API wouldn't support
7066: to a set of names that <em>are</em> allowed, by replacing any
7067: character that isn't supported with the uppercase letter U and the
7068: six digits of the character's Unicode code point when expressed in
7069: hexadecimal, using digits 0-9 and capital letters A-F as the
7070: symbols, in increasing numeric order.</p>
7071:
7072: <p class="example">For example, the element name <code title="">foo<bar</code>, which can be output by the <a href="#html-parser">HTML
7073: parser</a>, though it is neither a legal HTML element name nor a
7074: well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
7075: element name (though it's still not legal in HTML by any means).</p>
7076:
7077: <p class="example">As another example, consider the attribute
7078: <code>xlink:href</code>. Used on a MathML element, it becomes, after
7079: being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
7080: attribute with a prefix "<code title="">xlink</code>" and a local
7081: name "<code title="">href</code>". However, used on an HTML element,
7082: it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
7083: might not be accepted by an XML API. It could thus get converted,
7084: becoming "<code title="">xlinkU00003Ahref</code>".</p>
7085:
7086: <p class="note">The resulting names from this conversion
7087: conveniently can't clash with any attribute generated by the
7088: <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
7089: those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
7090: algorithm's table.</p>
7091:
7092: <p>If the XML API restricts comments from having two consecutive
7093: U+002D HYPHEN-MINUS characters (--), the tool may insert a single
7094: U+0020 SPACE character between any such offending characters.</p>
7095:
7096: <p>If the XML API restricts comments from ending in a
7097: U+002D HYPHEN-MINUS character (-), the tool may insert a single
7098: U+0020 SPACE character at the end of such comments.</p>
7099:
7100: <p>If the XML API restricts allowed characters in character data,
1.439 mike 7101: attribute values, or comments, the tool may replace any U+000C FORM
7102: FEED (FF) character with a U+0020 SPACE character, and any other
7103: literal non-XML character with a U+FFFD REPLACEMENT CHARACTER.</p>
1.1 mike 7104:
7105: <p>If the tool has no way to convey out-of-band information, then
7106: the tool may drop the following information:</p>
7107:
7108: <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
7109: <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>
7110:
7111: <li>The association between form controls and forms that aren't
7112: their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
7113: <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
7114:
7115: </ul><p class="note">The mutations allowed by this section apply
7116: <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
7117: applied. For example, a <code title=""><a::></code> start tag
7118: will be closed by a <code title=""></a::></code> end tag, and
7119: never by a <code title=""></aU00003AU00003A></code> end tag, even
7120: if the user agent is using the rules above to then generate an
7121: actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
7122:
1.266 mike 7123: </div><div class="impl">
1.1 mike 7124:
1.35 mike 7125: <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 7126:
7127: <p><i>This section is non-normative.</i></p>
7128:
7129: <p>This section examines some erroneous markup and discusses how
7130: the <a href="#html-parser">HTML parser</a> handles these cases.</p>
7131:
7132:
7133: <h5 id="misnested-tags:-b-i-b-i"><span class="secno">9.2.8.1 </span>Misnested tags: <b><i></b></i></h5>
7134:
7135: <p><i>This section is non-normative.</i></p>
7136:
7137: <p>The most-often discussed example of erroneous markup is as
7138: follows:</p>
7139:
7140: <pre><p>1<b>2<i>3</b>4</i>5</p></pre>
7141:
7142: <p>The parsing of this markup is straightforward up to the "3". At
7143: this point, the DOM looks like this:</p>
7144:
1.159 mike 7145: <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
7146: 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 7147: <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
7148: formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
7149: <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>
7150:
7151: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
7152: invoked. This is a simple case, in that the <var title="">formatting
7153: element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
7154: <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
1.159 mike 7155: elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element-0">html</a></code>,
7156: <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 7157: active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
7158: DOM tree is unmodified at this point.</p>
7159:
7160: <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
7161: the active formatting elements</a>, in this case just the
7162: <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
7163: for the "4" text node. After the end tag token for the "i" is also
7164: received, and the "5" text node is inserted, the DOM looks as
7165: follows:</p>
7166:
1.159 mike 7167: <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 7168:
7169: <p><i>This section is non-normative.</i></p>
7170:
7171: <p>A case similar to the previous one is the following:</p>
7172:
7173: <pre><b>1<p>2</b>3</p></pre>
7174:
7175: <p>Up to the "2" the parsing here is straightforward:</p>
7176:
1.159 mike 7177: <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 7178: "b" is parsed.</p>
7179:
7180: <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
1.159 mike 7181: elements</a> has four elements on it: <code><a href="semantics.html#the-html-element-0">html</a></code>,
7182: <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 7183: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
7184: <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>
7185:
7186: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
7187: in the previous example. However, in this case, there <em>is</em> a
7188: <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
7189: this time the adoption agency algorithm isn't skipped over.</p>
7190:
1.159 mike 7191: <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 7192: element. A conceptual "bookmark" marks the position of the
7193: <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
7194: elements</a>, but since that list has only one element in it,
7195: it won't have much effect.</p>
7196:
7197: <p>As the algorithm progresses, <var title="">node</var> ends up set
7198: to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
7199: node</var> ends up set to the <var title="">furthest block</var>
7200: (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
7201:
7202: <p>The <var title="">last node</var> gets appended (moved) to the
7203: <var title="">common ancestor</var>, so that the DOM looks like:</p>
7204:
1.159 mike 7205: <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 7206: <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
7207:
1.159 mike 7208: <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 7209: <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
7210:
1.159 mike 7211: <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 7212: active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
7213: elements</a>, so that when the "3" is parsed, it is appended to
7214: the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
7215:
1.159 mike 7216: <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 7217:
7218: <p><i>This section is non-normative.</i></p>
7219:
7220: <p>Error handling in tables is, for historical reasons, especially
7221: strange. For example, consider the following markup:</p>
7222:
7223: <pre><table><strong><b></strong><tr><td>aaa</td></tr><strong>bbb</strong></table>ccc</pre>
7224:
7225: <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
7226: directly inside a table like that, and the parser handles this case
7227: 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
7228: examining the DOM tree as it stands just after the
7229: <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
7230:
1.159 mike 7231: <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 7232: tag has been seen:</p>
7233:
1.159 mike 7234: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></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
7235: 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 7236: <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
7237: resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
7238: elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
7239: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
7240: table">in table</a>".</p>
7241:
7242: <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
7243: to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
7244: 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
7245: then handled in a rather straight-forward manner, taking the parser
7246: through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
7247: body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
7248: row</a>" insertion modes, after which the DOM looks as
7249: follows:</p>
7250:
1.159 mike 7251: <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
7252: 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 7253: <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
7254: formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
7255: it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
7256: mode: in row">in row</a>".</p>
7257:
7258: <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
7259: <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
7260: 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
7261: mode</a>).</p>
7262:
1.159 mike 7263: <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 7264: no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
7265: node:</p>
7266:
1.159 mike 7267: <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 7268: handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
1.159 mike 7269: 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 7270: 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
7271: elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
7272: marker having been removed by the "td" end tag token); and the
7273: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
7274: table body">in table body</a>".</p>
7275:
7276: <p>Thus it is that the "bbb" character tokens are found. These
7277: trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
7278: text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
7279: insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
7280: body">in table body</a>"). The character tokens are collected,
7281: and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
7282: seen, they are processed as a group. Since they are not all spaces,
7283: 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,
7284: which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
7285: body</a>" insertion mode but with <a href="#foster-parent" title="foster
7286: parent">foster parenting</a>.</p>
7287:
7288: <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
7289: active formatting elements are reconstructed</a>, a
7290: <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
7291: parent">foster parented</a>, and then the "bbb" text node is
7292: appended to it:</p>
7293:
1.159 mike 7294: <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
7295: <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 7296: <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
7297: this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
7298: formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
7299: and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
7300: mode: in table body">in table body</a>".</p>
7301:
7302: <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
7303: character">space characters</a> instead of "bbb", then those
7304: <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
7305: appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
7306:
7307: <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
7308: tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
7309: elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
7310: but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
7311: elements</a>, so the "ccc" character tokens after the table
7312: result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
7313: time after the table:</p>
7314:
1.159 mike 7315: <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 7316:
7317: <p><i>This section is non-normative.</i></p>
7318:
7319: <p>Consider the following markup, which for this example we will
7320: 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 7321: content of an <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code> in another document with the
1.1 mike 7322: <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
7323:
7324: <pre><div id=a>
7325: <script>
7326: var div = document.getElementById('a');
7327: parent.document.body.appendChild(div);
7328: </script>
7329: <script>
7330: alert(document.URL);
7331: </script>
7332: </div>
7333: <script>
7334: alert(document.URL);
7335: </script></pre>
7336:
7337: <p>Up to the first "script" end tag, before the script is parsed,
7338: the result is relatively straightforward:</p>
7339:
1.306 mike 7340: <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="">
7341: </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 7342: and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
7343:
1.159 mike 7344: <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 7345: aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
7346: <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
1.306 mike 7347: <code><a href="semantics.html#the-div-element">div</a></code> element</em>.</p>
1.1 mike 7348:
7349: <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
7350: is inserted <em>into the outer <code>Document</code>
7351: object</em>.</p>
7352:
7353: <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
7354: the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
7355: object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
1.159 mike 7356: <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>.</p>
1.1 mike 7357:
7358: <p class="note">This isn't a security problem since the script that
1.306 mike 7359: moves the <code><a href="semantics.html#the-div-element">div</a></code> into the outer <code>Document</code> can
1.1 mike 7360: only do so because they have the two <code>Document</code> object
1.159 mike 7361: have the same <a href="browsers.html#origin">origin</a>.</p>
1.1 mike 7362:
7363: <p>Thus, the first alert says "http://example.com/outer".</p>
7364:
1.306 mike 7365: <p>Once the <code><a href="semantics.html#the-div-element">div</a></code> element's end tag is parsed, the
7366: <code><a href="semantics.html#the-div-element">div</a></code> element is popped off the stack, and so the next
1.1 mike 7367: <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
7368:
1.159 mike 7369: <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 7370:
7371:
7372:
1.215 mike 7373: <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3>
1.1 mike 7374:
7375: <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
7376:
7377: <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
7378:
7379: <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
7380:
7381: <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
7382:
7383: <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
7384:
7385: <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
7386:
7387: <hr><p>Data mining tools and other user agents that perform operations
1.83 mike 7388: on <code><a href="iana-considerations.html#text-html">text/html</a></code> content without running scripts,
1.1 mike 7389: evaluating CSS or XPath expressions, or otherwise exposing the
7390: resulting DOM to arbitrary content, may "support namespaces" by just
7391: asserting that their DOM node analogues are in certain namespaces,
7392: without actually exposing the above strings.</p>
7393:
7394:
7395:
7396:
7397: <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3>
7398:
7399: <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
7400: algorithm</dfn>. The algorithm takes as input a DOM
7401: <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
7402: exception.</p>
7403:
7404: <p class="note">This algorithm serializes the <em>children</em> of
7405: the node being serialized, not the node itself.</p>
7406:
7407: <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
7408: the empty string.</p></li>
7409:
7410: <li>
7411:
7412: <p>For each child node of <var title="">the node</var>, in
7413: <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
7414:
7415: </p><ol><li><p>Let <var title="">current node</var> be the child node
7416: being processed.</p></li>
7417:
7418: <li>
7419:
7420: <p>Append the appropriate string from the following list to
7421: <var title="">s</var>:</p>
7422:
7423: <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
7424:
7425: <dd>
7426:
7427: <p>Append a U+003C LESS-THAN SIGN (<code title=""><</code>)
7428: character, followed by the element's tag name. (For nodes
7429: created by the <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
7430: lowercase.)</p>
7431:
7432: <p>For each attribute that the element has, append a U+0020
7433: SPACE character, the attribute's name (which, for attributes
7434: 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
7435: U+003D EQUALS SIGN (<code title="">=</code>) character, a
7436: U+0022 QUOTATION MARK (<code title="">"</code>)
7437: character, the attribute's value, <a href="#escapingString" title="escaping a
7438: string">escaped as described below</a> in <i>attribute
7439: mode</i>, and a second U+0022 QUOTATION MARK (<code title="">"</code>) character.</p>
7440:
7441: <p>While the exact order of attributes is UA-defined, and may
7442: depend on factors such as the order that the attributes were
7443: given in the original markup, the sort order must be stable,
7444: such that consecutive invocations of this algorithm serialize an
7445: element's attributes in the same order.</p>
7446:
7447: <p>Append a U+003E GREATER-THAN SIGN (<code title="">></code>)
7448: character.</p>
7449:
7450: <p>If <var title="">current node</var> is an
1.5 mike 7451: <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 7452: <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 7453: <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>,
7454: <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>,
7455: <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 7456: <code><a href="obsolete.html#spacer">spacer</a></code>, or <code>wbr</code> element, then
1.1 mike 7457: continue on to the next child node at this point.</p> <!--
7458: also, i guess: image and isindex, but we don't list those
7459: because we don't consider those "elements", more "macros", and
7460: thus we should never serialize them -->
7461:
7462: <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42 mike 7463: <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 7464: a U+000A LINE FEED (LF) character.</p>
7465:
7466: <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
7467: serialization algorithm</a> on the <var title="">current
7468: node</var> element (thus recursing into this algorithm for
7469: 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,
7470: and finally a U+003E GREATER-THAN SIGN (<code title="">></code>) character.</p>
7471:
7472: </dd>
7473:
7474:
7475: <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
7476: node</dt>
7477:
7478: <dd>
7479:
1.19 mike 7480: <p>If the parent of <var title="">current node</var> is a
1.42 mike 7481: <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 7482: <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 7483: <code><a href="obsolete.html#noframes">noframes</a></code>, or <code><a href="obsolete.html#plaintext">plaintext</a></code> element, or
7484: if the parent of <var title="">current node</var> is
7485: <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
7486: node, then append the value of <var title="">current
7487: node</var>'s <code title="">data</code> IDL attribute
7488: literally.</p>
1.1 mike 7489:
7490: <p>Otherwise, append the value of <var title="">current
1.192 mike 7491: node</var>'s <code title="">data</code> IDL attribute, <a href="#escapingString" title="escaping a string">escaped as described
1.1 mike 7492: below</a>.</p>
7493:
7494: </dd>
7495:
7496:
7497: <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
7498:
7499: <dd>
7500:
7501: <p>Append the literal string <code><!--</code> (U+003C
7502: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
1.192 mike 7503: U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1 mike 7504: attribute, followed by the literal string <code>--></code>
7505: (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
7506: SIGN).</p>
7507:
7508: </dd>
7509:
7510:
7511: <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
7512:
7513: <dd>
7514:
7515: <p>Append the literal string <code><?</code> (U+003C
7516: LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
1.192 mike 7517: of <var title="">current node</var>'s <code title="">target</code> IDL attribute, followed by a single
7518: U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1 mike 7519: attribute, followed by a single U+003E GREATER-THAN SIGN
7520: character ('>').</p>
7521:
7522: </dd>
7523:
7524:
7525: <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
7526:
7527: <dd>
7528:
7529: <p>Append the literal string <code><!DOCTYPE</code> (U+003C
7530: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
7531: LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
7532: LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
7533: LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
7534: LETTER E), followed by a space (U+0020 SPACE), followed by the
1.192 mike 7535: value of <var title="">current node</var>'s <code title="">name</code> IDL attribute, followed by the literal
1.1 mike 7536: string <code>></code> (U+003E GREATER-THAN SIGN).</p>
7537:
7538: </dd>
7539:
7540:
7541: </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
7542: occur as children of elements. If, despite this, they somehow do
7543: occur, this algorithm must raise an
7544: <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
7545:
7546: </li>
7547:
7548: </ol></li>
7549:
7550: <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
7551:
7552: </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
7553: purposes of the algorithm above) consists of replacing any
7554: occurrences of the "<code title="">&</code>" character by the
7555: string "<code title="">&amp;</code>", any occurrences of the
7556: U+00A0 NO-BREAK SPACE character by the string "<code title="">&nbsp;</code>", and, if the algorithm was invoked in
7557: 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
7558: 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>
7559:
7560: <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
7561: agent, and are therefore not covered in the algorithm above.</p>
7562:
7563: <p class="note">It is possible that the output of this algorithm, if
7564: parsed with an <a href="#html-parser">HTML parser</a>, will not return the
7565: original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
7566: element to which a <code title="">Comment</code> node has been
7567: appended is serialized and the output is then reparsed, the comment
7568: will end up being displayed in the text field. Similarly, if, as a
7569: result of DOM manipulation, an element contains a comment that
7570: contains the literal string "<code title="">--></code>", then
7571: when the result of serializing the element is parsed, the comment
7572: will be truncated at that point and the rest of the comment will be
7573: interpreted as markup. More examples would be making a
7574: <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
7575: "<code></script></code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
7576: 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
7577: <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
7578: tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
7579:
7580:
7581: <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3>
7582:
7583: <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
7584: algorithm</dfn>. The algorithm optionally takes as input an
7585: <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
7586: parser, as well as <var title="">input</var>, a string to parse, and
7587: returns a list of zero or more nodes.</p>
7588:
7589: <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
7590: in the parser section are parts that only occur if the parser was
7591: created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
7592: with such markings for informational purposes only; such markings
7593: have no normative weight. If it is possible for a condition
7594: described as a <a href="#fragment-case">fragment case</a> to occur even when the
7595: parser wasn't created for the purposes of handling this algorithm,
7596: then that is an error in the specification.</p>
7597:
7598: <ol><li>
7599:
7600: <p>Create a new <code>Document</code> node, and mark it as being
7601: an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
7602:
7603: </li>
7604:
7605: <li>
7606:
7607: <p>If there is a <var title="">context</var> element, and the
7608: <code>Document</code> of the <var title="">context</var> element
7609: is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
7610: 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
7611: the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
7612: mode</a>, then let the <code>Document</code> be in
7613: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
7614: <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
7615:
7616: </li>
7617:
7618: <li>
7619:
7620: <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
7621: the just created <code>Document</code> node.</p>
7622:
7623: </li>
7624:
7625: <li>
7626:
7627: <p>If there is a <var title="">context</var> element, run these
7628: substeps:</p>
7629:
7630: <ol><li>
7631:
7632: <p>Set the <a href="#html-parser">HTML parser</a>'s <a href="#tokenization">tokenization</a>
7633: stage's <a href="#content-model-flag">content model flag</a> according to the <var title="">context</var> element, as follows:</p>
7634:
1.159 mike 7635: <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 7636: element</dt>
7637:
7638: <dd>Set the <a href="#content-model-flag">content model flag</a> to
7639: the RCDATA state.</dd>
7640:
7641:
7642: <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 7643: <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 7644: <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1 mike 7645:
7646: <dd>Set the <a href="#content-model-flag">content model flag</a> to
1.91 mike 7647: the RAWTEXT state.</dd>
1.1 mike 7648:
7649:
7650: <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
7651:
7652: <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, set the
1.91 mike 7653: <a href="#content-model-flag">content model flag</a> to the RAWTEXT
1.1 mike 7654: state. Otherwise, set the <a href="#content-model-flag">content model flag</a> to the
7655: PCDATA state.</dd>
7656:
7657:
1.42 mike 7658: <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1 mike 7659:
7660: <dd>Set the <a href="#content-model-flag">content model flag</a> to
7661: PLAINTEXT.</dd>
7662:
7663:
7664: <dt>Otherwise</dt>
7665:
7666: <dd>Leave the <a href="#content-model-flag">content model flag</a> in the PCDATA
7667: state.</dd>
7668:
7669: </dl></li>
7670:
7671: <li>
7672:
1.159 mike 7673: <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 7674: with no attributes.</p>
7675:
7676: </li>
7677:
7678: <li>
7679:
7680: <p>Append the element <var title="">root</var> to the
7681: <code>Document</code> node created above.</p>
7682:
7683: </li>
7684:
7685: <li>
7686:
7687: <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
7688: it contains just the single element <var title="">root</var>.</p>
7689:
7690: </li>
7691:
7692: <li>
7693:
7694: <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
7695: parser's insertion mode appropriately</a>.</p>
7696:
7697: <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
7698:
7699: </li>
7700:
7701: <li>
7702:
7703: <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
7704: to the nearest node to the <var title="">context</var> element
7705: that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
7706: ancestor chain, and including the element itself, if it is a
7707: <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
7708: <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
7709:
7710: </li>
7711:
7712: </ol></li>
7713:
7714: <li>
7715:
7716: <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
7717: parser</a> just created the <var title="">input</var>. The
7718: encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
7719: <i>irrelevant</i>.</p>
7720:
7721: </li>
7722:
7723: <li>
7724:
7725: <p>Start the parser and let it run until it has consumed all the
7726: characters just inserted into the input stream.</p>
7727:
7728: </li>
7729:
7730: <li>
7731:
7732: <p>If there is a <var title="">context</var> element, return the
7733: child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
7734: order</a>.</p>
7735:
7736: <p>Otherwise, return the children of the <code>Document</code>
7737: object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
7738:
7739: </li>
7740:
1.123 mike 7741: </ol></div></body></html>
Webmaster