Annotation of html5/spec/syntax.html, revision 1.680
1.2 mike 1: <!DOCTYPE HTML>
1.258 mike 2: <!-- when publishing, change bits marked ZZZ --><html lang="en-US-x-Hixie"><head><title>9 The HTML syntax — HTML 5</title><style type="text/css">
1.1 mike 3: pre { margin-left: 2em; white-space: pre-wrap; }
4: h2 { margin: 3em 0 1em 0; }
5: h3 { margin: 2.5em 0 1em 0; }
6: h4 { margin: 2.5em 0 0.75em 0; }
7: h5, h6 { margin: 2.5em 0 1em; }
8: h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
9: h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
10: p { margin: 1em 0; }
11: hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
12: dl, dd { margin-top: 0; margin-bottom: 0; }
13: dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
14: dt + dt { margin-top: 0; }
15: dd dt { margin-top: 0.25em; margin-bottom: 0; }
16: dd p { margin-top: 0; }
17: dd dl + p { margin-top: 1em; }
18: dd table + p { margin-top: 1em; }
19: p + * > li, dd li { margin: 1em 0; }
20: dt, dfn { font-weight: bold; font-style: normal; }
21: dt dfn { font-style: italic; }
22: pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
23: pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
24: pre em { font-weight: bolder; font-style: normal; }
25: @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
26: var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
27: table { border-collapse: collapse; border-style: hidden hidden none hidden; }
28: table thead { border-bottom: solid; }
29: table tbody th:first-child { border-left: solid; }
1.475 mike 30: table tbody th { text-align: left; }
1.1 mike 31: table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
32: blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
33:
34: .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
35: .matrix, .matrix td { border: none; text-align: right; }
36: .matrix { margin-left: 2em; }
37: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
38: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
39: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
40:
41: .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
42: img.extra { float: right; }
43: pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
44: pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
45: pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
46: pre.css:first-line { color: #AAAA50; }
47: dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #EEFFEE; }
48: hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
49: dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
50: dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
51: dl.domintro dd p { margin: 0.5em 0; }
52: dl.switch { padding-left: 2em; }
53: dl.switch > dt { text-indent: -1.5em; }
54: dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
55: dl.triple { padding: 0 0 0 1em; }
56: dl.triple dt, dl.triple dd { margin: 0; display: inline }
57: dl.triple dt:after { content: ':'; }
58: dl.triple dd:after { content: '\A'; white-space: pre; }
59: .diff-old { text-decoration: line-through; color: silver; background: transparent; }
60: .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
61: a .diff-new { border-bottom: 1px blue solid; }
62:
63: h2 { page-break-before: always; }
64: h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
65: h1 + h2, hr + h2.no-toc { page-break-before: auto; }
66:
67: p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
68:
69: div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
70: div.head p { margin: 0; }
71: div.head h1 { margin: 0; }
72: div.head .logo { float: right; margin: 0 1em; }
73: div.head .logo img { border: none } /* remove border from top image */
74: div.head dl { margin: 1em 0; }
1.671 mike 75: div.head p.copyright, div.head p.alt { font-size: x-small; font-style: oblique; margin: 0; }
1.1 mike 76:
77: body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
78: body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
79: body > .toc > li > * { margin-bottom: 0.5em; }
80: body > .toc > li > * > li > * { margin-bottom: 0.25em; }
81: .toc, .toc li { list-style: none; }
82:
83: .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
84: .brief li { margin: 0; padding: 0; }
85: .brief li p { margin: 0; padding: 0; }
86:
87: .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
88: .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
89: .category-list li { display: inline; }
90: .category-list li:not(:last-child)::after { content: ', '; }
91: .category-list li > span, .category-list li > a { text-transform: lowercase; }
92: .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
93:
94: .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
95: .XXX > :first-child { margin-top: 0; }
96: p .XXX { line-height: 3em; }
1.159 mike 97: .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
98: .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
99: .annotation :link, .annotation :visited { color: inherit; }
100: .annotation :link:hover, .annotation :visited:hover { background: transparent; }
101: .annotation span { border: none ! important; }
1.1 mike 102: .note { color: green; background: transparent; font-family: sans-serif; }
103: .warning { color: red; background: transparent; }
104: .note, .warning { font-weight: bolder; font-style: italic; }
105: p.note, div.note { padding: 0.5em 2em; }
106: span.note { padding: 0 2em; }
107: .note p:first-child, .warning p:first-child { margin-top: 0; }
108: .note p:last-child, .warning p:last-child { margin-bottom: 0; }
109: .warning:before { font-style: normal; }
110: p.note:before { content: 'Note: '; }
111: p.warning:before { content: '\26A0 Warning! '; }
112:
113: .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
114: .bookkeeping { font-size: 0.8em; margin: 2em 0; }
115: .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
116:
117: h4 { position: relative; z-index: 3; }
118: h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
119: .element {
120: background: #EEEEFF;
121: color: black;
122: margin: 0 0 1em 0.15em;
123: padding: 0 1em 0.25em 0.75em;
124: border-left: solid #9999FF 0.25em;
125: position: relative;
126: z-index: 1;
127: }
128: .element:before {
129: position: absolute;
130: z-index: 2;
131: top: 0;
132: left: -1.15em;
133: height: 2em;
134: width: 0.9em;
135: background: #EEEEFF;
136: content: ' ';
137: border-style: none none solid solid;
138: border-color: #9999FF;
139: border-width: 0.25em;
140: }
141:
1.149 mike 142: .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
143: td > .example:only-child { margin: 0 0 0 0.1em; }
1.1 mike 144:
145: .tall-and-narrow {
146: font-size: 0.6em;
147: column-width: 25em;
148: column-gap: 1em;
149: -moz-column-width: 25em;
150: -moz-column-gap: 1em;
151: -webkit-column-width: 25em;
152: -webkit-column-gap: 1em;
153: }
154:
155: ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
156: ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
157: ul.domTree li li { list-style: none; }
158: ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
159: ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
160: ul.domTree span { font-style: italic; font-family: serif; }
161: ul.domTree .t1 code { color: purple; font-weight: bold; }
162: ul.domTree .t2 { font-style: normal; font-family: monospace; }
163: ul.domTree .t2 .name { color: black; font-weight: bold; }
164: ul.domTree .t2 .value { color: blue; font-weight: normal; }
165: ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
166: ul.domTree .t7 code, .domTree .t8 code { color: green; }
167: ul.domTree .t10 code { color: teal; }
168:
1.671 mike 169: #configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
170: #configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
171: #configUI p label { display: block; }
172: #configUI #updateUI, #configUI .loginUI { text-align: center; }
173: #configUI input[type=button] { display: block; margin: auto; }
1.267 mike 174: </style><style type="text/css">
175:
1.292 mike 176: .applies thead th > * { display: block; }
177: .applies thead code { display: block; }
178: .applies tbody th { whitespace: nowrap; }
179: .applies td { text-align: center; }
180: .applies .yes { background: yellow; }
181:
1.267 mike 182: .matrix, .matrix td { border: none; text-align: right; }
183: .matrix { margin-left: 2em; }
184:
185: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
186: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
187: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
188:
189: #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
190: #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
191: #table-example-1 caption { padding-bottom: 0.5em; }
192: #table-example-1 thead, #table-example-1 tbody { border: none; }
193: #table-example-1 th, #table-example-1 td { border: solid thin; }
194: #table-example-1 th { font-weight: normal; }
195: #table-example-1 td { border-style: none solid; vertical-align: top; }
196: #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
197: #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
198: #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
199: #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
200: #table-example-1 tbody td:first-child::after { content: leader(". "); }
201: #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
202: #table-example-1 tbody td:first-child + td { width: 10em; }
203: #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
204: #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
205:
206: .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
207: .apple-table-examples * { font-family: "Times", serif; }
208: .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
209: .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
210: .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
211: .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
212: .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
213: .apple-table-examples td { text-align: right; vertical-align: top; }
214: .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
215: .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
216: .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
217: .apple-table-examples sup { line-height: 0; }
218:
1.671 mike 219: </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="data:text/css," id="complete" rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D" id="author" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D" id="highlight" rel="alternate stylesheet" title="Highlight implementation requirements"><script>
220: function getCookie(name) {
221: var params = location.search.substr(1).split("&");
222: for (var index = 0; index < params.length; index++) {
223: if (params[index] == name)
224: return "1";
225: var data = params[index].split("=");
226: if (data[0] == name)
227: return unescape(data[1]);
228: }
229: var cookies = document.cookie.split("; ");
230: for (var index = 0; index < cookies.length; index++) {
231: var data = cookies[index].split("=");
232: if (data[0] == name)
233: return unescape(data[1]);
234: }
235: return null;
236: }
237: function load(script) {
238: var e = document.createElement('script');
239: e.setAttribute('src', 'http://www.whatwg.org/specs/web-apps/current-work/' + script + '?' + encodeURIComponent(location) + '&' + encodeURIComponent(document.referrer));
240: document.body.appendChild(e);
241: }
242: function init() {
243: if (location.search == '?slow-browser')
244: return;
245: var configUI = document.createElement('div');
246: configUI.id = 'configUI';
247: document.body.appendChild(configUI);
248: // load('reviewer.js'); // would need cross-site XHR
249: if (document.getElementById('head'))
250: load('toc.js');
251: load('styler.js');
252: // load('updater.js'); // would need cross-site XHR
253: load('dfn.js');
254: // load('status.js'); // would need cross-site XHR
255: if (getCookie('profile') == '1')
256: document.getElementsByTagName('h2')[0].textContent += '; load: ' + (new Date() - loadTimer) + 'ms';
257: fixBrokenLink();
258: }
259: </script><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css">
1.2 mike 260: <script src="link-fixup.js"></script>
261: <link href="comms.html" title="8 Communication" rel="prev">
262: <link href="spec.html#contents" title="Table of contents" rel="index">
1.1 mike 263: <link href="named-character-references.html" title="9.6 Named character references" rel="next">
1.671 mike 264: </head><body onload="fixBrokenLink(); init()"><div class="head" id="head">
1.1 mike 265: <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 266: <h1>HTML5</h1>
1.1 mike 267: <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.642 mike 268:
1.123 mike 269: </div><nav>
1.1 mike 270: <a href="comms.html">← 8 Communication</a> –
1.2 mike 271: <a href="spec.html#contents">Table of contents</a> –
1.1 mike 272: <a href="named-character-references.html">9.6 Named character references →</a>
1.680 ! mike 273: </nav><p>This is revision 1.3567.</p>
1.659 mike 274:
1.1 mike 275:
1.123 mike 276: <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.605 mike 277: <code><a href="iana.html#text-html">text/html</a></code> resources. Rules for XML resources are
1.1 mike 278: discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.614 mike 279: syntax</a>".</p><h3 id="writing"><span class="secno">9.1 </span>Writing HTML documents</h3><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><div class="impl">
1.1 mike 280:
281: <p><i>This section only applies to documents, authoring tools, and
282: markup generators. In particular, it does not apply to conformance
283: checkers; conformance checkers must use the requirements given in
284: the next section ("parsing HTML documents").</i></p>
285:
1.123 mike 286: </div><p>Documents must consist of the following parts, in the given
287: order:</p><ol><li>Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.</li>
1.1 mike 288:
289: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
290: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
291:
292: <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
293:
294: </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
295: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
296:
1.159 mike 297: <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 298:
299: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
300: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
301:
302: </ol><p>The various types of content mentioned above are described in the
1.123 mike 303: 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 304: declarations</a> are to be serialized, as discussed in the
1.123 mike 305: section on that topic.</p><div class="note">
1.1 mike 306:
1.159 mike 307: <p>Space characters before the root <code><a href="semantics.html#the-html-element-0">html</a></code> element, and
308: space characters at the start of the <code><a href="semantics.html#the-html-element-0">html</a></code> element and
309: before the <code><a href="semantics.html#the-head-element-0">head</a></code> element, will be dropped when the
1.1 mike 310: document is parsed; space characters <em>after</em> the root
1.159 mike 311: <code><a href="semantics.html#the-html-element-0">html</a></code> element will be parsed as if they were at the end
312: of the <code><a href="semantics.html#the-body-element-0">body</a></code> element. Thus, space characters around the
1.1 mike 313: root element do not round-trip.</p>
314:
315: <p>It is suggested that newlines be inserted after the DOCTYPE,
316: after any comments that are before the root element, after the
1.159 mike 317: <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
318: that are inside the <code><a href="semantics.html#the-html-element-0">html</a></code> element but before the
319: <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 320:
1.123 mike 321: </div><p>Many strings in the HTML syntax (e.g. the names of elements and
1.1 mike 322: their attributes) are case-insensitive, but only for characters in
1.547 mike 323: the ranges U+0041 to U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
324: LETTER Z) and U+0061 to U+007A (LATIN SMALL LETTER A to LATIN SMALL
1.1 mike 325: LETTER Z). For convenience, in this section this is just referred to
1.614 mike 326: as "case-insensitive".</p><h4 id="the-doctype"><span class="secno">9.1.1 </span>The DOCTYPE</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments. </i><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 327: but required, header.</p><p class="note">DOCTYPEs are required for legacy reasons. When
1.1 mike 328: omitted, browsers tend to use a different rendering mode that is
329: incompatible with some specifications. Including the DOCTYPE in a
330: document ensures that the browser makes a best-effort attempt at
1.123 mike 331: following the relevant specifications.</p><p>A DOCTYPE must consist of the following characters, in this
1.588 mike 332: order:</p><ol class="brief"><li>A U+003C LESS-THAN SIGN character (<).</li>
333: <li>A U+0021 EXCLAMATION MARK character (!).</li>
1.1 mike 334: <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>
335: <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
336: <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>
337: <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> (defined below).</li>
338: <li>Zero or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.588 mike 339: <li>A U+003E GREATER-THAN SIGN character (>).</li>
1.1 mike 340: </ol><p class="note">In other words, <code><!DOCTYPE HTML></code>,
1.123 mike 341: case-insensitively.</p><p>For the purposes of HTML generators that cannot output HTML
1.1 mike 342: markup with the short DOCTYPE "<code title=""><!DOCTYPE
343: HTML></code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
344: into the DOCTYPE (in the position defined above). This string must
1.123 mike 345: 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 346: <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">SYSTEM</code>".</li>
1.444 mike 347: <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.1 mike 348: <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
1.465 mike 349: <li>The literal string "<code><a href="infrastructure.html#about:legacy-compat">about:legacy-compat</a></code>".</li>
1.1 mike 350: <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>
351: </ol><p class="note">In other words, <code><!DOCTYPE HTML SYSTEM
352: "about:legacy-compat"></code> or <code><!DOCTYPE HTML SYSTEM
353: 'about:legacy-compat'></code>, case-insensitively except for the bit
1.123 mike 354: in quotes.</p><p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1 mike 355: the document is generated from a system that cannot output the
1.614 mike 356: shorter string.</p><h4 id="elements-0"><span class="secno">9.1.2 </span>Elements</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p>There are five different kinds of <dfn id="syntax-elements" title="syntax-elements">elements</dfn>: <a href="#void-elements">void elements</a>,
1.373 mike 357: <a href="#raw-text-elements">raw text elements</a>, <a href="#rcdata-elements">RCDATA elements</a>,
358: <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 359:
360: <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 361: <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>,
362: <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 363: <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 364: <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 365:
1.373 mike 366: <dt><dfn id="raw-text-elements">Raw text elements</dfn></dt>
1.1 mike 367:
368: <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 369: noscript don't count as raw text for syntax purposes -->
1.1 mike 370:
1.373 mike 371: <dt><dfn id="rcdata-elements">RCDATA elements</dfn></dt>
1.1 mike 372:
1.159 mike 373: <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 374:
1.373 mike 375: <dt><dfn id="foreign-elements">Foreign elements</dfn></dt>
1.1 mike 376:
377: <dd>Elements from the <a href="#mathml-namespace">MathML namespace</a>
378: and the <a href="#svg-namespace">SVG namespace</a>.</dd>
379:
1.373 mike 380: <dt><dfn id="normal-elements">Normal elements</dfn></dt>
1.1 mike 381:
382: <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
383: elements.</dd>
384:
385: </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.373 mike 386: and end of elements in the markup. <a href="#raw-text-elements" title="raw text
387: elements">Raw text</a>, <a href="#rcdata-elements" title="RCDATA
388: elements">RCDATA</a>, and <a href="#normal-elements" title="normal
389: elements">normal</a> elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to indicate where they
390: begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> to
391: indicate where they end. The start and end tags of certain
392: <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 393: later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
394: elements</a> only have a start tag; end tags must not be
1.373 mike 395: specified for <a href="#void-elements">void elements</a>. <a href="#foreign-elements">Foreign
396: elements</a> must either have a start tag and an end tag, or a
397: start tag that is marked as self-closing, in which case they must
398: not have an end tag.</p><p>The contents of the element must be placed between just after the
1.1 mike 399: start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
400: in certain cases</a>) and just before the end tag (which again,
401: <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
402: cases</a>). The exact allowed contents of each individual element
403: depends on the content model of that element, as described earlier
404: in this specification. Elements must not contain content that their
405: content model disallows. In addition to the restrictions placed on
406: the contents by those content models, however, the five types of
1.123 mike 407: 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 408: no end tag, no content can be put between the start tag and the end
1.373 mike 409: 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
410: 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
411: must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
1.1 mike 412: There are also <a href="#cdata-rcdata-restrictions">further
1.373 mike 413: restrictions</a> described below.</p><p><a href="#foreign-elements">Foreign elements</a> whose start tag is marked as
414: self-closing can't have any contents (since, again, as there's no
415: end tag, no content can be put between the start tag and the end
416: tag). <a href="#foreign-elements">Foreign elements</a> whose start tag is <em>not</em>
417: 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.588 mike 418: contain the character U+003C LESS-THAN SIGN (<) or an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.</p><div class="note">
1.374 mike 419:
420: <p>The HTML syntax does not support namespace
421: declarations, even in <a href="#foreign-elements">foreign elements</a>.</p>
422:
423: <p>For instance, consider the following HTML fragment:</p>
424:
425: <pre><p>
426: <svg>
427: <metadata>
428: <!-- this is invalid -->
429: <cdr:license xmlns:cdr="http://www.example.com/cdr/metadata" name="MIT"/>
430: </metadata>
431: </svg>
432: </p></pre>
433:
434: <p>The innermost element, <code title="">cdr:license</code>, is
435: actually in the SVG namespace, as the "<code title="">xmlns:cdr</code>" attribute has no effect (unlike in
436: XML). In fact, as the comment in the fragment above says, the
437: fragment is actually non-conforming. This is because the SVG
438: specification does not define any elements called "<code title="">cdr:license</code>" in the SVG namespace.</p>
439:
440: </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.588 mike 441: contain the character U+003C LESS-THAN SIGN (<) or an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>. Some
442: <a href="#normal-elements">normal elements</a> also have <a href="#element-restrictions">yet more restrictions</a> on what
1.1 mike 443: content they are allowed to hold, beyond the restrictions imposed by
444: the content model and those described in this paragraph. Those
1.123 mike 445: restrictions are described below.</p><p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1 mike 446: giving the element's name. HTML elements all have names that only
1.464 mike 447: use characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT
448: NINE (9), U+0061 LATIN SMALL LETTER A to U+007A LATIN SMALL LETTER
449: Z, and U+0041 LATIN CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER
450: Z. In the HTML syntax, tag names, even those for <a href="#foreign-elements">foreign
1.462 mike 451: elements</a>, may be written with any mix of lower- and uppercase
452: letters that, when converted to all-lowercase, matches the element's
1.614 mike 453: tag name; tag names are case-insensitive.</p><h5 id="start-tags"><span class="secno">9.1.2.1 </span>Start tags</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p><dfn id="syntax-start-tag" title="syntax-start-tag">Start tags</dfn> must have the
1.123 mike 454: following format:</p><ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.588 mike 455: SIGN character (<).</li>
1.1 mike 456:
457: <li>The next few characters of a start tag must be the element's
458: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
459:
460: <li>If there are to be any attributes in the next step, there must
461: first be one or more <a href="infrastructure.html#space-character" title="space character">space
462: characters</a>.</li>
463:
464: <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
465: below. Attributes may be separated from each other by one or more
466: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
467:
468: <li>After the attributes, there may be one or more <a href="infrastructure.html#space-character" title="space character">space characters</a>. (Some attributes
469: are required to be followed by a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes section</a> below.)</li>
470:
471: <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
1.373 mike 472: or if the element is a <a href="#foreign-elements" title="foreign elements">foreign
1.588 mike 473: element</a>, then there may be a single U+002F SOLIDUS character
474: (/). This character has no effect on <a href="#void-elements">void elements</a>,
475: but on <a href="#foreign-elements">foreign elements</a> it marks the start tag as
476: self-closing.</li>
1.1 mike 477:
478: <li>Finally, start tags must be closed by a U+003E GREATER-THAN
1.588 mike 479: SIGN character (>).</li>
1.1 mike 480:
1.614 mike 481: </ol><h5 id="end-tags"><span class="secno">9.1.2.2 </span>End tags</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p><dfn id="syntax-end-tag" title="syntax-end-tag">End tags</dfn> must have the
1.123 mike 482: following format:</p><ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.588 mike 483: SIGN character (<).</li>
1.1 mike 484:
485: <li>The second character of an end tag must be a U+002F SOLIDUS
1.588 mike 486: character (/).</li>
1.1 mike 487:
488: <li>The next few characters of an end tag must be the element's
489: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
490:
491: <li>After the tag name, there may be one or more <a href="infrastructure.html#space-character" title="space
492: character">space characters</a>.</li>
493:
1.588 mike 494: <li>Finally, end tags must be closed by a U+003E GREATER-THAN SIGN
495: character (>).</li>
1.1 mike 496:
1.614 mike 497: </ol><h5 id="attributes"><span class="secno">9.1.2.3 </span>Attributes</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p><dfn id="syntax-attributes" title="syntax-attributes">Attributes</dfn> for an element
1.123 mike 498: 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 499: one or more characters other than the <a href="infrastructure.html#space-character" title="space
500: character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
501: MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
502: (>), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters,
503: the control characters, and any characters that are not defined by
1.462 mike 504: Unicode. In the HTML syntax, attribute names, even those for
505: <a href="#foreign-elements">foreign elements</a>, may be written with any mix of lower-
506: and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.123 mike 507: 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 508: 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 509: 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 510:
511: <dd>
512:
513: <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
514: name</a>.</p>
515:
516: <div class="example">
517:
518: <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
519: the empty attribute syntax:</p>
520:
521: <pre><input <em>disabled</em>></pre>
522:
523: </div>
524:
525: <p>If an attribute using the empty attribute syntax is to be
526: followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
527: character</a> separating the two.</p>
528:
529: </dd>
530:
1.2 mike 531: <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1 mike 532:
533: <dd>
534:
535: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
536: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
537: characters</a>, followed by a single U+003D EQUALS SIGN
538: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
539: character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
540: addition to the requirements given above for attribute values,
541: must not contain any literal <a href="infrastructure.html#space-character" title="space character">space
1.588 mike 542: characters</a>, any U+0022 QUOTATION MARK characters ("),
543: U+0027 APOSTROPHE characters ('), U+003D EQUALS SIGN
544: characters (=), U+003C LESS-THAN SIGN characters (<), U+003E
545: GREATER-THAN SIGN characters (>), or U+0060 GRAVE ACCENT
546: characters (`), and must not be the empty string.</p>
1.463 mike 547:
548: <!-- The ` character is in this list on a temporary basis, waiting
549: for IE to fix it's parsing bug whereby it treats ` as an
550: attribute value delimiter. Otherwise, escaping software that
551: tries to be clever and not use quotes when it doesn't need to
552: could be tricked by an attacker.
553:
554: Posit a site that allows the user to input text that is used
555: verbatim in two attributes, such that the user can set the
556: first attribute's value to:
557:
558: `
559:
560: ...and the second to:
561:
562: ` onload='...payload...' end=x
563:
564: ...with the assumption that the site is going to not quote
565: the first one, and quote the second one with double quotes:
566:
567: <body title=` class="` onload='...payload...' end=x">
568:
569: In IE, this is treated as:
570:
571: <body title=' class="'
572: onload='...payload...'
573: end='x"'>
574:
575: -->
576:
1.1 mike 577:
578: <div class="example">
579:
580: <p>In the following example, the <code title="attr-input-value"><a href="forms.html#attr-input-value">value</a></code> attribute is given
581: with the unquoted attribute value syntax:</p>
582:
583: <pre><input <em>value=yes</em>></pre>
584:
585: </div>
586:
587: <p>If an attribute using the unquoted attribute syntax is to be
1.101 mike 588: followed by another attribute or by the optional U+002F SOLIDUS
1.464 mike 589: 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 590: must be a <a href="infrastructure.html#space-character">space character</a> separating the two.</p>
591:
592: </dd>
593:
594: <dt>Single-quoted attribute value syntax</dt>
595:
596: <dd>
597:
598: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
599: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
600: characters</a>, followed by a single U+003D EQUALS SIGN
601: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
602: character">space characters</a>, followed by a single U+0027
1.588 mike 603: APOSTROPHE character ('), followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
1.1 mike 604: addition to the requirements given above for attribute values,
1.588 mike 605: must not contain any literal U+0027 APOSTROPHE characters ('), and
606: finally followed by a second single U+0027 APOSTROPHE character
607: (').</p>
1.1 mike 608:
609: <div class="example">
610:
611: <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
612: single-quoted attribute value syntax:</p>
613:
614: <pre><input <em>type='checkbox'</em>></pre>
615:
616: </div>
617:
618: <p>If an attribute using the single-quoted attribute syntax is to
619: be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
620: character</a> separating the two.</p>
621:
622: </dd>
623:
624: <dt>Double-quoted attribute value syntax</dt>
625:
626: <dd>
627:
628: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
629: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
630: characters</a>, followed by a single U+003D EQUALS SIGN
631: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
632: character">space characters</a>, followed by a single U+0022
1.588 mike 633: QUOTATION MARK character ("), followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
1.1 mike 634: addition to the requirements given above for attribute values,
1.588 mike 635: must not contain any literal U+0022 QUOTATION MARK characters ("),
636: and finally followed by a second single U+0022 QUOTATION MARK
637: character (").</p>
1.1 mike 638:
639: <div class="example">
640:
641: <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
642: double-quoted attribute value syntax:</p>
643:
644: <pre><input <em>name="be evil"</em>></pre>
645:
646: </div>
647:
648: <p>If an attribute using the double-quoted attribute syntax is to
649: be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
650: character</a> separating the two.</p>
651:
652: </dd>
653:
654: </dl><p>There must never be two or more attributes on the same start tag
655: whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.462 mike 656: each other.</p><hr><p>When a <a href="#foreign-elements" title="foreign elements">foreign element</a> has
657: one of the namespaced attributes given by the local name and
658: namespace of the first and second cells of a row from the following
659: table, it must be written using the name given by the third cell
660: from the same row.</p><table><thead><tr><th> Local name </th><th> Namespace </th><th> Attribute name
661: </th></tr></thead><tbody><tr><td> <code title="">actuate</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:actuate</code>
662: </td></tr><tr><td> <code title="">arcrole</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:arcrole</code>
663: </td></tr><tr><td> <code title="">href</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:href</code>
664: </td></tr><tr><td> <code title="">role</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:role</code>
665: </td></tr><tr><td> <code title="">show</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:show</code>
666: </td></tr><tr><td> <code title="">title</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:title</code>
667: </td></tr><tr><td> <code title="">type</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:type</code>
668: </td></tr><tr><td> <code title="">base</code> </td><td> <a href="#xml-namespace">XML namespace</a> <!-- attr-xml-base --> </td><td> <code title="">xml:base</code>
669: </td></tr><tr><td> <code title="">lang</code> </td><td> <a href="#xml-namespace">XML namespace</a> </td><td> <code title="">xml:lang</code>
670: </td></tr><tr><td> <code title="">space</code> </td><td> <a href="#xml-namespace">XML namespace</a> </td><td> <code title="">xml:space</code>
671: </td></tr><tr><td> <code title="">xmlns</code> </td><td> <a href="#xmlns-namespace">XMLNS namespace</a> </td><td> <code title="">xmlns</code>
672: </td></tr><tr><td> <code title="">xlink</code> </td><td> <a href="#xmlns-namespace">XMLNS namespace</a> </td><td> <code title="">xmlns:xlink</code>
1.671 mike 673: </td></tr></tbody></table><p>No other namespaced attribute can be expressed in <a href="#syntax">the
1.614 mike 674: HTML syntax</a>.</p><h5 id="optional-tags"><span class="secno">9.1.2.4 </span>Optional tags</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><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 675: is not present; it is implied, but it is still there. An HTML
1.159 mike 676: document always has a root <code><a href="semantics.html#the-html-element-0">html</a></code> element, even if the
1.1 mike 677: string <code title=""><html></code> doesn't appear anywhere in
1.159 mike 678: 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
679: 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
680: tag</a> may be omitted if the <code><a href="semantics.html#the-html-element-0">html</a></code> element is not
681: 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 682: element is empty, or--> if the first thing inside the
1.159 mike 683: <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
684: tag</a> may be omitted if the <code><a href="semantics.html#the-head-element-0">head</a></code> element is not
685: 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
686: 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 687: 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 688: 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 689: <code><a href="semantics.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
690: tag is present, the parser makes <style> and <script> elements
691: between </head> and <body> end up in the <head> instead of implying
1.159 mike 692: 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
693: 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 694: 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 695: tag</a> may be omitted if the <code><a href="semantics.html#the-li-element">li</a></code> element is
696: immediately followed by another <code><a href="semantics.html#the-li-element">li</a></code> element or if there
1.422 mike 697: 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 698: tag</a> may be omitted if the <code><a href="semantics.html#the-dt-element">dt</a></code> element is
699: immediately followed by another <code><a href="semantics.html#the-dt-element">dt</a></code> element or a
1.123 mike 700: <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 701: tag</a> may be omitted if the <code><a href="semantics.html#the-dd-element">dd</a></code> element is
702: immediately followed by another <code><a href="semantics.html#the-dd-element">dd</a></code> element or a
703: <code><a href="semantics.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.123 mike 704: 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 705: tag</a> may be omitted if the <code><a href="semantics.html#the-p-element">p</a></code> element is
706: immediately followed by an <code><a href="semantics.html#the-address-element">address</a></code>,
707: <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 708: <!--v2DATAGRID <code>datagrid</code>,--> <code><a href="obsolete.html#dir">dir</a></code>,
1.306 mike 709: <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 710: <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>,
711: <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>,
712: <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>,
713: <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>,
714: <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 715: <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>,
716: element, or if there is no more content in the parent element and
1.123 mike 717: 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 718: tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element is
719: 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 720: 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 721: tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element is
722: 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 723: 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 724: <select>; commented out text below can handle the non-<select> case
1.123 mike 725: 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 726: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
727: <code>select</code> element and--> is immediately followed by
728: another <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
729: that are ancestors of the <code>optgroup</code> element, up to and
730: including the first ancestor element that is not an
731: <code>optgroup</code> element, have no more content--> there is no
1.123 mike 732: more content in the parent element.</p><!-- so e.g. the max number of </optgroup>s are omitted here:
1.1 mike 733: <select><optgroup></select>
734: <p id=x><optgroup></optgroup>x</p>
735: <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
736: <p><optgroup id=x><optgroup></optgroup>x</p>
737: <p><optgroup><optgroup id=x>x</p>
1.123 mike 738: --><!-- </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 739: tag</a> may be omitted if the <code><a href="forms.html#the-option-element">option</a></code> element is
740: immediately followed by another <code><a href="forms.html#the-option-element">option</a></code> element, or if
741: it is immediately followed by an <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or
1.123 mike 742: 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 743: first thing inside the <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is a
744: <code><a href="tabular-data.html#the-col-element">col</a></code> element, and if the element is not immediately
745: 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 746: 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 747: <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.123 mike 748: <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 749: tag</a> may be omitted if the <code><a href="tabular-data.html#the-thead-element">thead</a></code> element is
750: 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 751: 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 752: first thing inside the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is a
753: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, and if the element is not immediately
754: 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
755: <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
756: tag</a> has been omitted. (It can't be omitted if the element is
1.123 mike 757: 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 758: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is
759: 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 760: 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 761: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element is
762: immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, or if there is
1.123 mike 763: 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 764: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
765: immediately followed by another <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, or if there
1.123 mike 766: 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 767: tag</a> may be omitted if the <code><a href="tabular-data.html#the-td-element">td</a></code> element is
768: 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 769: 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 770: tag</a> may be omitted if the <code><a href="tabular-data.html#the-th-element">th</a></code> element is
771: 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 772: 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
1.614 mike 773: 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 class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p>For historical reasons, certain elements have extra restrictions
1.123 mike 774: 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 775: elements, even though these elements are technically allowed inside
776: <code><a href="tabular-data.html#the-table-element">table</a></code> elements according to the content models
777: described in this specification. (If a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
778: 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 779: 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
780: placed immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
1.1 mike 781: 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>
782: elements. This does not affect the processing of the element. The
1.304 mike 783: otherwise optional <a href="#syntax-newlines" title="syntax-newlines">newline</a>
1.381 mike 784: <em>must</em> be included if the element's contents themselves start
785: with a <a href="#syntax-newlines" title="syntax-newlines">newline</a> (because
786: otherwise the leading newline in the contents would be treated like
787: the optional newline, and ignored).</p><div class="example">
1.1 mike 788: <p>The following two <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
789: <pre><pre>Hello</pre></pre>
790: <pre><pre><br>Hello</pre></pre>
1.614 mike 791: </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 class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p>The text in <a href="#raw-text-elements" title="raw text elements">raw text</a> and
1.373 mike 792: <a href="#rcdata-elements" title="RCDATA elements">RCDATAs</a> element must not
793: contain any occurrences of the string "<code title=""></</code>"
794: (U+003C LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that
1.1 mike 795: case-insensitively match the tag name of the element followed by one
796: of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM
1.304 mike 797: FEED (FF), U+000D CARRIAGE RETURN (CR), U+0020 SPACE, U+003E
1.614 mike 798: GREATER-THAN SIGN (>), or U+002F SOLIDUS (/).</p><h4 id="text-0"><span class="secno">9.1.3 </span>Text</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p><dfn id="syntax-text" title="syntax-text">Text</dfn> is allowed inside elements,
1.1 mike 799: attributes, and comments. Text must consist of Unicode characters.
800: Text must not contain U+0000 characters. Text must not contain
1.316 mike 801: permanently undefined Unicode characters (noncharacters). Text must
802: not contain control characters other than <a href="infrastructure.html#space-character" title="space
803: character">space characters</a>. Extra constraints are placed on
804: what is and what is not allowed in text based on where the text is
1.614 mike 805: to be put, as described in the other sections.</p><h5 id="newlines"><span class="secno">9.1.3.1 </span>Newlines</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p><dfn id="syntax-newlines" title="syntax-newlines">Newlines</dfn> in HTML may be
1.1 mike 806: represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A
807: LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR),
1.614 mike 808: 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 class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><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 809: to escape characters that couldn't otherwise legally be included in
1.588 mike 810: <a href="#syntax-text" title="syntax-text">text</a>.</p><p>Character references must start with a U+0026 AMPERSAND character
811: (&). Following this, there are three possible kinds of character
812: references:</p><dl><dt>Named character references</dt>
1.1 mike 813:
814: <dd>The ampersand must be followed by one of the names given in the
815: <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
1.677 mike 816: case. <span class="impl">The name must be one that is terminated by
817: a U+003B SEMICOLON character (;).</span></dd>
1.1 mike 818:
819:
820: <dt>Decimal numeric character reference</dt>
821:
822: <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
1.588 mike 823: character (#), followed by one or more digits in the range U+0030
824: DIGIT ZERO (0) to U+0039 DIGIT NINE (9), representing a base-ten
825: integer that corresponds to a Unicode code point that is allowed
826: according to the definition below. The digits must then be followed
827: by a U+003B SEMICOLON character (;).</dd>
1.1 mike 828:
829:
830: <dt>Hexadecimal numeric character reference</dt>
831:
832: <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
1.588 mike 833: character (#), which must be followed by either a U+0078 LATIN
834: SMALL LETTER X character (x) or a U+0058 LATIN CAPITAL LETTER X
835: character (X), which must then be followed by one or more digits in
836: the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), U+0061
837: LATIN SMALL LETTER A to U+0066 LATIN SMALL LETTER F, and U+0041
838: LATIN CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F,
1.464 mike 839: representing a base-sixteen integer that corresponds to a Unicode
840: code point that is allowed according to the definition below. The
841: digits must then be followed by a U+003B SEMICOLON character
842: (;).</dd>
1.378 mike 843:
844: </dl><p>The numeric character reference forms described above are allowed
845: to reference any Unicode code point other than U+0000, permanently
846: undefined Unicode characters (noncharacters), and control characters
847: other than <a href="infrastructure.html#space-character" title="space character">space
848: characters</a>.</p><p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.464 mike 849: ampersand</dfn> is a U+0026 AMPERSAND character (&) that is
850: followed by some <a href="#syntax-text" title="syntax-text">text</a> other than a
851: <a href="infrastructure.html#space-character">space character</a>, a U+003C LESS-THAN SIGN character
1.614 mike 852: (<), or another U+0026 AMPERSAND character (&).</p><h4 id="cdata-sections"><span class="secno">9.1.5 </span>CDATA sections</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p><dfn id="syntax-cdata" title="syntax-cdata">CDATA sections</dfn> must start with
1.1 mike 853: the character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
854: MARK, U+005B LEFT SQUARE BRACKET, U+0043 LATIN CAPITAL LETTER C,
855: U+0044 LATIN CAPITAL LETTER D, U+0041 LATIN CAPITAL LETTER A, U+0054
856: LATIN CAPITAL LETTER T, U+0041 LATIN CAPITAL LETTER A, U+005B LEFT
857: SQUARE BRACKET (<code title=""><![CDATA[</code>). Following this
858: sequence, the CDATA section may have <a href="#syntax-text" title="syntax-text">text</a>, with the additional restriction
859: that the text must not contain the three character sequence U+005D
860: RIGHT SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E
861: GREATER-THAN SIGN (<code title="">]]></code>). Finally, the CDATA
862: section must be ended by the three character sequence U+005D RIGHT
863: SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E GREATER-THAN
1.614 mike 864: 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>Last call for comments</i></p><p><dfn id="syntax-comments" title="syntax-comments">Comments</dfn> must start with the
1.1 mike 865: four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
866: MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title=""><!--</code>). Following this sequence, the comment may
867: have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
868: restriction that the text must not start with a single U+003E
1.588 mike 869: GREATER-THAN SIGN character (>), nor start with a U+002D
870: HYPHEN-MINUS character (-) followed by a U+003E GREATER-THAN SIGN
871: (>) character, nor contain two consecutive U+002D HYPHEN-MINUS
872: characters (<code title="">--</code>), nor end with a U+002D
873: HYPHEN-MINUS character (-). Finally, the comment must be ended by
1.1 mike 874: the three character sequence U+002D HYPHEN-MINUS, U+002D
1.123 mike 875: HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--></code>).</p><div class="impl">
1.1 mike 876:
1.159 mike 877: <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 878:
879: <p><i>This section only applies to user agents, data mining tools,
880: and conformance checkers.</i></p>
881:
882: <p class="note">The rules for parsing XML documents into DOM trees
883: are covered by the next section, entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
884: syntax</a>".</p>
885:
886: <p>For <a href="dom.html#html-documents">HTML documents</a>, user agents must use the parsing
887: rules described in this section to generate the DOM trees. Together,
888: these rules define what is referred to as the <dfn id="html-parser">HTML
889: parser</dfn>.</p>
890:
891: <div class="note">
892:
893: <p>While the HTML syntax described in this specification bears a
894: close resemblance to SGML and XML, it is a separate language with
895: its own parsing rules.</p>
896:
1.183 mike 897: <p>Some earlier versions of HTML (in particular from HTML2 to
898: HTML4) were based on SGML and used SGML parsing rules. However, few
1.1 mike 899: (if any) web browsers ever implemented true SGML parsing for HTML
900: documents; the only user agents to strictly handle HTML as an SGML
901: application have historically been validators. The resulting
902: confusion — with validators claiming documents to have one
903: representation while widely deployed Web browsers interoperably
904: implemented a different representation — has wasted decades
905: of productivity. This version of HTML thus returns to a non-SGML
906: basis.</p>
907:
908: <p>Authors interested in using SGML tools in their authoring
909: pipeline are encouraged to use XML tools and the XML serialization
910: of HTML.</p>
911:
912: </div>
913:
914: <p>This specification defines the parsing rules for HTML documents,
915: whether they are syntactically correct or not. Certain points in the
916: parsing algorithm are said to be <dfn id="parse-error" title="parse error">parse
917: errors</dfn>. The error handling for parse errors is well-defined:
918: user agents must either act as described below when encountering
919: such problems, or must abort processing at the first error that they
920: encounter for which they do not wish to apply the rules described
921: below.</p>
922:
923: <p>Conformance checkers must report at least one parse error
924: condition to the user if one or more parse error conditions exist in
925: the document and must not report parse error conditions if none
926: exist in the document. Conformance checkers may report more than one
1.174 mike 927: parse error condition if more than one parse error condition exists
1.1 mike 928: in the document. Conformance checkers are not required to recover
929: from parse errors.</p>
930:
931: <p class="note">Parse errors are only errors with the
932: <em>syntax</em> of HTML. In addition to checking for parse errors,
933: conformance checkers will also verify that the document obeys all
934: the other conformance requirements described in this
935: specification.</p>
936:
937: <p>For the purposes of conformance checkers, if a resource is
938: determined to be in <a href="#syntax">the HTML syntax</a>, then it is an
939: <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
940:
1.266 mike 941: </div><div class="impl">
1.1 mike 942:
1.614 mike 943: <h4 id="overview-of-the-parsing-model"><span class="secno">9.2.1 </span>Overview of the parsing model</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 944:
945: <p>The input to the HTML parsing process consists of a stream of
946: Unicode characters, which is passed through a
947: <a href="#tokenization">tokenization</a> stage followed by a <a href="#tree-construction">tree
948: construction</a> stage. The output is a <code>Document</code>
949: object.</p>
950:
951: <p class="note">Implementations that <a href="infrastructure.html#non-scripted">do not
952: support scripting</a> do not have to actually create a DOM
953: <code>Document</code> object, but the DOM tree in such cases is
954: still used as the model for the rest of the specification.</p>
955:
956: <p>In the common case, the data handled by the tokenization stage
1.159 mike 957: comes from the network, but <a href="embedded-content-0.html#dynamic-markup-insertion" title="dynamic markup
958: 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 959:
960: <p><img alt="" src="images/parsing-model-overview.png"></p>
961:
962: <p id="nestedParsing">There is only one set of states for the
963: tokenizer stage and the tree construction stage, but the tree
964: construction stage is reentrant, meaning that while the tree
965: construction stage is handling one token, the tokenizer might be
966: resumed, causing further tokens to be emitted and processed before
967: the first token's processing is complete.</p>
968:
969: <div class="example">
970:
971: <p>In the following example, the tree construction stage will be
972: called upon to handle a "p" start tag token while handling the
973: "script" start tag token:</p>
974:
975: <pre>...
976: <script>
977: document.write('<p>');
978: </script>
979: ...</pre>
980:
981: </div>
982:
983: <p>To handle these cases, parsers have a <dfn id="script-nesting-level">script nesting
984: level</dfn>, which must be initially set to zero, and a <dfn id="parser-pause-flag">parser
985: pause flag</dfn>, which must be initially set to false.</p>
986:
1.266 mike 987: </div><div class="impl">
1.1 mike 988:
1.614 mike 989: <h4 id="the-input-stream"><span class="secno">9.2.2 </span>The <dfn>input stream</dfn></h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 990:
991: <p>The stream of Unicode characters that comprises the input to the
992: tokenization stage will be initially seen by the user agent as a
993: stream of bytes (typically coming over the network or from the local
994: file system). The bytes encode the actual characters according to a
995: particular <em>character encoding</em>, which the user agent must
996: use to decode the bytes into characters.</p>
997:
998: <p class="note">For XML documents, the algorithm user agents must
999: use to determine the character encoding is given by the XML
1.104 mike 1000: specification. This section does not apply to XML documents. <a href="references.html#refsXML">[XML]</a></p>
1.1 mike 1001:
1002:
1.614 mike 1003: <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>Last call for comments</i></p>
1.1 mike 1004:
1005: <p>In some cases, it might be impractical to unambiguously determine
1006: the encoding before parsing the document. Because of this, this
1007: specification provides for a two-pass mechanism with an optional
1008: pre-scan. Implementations are allowed, as described below, to apply
1009: a simplified parsing algorithm to whatever bytes they have available
1010: before beginning to parse the document. Then, the real parser is
1011: started, using a tentative encoding derived from this pre-parse and
1012: other out-of-band metadata. If, while the document is being loaded,
1013: the user agent discovers an encoding declaration that conflicts with
1014: this information, then the parser can get reinvoked to perform a
1015: parse of the document with the real encoding.</p>
1016:
1017: <p id="documentEncoding">User agents must use the following
1018: algorithm (the <dfn id="encoding-sniffing-algorithm">encoding sniffing algorithm</dfn>) to determine
1019: the character encoding to use when decoding a document in the first
1020: pass. This algorithm takes as input any out-of-band metadata
1021: available to the user agent (e.g. the <a href="infrastructure.html#content-type" title="Content-Type">Content-Type metadata</a> of the document)
1022: and all the bytes available so far, and returns an encoding and a
1023: <dfn id="concept-encoding-confidence" title="concept-encoding-confidence">confidence</dfn>. The
1024: confidence is either <i>tentative</i>, <i>certain</i>, or
1025: <i>irrelevant</i>. The encoding used, and whether the confidence in
1026: that encoding is <i>tentative</i> or <i>certain</i>, is <a href="#meta-charset-during-parse">used during the parsing</a> to
1027: determine whether to <a href="#change-the-encoding">change the encoding</a>. If no
1028: encoding is necessary, e.g. because the parser is operating on a
1029: stream of Unicode characters and doesn't have to use an encoding at
1030: all, then the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
1031: <i>irrelevant</i>.</p>
1032:
1033: <ol><li><p>If the transport layer specifies an encoding, and it is
1034: supported, return that encoding with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1035: <i>certain</i>, and abort these steps.</p></li>
1036:
1037: <li><p>The user agent may wait for more bytes of the resource to be
1038: available, either in this step or at any later step in this
1039: algorithm. For instance, a user agent might wait 500ms or 512
1040: bytes, whichever came first. In general preparsing the source to
1041: find the encoding improves performance, as it reduces the need to
1042: throw away the data structures used when parsing upon finding the
1043: encoding information. However, if the user agent delays too long to
1044: obtain data to determine the encoding, then the cost of the delay
1045: could outweigh any performance improvements from the
1046: preparse.</p></li>
1047:
1048: <li><p>For each of the rows in the following table, starting with
1049: the first one and going down, if there are as many or more bytes
1050: available than the number of bytes in the first column, and the
1051: first bytes of the file match the bytes given in the first column,
1052: then return the encoding given in the cell in the second column of
1053: that row, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1054: <i>certain</i>, and abort these steps:</p>
1055:
1056: <!-- this table is present in several forms in this file; keep them in sync -->
1057: <table><thead><tr><th>Bytes in Hexadecimal
1058: </th><th>Encoding
1059: </th></tr></thead><tbody><!-- nobody uses this
1060: <tr>
1061: <td>00 00 FE FF
1062: <td>UTF-32BE
1063: <tr>
1064: <td>FF FE 00 00
1065: <td>UTF-32LE
1066: --><tr><td>FE FF
1067: </td><td>UTF-16BE
1068: </td></tr><tr><td>FF FE
1069: </td><td>UTF-16LE
1070: </td></tr><tr><td>EF BB BF
1071: </td><td>UTF-8
1072: <!-- nobody uses this
1073: <tr>
1074: <td>DD 73 66 73
1075: <td>UTF-EBCDIC
1076: -->
1077: </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
1078: (BOMs).</p></li>
1079:
1080: <li><p>Otherwise, the user agent will have to search for explicit
1081: character encoding information in the file itself. This should
1082: proceed as follows:
1083:
1084: </p><p>Let <var title="">position</var> be a pointer to a byte in the
1085: input stream, initially pointing at the first byte. If at any
1086: point during these substeps the user agent either runs out of
1087: bytes or decides that scanning further bytes would not be
1088: efficient, then skip to the next step of the overall character
1089: encoding detection algorithm. User agents may decide that scanning
1090: <em>any</em> bytes is not efficient, in which case these substeps
1091: are entirely skipped.</p>
1092:
1093: <p>Now, repeat the following "two" steps until the algorithm
1094: aborts (either because user agent aborts, as described above, or
1095: because a character encoding is found):</p>
1096:
1097: <ol><li><p>If <var title="">position</var> points to:</p>
1098:
1099: <dl class="switch"><dt>A sequence of bytes starting with: 0x3C 0x21 0x2D 0x2D (ASCII '<!--')</dt>
1100: <dd>
1101:
1102: <p>Advance the <var title="">position</var> pointer so that it
1103: points at the first 0x3E byte which is preceded by two 0x2D
1104: bytes (i.e. at the end of an ASCII '-->' sequence) and comes
1105: after the 0x3C byte that was found. (The two 0x2D bytes can be
1106: the same as the those in the '<!--' sequence.)</p>
1107:
1108: </dd>
1109:
1110: <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>
1111: <dd>
1112:
1113: <ol><li><p>Advance the <var title="">position</var> pointer so
1114: that it points at the next 0x09, 0x0A, 0x0C, 0x0D, 0x20, or
1115: 0x2F byte (the one in sequence of characters matched
1116: above).</p></li>
1117:
1118: <li><p><a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">Get
1119: an attribute</a> and its value. If no attribute was
1120: sniffed, then skip this inner set of steps, and jump to the
1121: second step in the overall "two step" algorithm.</p></li>
1122:
1123: <li><p>If the attribute's name is neither "<code title="">charset</code>" nor "<code title="">content</code>",
1124: then return to step 2 in these inner steps.</p></li>
1125:
1126: <li><p>If the attribute's name is "<code title="">charset</code>", let <var title="">charset</var> be
1127: the attribute's value, interpreted as a character
1128: encoding.</p></li>
1129:
1130: <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
1131: extracting an encoding from a Content-Type</a>, giving the
1132: attribute's value as the string to parse. If an encoding is
1133: returned, let <var title="">charset</var> be that
1134: encoding. Otherwise, return to step 2 in these inner
1135: steps.</p></li>
1136:
1137: <li><p>If <var title="">charset</var> is a UTF-16 encoding,
1138: change the value of <var title="">charset</var> to
1139: UTF-8.</p></li>
1140:
1141: <li><p>If <var title="">charset</var> is a supported
1142: character encoding, then return the given encoding, with
1143: <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1144: <i>tentative</i>, and abort all these steps.</p></li>
1145:
1146: <li><p>Otherwise, return to step 2 in these inner
1147: steps.</p></li>
1148:
1149: </ol></dd>
1150:
1.464 mike 1151: <dt>A sequence of bytes starting with a 0x3C byte (ASCII <), optionally a 0x2F byte (ASCII /), and finally a byte in the range 0x41-0x5A or 0x61-0x7A (an ASCII letter)</dt>
1.1 mike 1152: <dd>
1153:
1154: <ol><li><p>Advance the <var title="">position</var> pointer so
1155: that it points at the next 0x09 (ASCII TAB), 0x0A (ASCII LF),
1156: 0x0C (ASCII FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E
1.464 mike 1157: (ASCII >) byte.</p></li>
1.1 mike 1158:
1159: <li><p>Repeatedly <a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
1160: attribute</a> until no further attributes can be found,
1161: then jump to the second step in the overall "two step"
1162: algorithm.</p></li>
1163:
1164: </ol></dd>
1165:
1166: <dt>A sequence of bytes starting with: 0x3C 0x21 (ASCII '<!')</dt>
1167: <dt>A sequence of bytes starting with: 0x3C 0x2F (ASCII '</')</dt>
1168: <dt>A sequence of bytes starting with: 0x3C 0x3F (ASCII '<?')</dt>
1169: <dd>
1170:
1171: <p>Advance the <var title="">position</var> pointer so that it
1.464 mike 1172: points at the first 0x3E byte (ASCII >) that comes after the
1.1 mike 1173: 0x3C byte that was found.</p>
1174:
1175: </dd>
1176:
1177: <dt>Any other byte</dt>
1178: <dd>
1179:
1180: <p>Do nothing with that byte.</p>
1181:
1182: </dd>
1183:
1184: </dl></li>
1185:
1186: <li>Move <var title="">position</var> so it points at the next
1187: byte in the input stream, and return to the first step of this
1188: "two step" algorithm.</li>
1189:
1190: </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
1191: attribute</dfn>, it means doing this:</p>
1192:
1193: <ol><li><p>If the byte at <var title="">position</var> is one of 0x09
1194: (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII FF), 0x0D (ASCII CR),
1.464 mike 1195: 0x20 (ASCII space), or 0x2F (ASCII /) then advance <var title="">position</var> to the next byte and redo this
1.1 mike 1196: substep.</p></li>
1197:
1198: <li><p>If the byte at <var title="">position</var> is 0x3E (ASCII
1.464 mike 1199: >), then abort the "get an attribute" algorithm. There isn't
1.1 mike 1200: one.</p></li>
1201:
1202: <li><p>Otherwise, the byte at <var title="">position</var> is the
1203: start of the attribute name. Let <var title="">attribute
1204: name</var> and <var title="">attribute value</var> be the empty
1205: string.</p></li>
1206:
1207: <li><p><i>Attribute name</i>: Process the byte at <var title="">position</var> as follows:</p>
1208:
1.464 mike 1209: <dl class="switch"><dt>If it is 0x3D (ASCII =), and the <var title="">attribute
1.1 mike 1210: name</var> is longer than the empty string</dt>
1211:
1212: <dd>Advance <var title="">position</var> to the next byte and
1213: jump to the step below labeled <i>value</i>.</dd>
1214:
1215: <dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
1216: FF), 0x0D (ASCII CR), or 0x20 (ASCII space)</dt>
1217:
1218: <dd>Jump to the step below labeled <i>spaces</i>.</dd>
1219:
1.464 mike 1220: <dt>If it is 0x2F (ASCII /) or 0x3E (ASCII >)</dt>
1.1 mike 1221:
1222: <dd>Abort the "get an attribute" algorithm. The attribute's
1223: name is the value of <var title="">attribute name</var>, its
1224: value is the empty string.</dd>
1225:
1.464 mike 1226: <dt>If it is in the range 0x41 (ASCII A) to 0x5A (ASCII
1227: Z)</dt>
1.1 mike 1228:
1229: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1230: name</var> (where <var title="">b</var> is the value of the
1231: byte at <var title="">position</var>).</dd>
1232:
1233: <dt>Anything else</dt>
1234:
1235: <dd>Append the Unicode character with the same code point as the
1236: value of the byte at <var title="">position</var>) to <var title="">attribute name</var>. (It doesn't actually matter how
1237: bytes outside the ASCII range are handled here, since only
1238: ASCII characters can contribute to the detection of a character
1239: encoding.)</dd>
1240:
1241: </dl></li>
1242:
1243: <li><p>Advance <var title="">position</var> to the next byte and
1244: return to the previous step.</p></li>
1245:
1246: <li><p><i>Spaces</i>: If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
1247: LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
1248: advance <var title="">position</var> to the next byte, then,
1249: repeat this step.</p></li>
1250:
1251: <li><p>If the byte at <var title="">position</var> is
1.464 mike 1252: <em>not</em> 0x3D (ASCII =), abort the "get an attribute"
1.1 mike 1253: algorithm. The attribute's name is the value of <var title="">attribute name</var>, its value is the empty
1254: string.</p></li>
1255:
1256: <li><p>Advance <var title="">position</var> past the 0x3D (ASCII
1.464 mike 1257: =) byte.</p></li>
1.1 mike 1258:
1259: <li><p><i>Value:</i> If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
1260: LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
1261: advance <var title="">position</var> to the next byte, then,
1262: repeat this step.</p></li>
1263:
1264: <li><p>Process the byte at <var title="">position</var> as
1265: follows:</p>
1266:
1.464 mike 1267: <dl class="switch"><dt>If it is 0x22 (ASCII ") or 0x27 (ASCII ')</dt>
1.1 mike 1268:
1269: <dd>
1270:
1271: <ol><li>Let <var title="">b</var> be the value of the byte at
1272: <var title="">position</var>.</li>
1273:
1274: <li>Advance <var title="">position</var> to the next
1275: byte.</li>
1276:
1277: <li>If the value of the byte at <var title="">position</var>
1278: is the value of <var title="">b</var>, then advance <var title="">position</var> to the next byte and abort the "get
1279: an attribute" algorithm. The attribute's name is the value of
1280: <var title="">attribute name</var>, and its value is the
1281: value of <var title="">attribute value</var>.</li>
1282:
1.464 mike 1283: <li>Otherwise, if the value of the byte at <var title="">position</var> is in the range 0x41 (ASCII A) to
1284: 0x5A (ASCII Z), then append a Unicode character to <var title="">attribute value</var> whose code point is 0x20 more
1.1 mike 1285: than the value of the byte at <var title="">position</var>.</li>
1286:
1287: <li>Otherwise, append a Unicode character to <var title="">attribute value</var> whose code point is the same as
1288: the value of the byte at <var title="">position</var>.</li>
1289:
1290: <li>Return to the second step in these substeps.</li>
1291:
1292: </ol></dd>
1293:
1.464 mike 1294: <dt>If it is 0x3E (ASCII >)</dt>
1.1 mike 1295:
1296: <dd>Abort the "get an attribute" algorithm. The attribute's
1297: name is the value of <var title="">attribute name</var>, its
1298: value is the empty string.</dd>
1299:
1300:
1.464 mike 1301: <dt>If it is in the range 0x41 (ASCII A) to 0x5A (ASCII
1302: Z)</dt>
1.1 mike 1303:
1304: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1305: value</var> (where <var title="">b</var> is the value of the
1306: byte at <var title="">position</var>). Advance <var title="">position</var> to the next byte.</dd>
1307:
1308: <dt>Anything else</dt>
1309:
1310: <dd>Append the Unicode character with the same code point as the
1311: 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>
1312:
1313: </dl></li>
1314:
1315: <li><p>Process the byte at <var title="">position</var> as
1316: follows:</p>
1317:
1318: <dl class="switch"><dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
1319: FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E (ASCII
1.464 mike 1320: >)</dt>
1.1 mike 1321:
1322: <dd>Abort the "get an attribute" algorithm. The attribute's
1323: name is the value of <var title="">attribute name</var> and its
1324: value is the value of <var title="">attribute value</var>.</dd>
1325:
1.464 mike 1326: <dt>If it is in the range 0x41 (ASCII A) to 0x5A (ASCII
1327: Z)</dt>
1.1 mike 1328:
1329: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1330: value</var> (where <var title="">b</var> is the value of the
1331: byte at <var title="">position</var>).</dd>
1332:
1333: <dt>Anything else</dt>
1334:
1335: <dd>Append the Unicode character with the same code point as the
1336: value of the byte at <var title="">position</var>) to <var title="">attribute value</var>.</dd>
1337:
1338: </dl></li>
1339:
1340: <li><p>Advance <var title="">position</var> to the next byte and
1341: return to the previous step.</p></li>
1342:
1343: </ol><p>For the sake of interoperability, user agents should not use a
1344: pre-scan algorithm that returns different results than the one
1345: described above. (But, if you do, please at least let us know, so
1346: that we can improve this algorithm and benefit everyone...)</p>
1347:
1348: </li>
1349:
1350: <li><p>If the user agent has information on the likely encoding for
1351: this page, e.g. based on the encoding of the page when it was last
1352: visited, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1353: <i>tentative</i>, and abort these steps.</p></li>
1354:
1.322 mike 1355: <li>
1356:
1357: <p>The user agent may attempt to autodetect the character encoding
1358: from applying frequency analysis or other algorithms to the data
1.568 mike 1359: stream. Such algorithms may use information about the resource
1360: other than the resource's contents, including the address of the
1361: resource. If autodetection succeeds in determining a character
1.322 mike 1362: encoding, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1363: <i>tentative</i>, and abort these steps. <a href="references.html#refsUNIVCHARDET">[UNIVCHARDET]</a></p>
1364:
1365: <p class="note">The UTF-8 encoding has a highly detectable bit
1366: pattern. Documents that contain bytes with values greater than
1367: 0x7F which match the UTF-8 pattern are very likely to be UTF-8,
1368: while documents with byte sequences that do not match it are very
1369: likely not. User-agents are therefore encouraged to search for
1.485 mike 1370: this common encoding. <a href="references.html#refsPPUTF8">[PPUTF8]</a> <a href="references.html#refsUTF8DET">[UTF8DET]</a></p>
1.322 mike 1371:
1372: </li>
1.1 mike 1373:
1.501 mike 1374: <li>
1375:
1376: <p>Otherwise, return an implementation-defined or user-specified
1377: default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1378: <i>tentative</i>.</p>
1379:
1380: <p>In controlled environments or in environments where the
1381: encoding of documents can be prescribed (for example, for user
1382: agents intended for dedicated use in new networks), the
1383: comprehensive <code title="">UTF-8</code> encoding is
1384: suggested.</p>
1385:
1386: <p>In other environments, the default encoding is typically
1387: dependent on the user's locale (an approximation of the languages,
1388: and thus typically encodings, of the pages that the user is likely
1389: to frequent). The following table gives suggested defaults based
1.504 mike 1390: on the user's locale, for compatibility with legacy
1391: content. Locales are identified by BCP 47 language codes. <a href="references.html#refsBCP47">[BCP47]</a></p>
1.501 mike 1392:
1393: <!-- based on mozilla 1.9.1 localizations:
1394: http://mxr.mozilla.org/l10n-mozilla1.9.1/find?string=global%2Fintl.properties&tree=l10n-mozilla1.9.1&hint= -->
1395:
1.504 mike 1396: <table><thead><tr><th>Locale language
1.501 mike 1397: </th><th>Suggested default encoding
1398: </th></tr></thead><tbody><tr><td>ar
1399: </td><td>UTF-8
1400:
1401: </td></tr><tr><td>be
1402: </td><td>ISO-8859-5
1403:
1404: </td></tr><tr><td>bg
1405: </td><td>windows-1251
1406:
1407: </td></tr><tr><td>cs<!-- -CZ -->
1408: </td><td>ISO-8859-2
1409:
1410: </td></tr><tr><td>cy
1411: </td><td>UTF-8
1412:
1413: </td></tr><tr><td>fa<!-- -IR -->
1414: </td><td>UTF-8
1415:
1416: </td></tr><tr><td>he<!-- -IL -->
1417: </td><td>windows-1255
1418:
1419: </td></tr><tr><td>hr
1420: </td><td>UTF-8
1421:
1422: </td></tr><tr><td>hu<!-- -HU -->
1423: </td><td>ISO-8859-2
1424:
1425: </td></tr><tr><td>ja <!-- and ja-JP-mac -->
1426: </td><td>windows-31J <!-- Shift_JIS -->
1427:
1428: </td></tr><tr><td>kk
1429: </td><td>UTF-8
1430:
1431: </td></tr><tr><td>ko<!-- -KR -->
1432: </td><td>windows-949 <!-- EUC-KR -->
1433:
1434: </td></tr><tr><td>ku
1435: </td><td>windows-1254 <!-- ISO-8859-9 -->
1436:
1437: </td></tr><tr><td>lt
1438: </td><td>windows-1257
1439:
1440: </td></tr><tr><td>lv<!-- -LV -->
1441: </td><td>ISO-8859-13
1442:
1443: </td></tr><tr><td>mk<!-- -MK -->
1444: </td><td>UTF-8
1445:
1446: </td></tr><tr><td>or
1447: </td><td>UTF-8
1448:
1449: </td></tr><tr><td>pl<!-- -PL -->
1450: </td><td>ISO-8859-2
1451:
1452: </td></tr><tr><td>ro
1453: </td><td>UTF-8
1454:
1455: </td></tr><tr><td>ru
1456: </td><td>windows-1251
1457:
1458: </td></tr><tr><td>sk
1459: </td><td>windows-1250
1460:
1461: </td></tr><tr><td>sl
1462: </td><td>ISO-8859-2
1463:
1464: </td></tr><tr><td>sr
1465: </td><td>UTF-8
1466:
1467: </td></tr><tr><td>th
1468: </td><td>windows-874 <!-- TIS-620 -->
1469:
1470: </td></tr><tr><td>tr<!-- -TR -->
1471: </td><td>windows-1254 <!-- ISO-8859-9 -->
1472:
1.503 mike 1473: </td></tr><tr><td>uk
1.501 mike 1474: </td><td>windows-1251
1475:
1476: </td></tr><tr><td>vi
1477: </td><td>UTF-8
1478:
1479: </td></tr><tr><td>zh-CN
1480: </td><td>GB18030
1481:
1482: </td></tr><tr><td>zh-TW
1483: </td><td>Big5
1484:
1485: </td></tr><tr><td>All other locales
1486: </td><td>windows-1252
1487:
1488: </td></tr></tbody></table></li>
1.1 mike 1489:
1490: </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
1491: be set to the value returned from this algorithm, at the same time
1492: as the user agent uses the returned value to select the decoder to
1493: use for the input stream.</p>
1494:
1.582 mike 1495: <p class="note">This algorithm is a <a href="introduction.html#willful-violation">willful violation</a>
1496: of the HTTP specification, which requires that the encoding be
1497: assumed to be ISO-8859-1 in the absence of a <a href="semantics.html#character-encoding-declaration">character
1.647 mike 1498: encoding declaration</a> to the contrary, and of RFC 2046,
1.582 mike 1499: which requires that the encoding be assumed to be US-ASCII in the
1500: absence of a <a href="semantics.html#character-encoding-declaration">character encoding declaration</a> to the
1501: contrary. This specification's third approach is motivated by a
1502: desire to be maximally compatible with legacy content. <a href="references.html#refsHTTP">[HTTP]</a> <a href="references.html#refsRFC2046">[RFC2046]</a></p>
1503:
1.1 mike 1504:
1.614 mike 1505: <h5 id="character-encodings-0"><span class="secno">9.2.2.2 </span>Character encodings</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 1506:
1.237 mike 1507: <p>User agents must at a minimum support the UTF-8 and Windows-1252
1508: encodings, but may support more.</p>
1509:
1510: <p class="note">It is not unusual for Web browsers to support dozens
1511: if not upwards of a hundred distinct character encodings.</p>
1512:
1.365 mike 1513: <p>User agents must support the <a href="infrastructure.html#preferred-mime-name">preferred MIME name</a> of
1514: every character encoding they support, and should support all the
1515: IANA-registered names and aliases of every character encoding they
1516: support. <a href="references.html#refsIANACHARSET">[IANACHARSET]</a></p>
1.237 mike 1517:
1518: <p>When comparing a string specifying a character encoding with the
1519: name or alias of a character encoding to determine if they are
1520: 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
1521: then perform the comparison in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1522: case-insensitive</a> manner.</p>
1523:
1.539 mike 1524: <hr><p>When a user agent would otherwise use an encoding given in the
1.237 mike 1525: first column of the following table to either convert content to
1526: Unicode characters or convert Unicode characters to bytes, it must
1527: instead use the encoding given in the cell in the second column of
1528: the same row. When a byte or sequence of bytes is treated
1529: differently due to this encoding aliasing, it is said to have been
1530: <dfn id="misinterpreted-for-compatibility">misinterpreted for compatibility</dfn>.</p>
1531:
1532: <table><caption>Character encoding overrides</caption>
1533: <thead><tr><th> Input encoding </th><th> Replacement encoding </th><th> References
1534: </th></tr></thead><tbody><!-- how about EUC-JP? --><tr><td> EUC-KR </td><td> windows-949 </td><td>
1535: <a href="references.html#refsEUCKR">[EUCKR]</a>
1536: <a href="references.html#refsWIN949">[WIN949]</a>
1537: </td></tr><tr><td> GB2312 </td><td> GBK </td><td>
1538: <a href="references.html#refsRFC1345">[RFC1345]</a>
1539: <a href="references.html#refsGBK">[GBK]</a>
1540: </td></tr><tr><td> GB_2312-80 </td><td> GBK </td><td>
1541: <a href="references.html#refsRFC1345">[RFC1345]</a>
1542: <a href="references.html#refsGBK">[GBK]</a>
1543: </td></tr><tr><td> ISO-8859-1 </td><td> windows-1252 </td><td>
1544: <a href="references.html#refsRFC1345">[RFC1345]</a>
1545: <a href="references.html#refsWIN1252">[WIN1252]</a>
1546: </td></tr><tr><td> ISO-8859-9 </td><td> windows-1254 </td><td>
1547: <a href="references.html#refsRFC1345">[RFC1345]</a>
1548: <a href="references.html#refsWIN1254">[WIN1254]</a>
1549: </td></tr><tr><td> ISO-8859-11 </td><td> windows-874 </td><td>
1550: <a href="references.html#refsISO885911">[ISO885911]</a>
1551: <a href="references.html#refsWIN874">[WIN874]</a>
1552: </td></tr><tr><td> KS_C_5601-1987 </td><td> windows-949 </td><td>
1553: <a href="references.html#refsRFC1345">[RFC1345]</a>
1554: <a href="references.html#refsWIN949">[WIN949]</a>
1555: </td></tr><tr><td> Shift_JIS </td><td> windows-31J </td><td>
1556: <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
1557: <a href="references.html#refsWIN31J">[WIN31J]</a>
1558: </td></tr><tr><td> TIS-620 </td><td> windows-874 </td><td>
1559: <a href="references.html#refsTIS620">[TIS620]</a>
1560: <a href="references.html#refsWIN874">[WIN874]</a>
1561: </td></tr><tr><td> US-ASCII </td><td> windows-1252 </td><td>
1562: <a href="references.html#refsRFC1345">[RFC1345]</a>
1563: <a href="references.html#refsWIN1252">[WIN1252]</a>
1564: </td></tr></tbody></table><p class="note">The requirement to treat certain encodings as other
1565: encodings according to the table above is a <a href="introduction.html#willful-violation">willful
1566: violation</a> of the W3C Character Model specification, motivated
1567: by a desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
1568:
1569: <p>When a user agent is to use the UTF-16 encoding but no BOM has
1570: been found, user agents must default to UTF-16LE.</p>
1571:
1572: <p class="note">The requirement to default UTF-16 to LE rather than
1573: BE is a <a href="introduction.html#willful-violation">willful violation</a> of RFC 2781, motivated by a
1.581 mike 1574: desire for compatibility with legacy content. <a href="references.html#refsRFC2781">[RFC2781]</a></p>
1.237 mike 1575:
1576: <hr><p>User agents must not support the CESU-8, UTF-7, BOCU-1 and SCSU
1577: 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>
1578:
1579: <p>Support for encodings based on EBCDIC is not recommended. This
1580: encoding is rarely used for publicly-facing Web content.</p>
1581:
1582: <p>Support for UTF-32 is not recommended. This encoding is rarely
1583: used, and frequently implemented incorrectly.</p>
1584:
1585: <p class="note">This specification does not make any attempt to
1586: support EBCDIC-based encodings and UTF-32 in its algorithms; support
1587: and use of these encodings can thus lead to unexpected behavior in
1588: implementations of this specification.</p>
1589:
1590:
1591:
1.614 mike 1592: <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.3 </span>Preprocessing the input stream</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 1593:
1594: <p>Given an encoding, the bytes in the input stream must be
1595: converted to Unicode characters for the tokenizer, as described by
1596: the rules for that encoding, except that the leading U+FEFF BYTE
1597: ORDER MARK character, if any, must not be stripped by the encoding
1598: layer (it is stripped by the rule below).</p> <!-- this is to
1599: prevent two leading BOMs from being both stripped, once by the
1600: decoder, and once by the parser -->
1601:
1602: <p>Bytes or sequences of bytes in the original byte stream that
1.393 mike 1603: could not be converted to Unicode code points must be converted to
1604: U+FFFD REPLACEMENT CHARACTERs.</p>
1.1 mike 1605:
1606: <p class="note">Bytes or sequences of bytes in the original byte
1607: stream that did not conform to the encoding specification
1608: (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
1609: errors that conformance checkers are expected to report.</p>
1610:
1.438 mike 1611: <p>Any byte or sequence of bytes in the original byte stream that is
1612: <a href="#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
1.1 mike 1613: error</a>.</p>
1614:
1615: <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
1616: any are present.</p>
1617:
1.300 mike 1618: <p class="note">The requirement to strip a U+FEFF BYTE ORDER MARK
1619: character regardless of whether that character was used to determine
1620: the byte order is a <a href="introduction.html#willful-violation">willful violation</a> of Unicode,
1621: motivated by a desire to increase the resilience of user agents in
1622: the face of naïve transcoders.</p>
1623:
1.316 mike 1624: <p>All U+0000 NULL characters and code points in the range U+D800 to
1.315 mike 1625: U+DFFF<!-- surrogates not allowed e.g. in UTF-8, and we don't want
1626: them to suddenly turn into codepoints when they go through a UTF-16
1627: pipe --> in the input must be replaced by U+FFFD REPLACEMENT
1.316 mike 1628: CHARACTERs. Any occurrences of such characters and code points are
1629: <a href="#parse-error" title="parse error">parse errors</a>.</p>
1.1 mike 1630:
1631: <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
1632: <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
1633: CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
1.315 mike 1634: <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+FDD0
1635: to U+FDEF, and characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF,
1636: U+2FFFE, U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE,
1637: U+5FFFF, U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF,
1638: U+9FFFE, U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE,
1639: U+CFFFF, U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF,
1640: U+10FFFE, and U+10FFFF are <a href="#parse-error" title="parse error">parse
1.316 mike 1641: errors</a>. These are all control characters or permanently
1642: undefined Unicode characters (noncharacters).</p>
1.1 mike 1643:
1644: <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
1645: characters are treated specially. Any CR characters that are
1646: followed by LF characters must be removed, and any CR characters not
1647: followed by LF characters must be converted to LF characters. Thus,
1648: newlines in HTML DOMs are represented by LF characters, and there
1649: are never any CR characters in the input to the
1650: <a href="#tokenization">tokenization</a> stage.</p>
1651:
1652: <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
1653: input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
1654: the <i><a href="#next-input-character">next input character</a></i> is the first character in the
1655: input. The <dfn id="current-input-character">current input character</dfn> is the last character
1656: to have been <i><a href="#consumed">consumed</a></i>.</p>
1657:
1658: <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
1659: character or just before the end of the input stream) where content
1.159 mike 1660: 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 1661: inserted. The insertion point is relative to the position of the
1662: character immediately after it, it is not an absolute offset into
1663: the input stream. Initially, the insertion point is
1.10 mike 1664: undefined.</p>
1.1 mike 1665:
1666: <p>The "EOF" character in the tables below is a conceptual character
1667: representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
1.159 mike 1668: is a <a href="embedded-content-0.html#script-created-parser">script-created parser</a>, then the end of the
1.1 mike 1669: <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
1.159 mike 1670: 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 1671: consumed. Otherwise, the "EOF" character is not a real character in
1672: the stream, but rather the lack of any further characters.</p>
1673:
1674:
1.614 mike 1675: <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.4 </span>Changing the encoding while parsing</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 1676:
1677: <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
1678: encoding</dfn>, it must run the following steps. This might happen
1679: if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
1680: failed to find an encoding, or if it found an encoding that was not
1681: the actual encoding of the file.</p>
1682:
1683: <ol><li>If the new encoding is identical or equivalent to the encoding
1684: that is already being used to interpret the input stream, then set
1685: the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1686: <i>certain</i> and abort these steps. This happens when the
1687: encoding information found in the file matches what the
1688: <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
1689: encoding, and in the second pass through the parser if the first
1690: pass found that the encoding sniffing algorithm described in the
1691: earlier section failed to find the right encoding.</li>
1692:
1693: <li>If the encoding that is already being used to interpret the
1694: input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1695: <i>certain</i> and abort these steps. The new encoding is ignored;
1696: if it was anything but the same encoding, then it would be clearly
1697: incorrect.</li>
1698:
1699: <li>If the new encoding is a UTF-16 encoding, change it to
1700: UTF-8.</li>
1701:
1702: <li>If all the bytes up to the last byte converted by the current
1703: decoder have the same Unicode interpretations in both the current
1704: encoding and the new encoding, and if the user agent supports
1705: changing the converter on the fly, then the user agent may change
1706: to the new converter for the encoding on the fly. Set the
1707: <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
1708: convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1709: <i>certain</i>, and abort these steps.</li>
1710:
1711: <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
1712: <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
1713: browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
1714: sniffing algorithm</a> and instead just set the encoding to the
1715: new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1716: <i>certain</i>. Whenever possible, this should be done without
1717: actually contacting the network layer (the bytes should be
1718: re-parsed from memory), even if, e.g., the document is marked as
1719: not being cacheable. If this is not possible and contacting the
1720: network layer would involve repeating a request that uses a method
1721: other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
1722: equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1723: <i>certain</i> and ignore the new encoding. The resource will be
1724: misinterpreted. User agents may notify the user of the situation,
1725: to aid in application development.</li>
1726:
1.266 mike 1727: </ol></div><div class="impl">
1728:
1.614 mike 1729: <h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 1730:
1.614 mike 1731: <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 1732:
1733: <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
1734: the primary operation of the tree construction stage.</p>
1735:
1736: <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
1737: "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
1738: "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
1739: "<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.540 mike 1740: "<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: text">text</a>",
1.1 mike 1741: "<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>",
1742: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
1743: "<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
1744: table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
1745: foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
1746: body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
1747: frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
1748: frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
1749: after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
1750: frameset</a>" during the course of the parsing, as described in
1751: the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
1752: how tokens are processed and whether CDATA sections are
1753: supported.</p>
1754:
1755: <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
1756: head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
1757: body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
1758: table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
1759: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
1760: "<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
1761: that the other modes defer to them at various times. When the
1762: algorithm below says that the user agent is to do something
1763: "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
1764: mode", where <var title="">m</var> is one of these modes, the user
1765: agent must use the rules described under the <var title="">m</var>
1766: <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
1767: <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>
1768: to a new value.</p>
1769:
1770: <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.540 mike 1771: mode: text">text</a>" or "<a href="#parsing-main-intabletext" title="insertion mode: in table
1772: text">in table text</a>", the <dfn id="original-insertion-mode">original insertion mode</dfn>
1773: is also set. This is the insertion mode to which the tree
1774: construction stage will return.</p>
1.1 mike 1775:
1776: <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
1777: mode: in foreign content">in foreign content</a>", the
1778: <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
1779: is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
1780: foreign content">in foreign content</a>" mode to handle HTML
1781: (i.e. not foreign) content.</p>
1782:
1783: <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
1784: mode appropriately</dfn>, it means the UA must follow these
1785: steps:</p>
1786:
1787: <ol><li>Let <var title="">last</var> be false.</li>
1788:
1.604 mike 1789: <li>Let <var title="">foreign</var> be false.</li>
1790:
1.1 mike 1791: <li>Let <var title="">node</var> be the last node in the
1792: <a href="#stack-of-open-elements">stack of open elements</a>.</li>
1793:
1.604 mike 1794: <li><i>Loop</i>: If <var title="">node</var> is the first node in
1795: the stack of open elements, then set <var title="">last</var> to
1796: true and set <var title="">node</var> to the <var title="">context</var> element. (<a href="#fragment-case">fragment case</a>)</li>
1.1 mike 1797:
1798: <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
1.604 mike 1799: 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 jump to the
1800: step marked <i title="">end</i>. (<a href="#fragment-case">fragment case</a>)</li>
1.1 mike 1801:
1802: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
1803: <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
1804: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
1.604 mike 1805: mode: in cell">in cell</a>" and jump to the step marked <i title="">end</i>.</li>
1.1 mike 1806:
1807: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
1808: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
1.604 mike 1809: mode: in row">in row</a>" and jump to the step marked <i title="">end</i>.</li>
1.1 mike 1810:
1811: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
1812: <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
1813: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
1.604 mike 1814: table body">in table body</a>" and jump to the step marked <i title="">end</i>.</li>
1.1 mike 1815:
1816: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
1.604 mike 1817: 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 jump to
1818: the step marked <i title="">end</i>.</li>
1.1 mike 1819:
1820: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
1821: 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
1.604 mike 1822: jump to the step marked <i title="">end</i>. (<a href="#fragment-case">fragment
1823: case</a>)</li>
1.1 mike 1824:
1825: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
1.604 mike 1826: 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 jump to the
1827: step marked <i title="">end</i>.</li>
1.1 mike 1828:
1.159 mike 1829: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element-0">head</a></code> element,
1.604 mike 1830: 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 jump to
1831: the step marked <i title="">end</i>. (<a href="#fragment-case">fragment
1832: case</a>)</li> <!-- This is only here for now in case people
1833: think that the spec accidentally omitted it and try to "fix"
1834: it. Note that noscript-in-head is also handled this way. This is
1835: all intentional. The only thing it doesn't handle is the
1836: scripting-disabled fragment parsing case for a <head> element
1837: containing a <noscript> which itself contains something other than
1838: a <link> or a <style> element; you'd expect that to break out of
1839: the <noscript> but it doesn't. This is an edge case that doesn't
1840: affect the spec, since the algorithm for fragment parsing is only
1841: used for innerHTML/outerHTML/insertAdjacentHTML(), where we know
1842: scripting is enabled. -->
1.1 mike 1843:
1.159 mike 1844: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element-0">body</a></code> element,
1.604 mike 1845: 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 jump to the
1846: step marked <i title="">end</i>.</li>
1.1 mike 1847:
1.5 mike 1848: <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.604 mike 1849: 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 jump to
1850: the step marked <i title="">end</i>. (<a href="#fragment-case">fragment
1851: case</a>)</li>
1.1 mike 1852:
1.159 mike 1853: <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element-0">html</a></code> element,
1.333 mike 1854: then <!--: if the <span><code title="">head</code> element
1855: pointer</span> is null,--> switch the <a href="#insertion-mode">insertion mode</a>
1856: to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before
1857: head</a>"<!--, otherwise, switch the <span>insertion mode</span>
1858: to "<span title="insertion mode: after head">after head</span>".-->
1.604 mike 1859: Then, <!-- in either case, --> jump to the step marked <i title="">end</i>. (<a href="#fragment-case">fragment case</a>)</li> <!-- if the
1860: head element pointer can ever be non-null when we're going through
1861: these steps, we'll need to uncomment out the commented-out bits -->
1862:
1863: <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
1864: namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then set the
1865: <var title="">foreign</var> flag to true.</li>
1.1 mike 1866:
1867: <li>If <var title="">last</var> is true, then switch the
1868: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
1.604 mike 1869: body">in body</a>" and jump to the step marked <i title="">end</i>. (<a href="#fragment-case">fragment case</a>)</li>
1.1 mike 1870:
1871: <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
1872: elements</a>.</li>
1873:
1.604 mike 1874: <li>Return to the step marked <i>loop</i>.</li>
1875:
1876: <li><i>End</i>: If <var title="">foreign</var> is true, switch the
1877: <a href="#secondary-insertion-mode">secondary insertion mode</a> to whatever the
1878: <a href="#insertion-mode">insertion mode</a> is set to, and switch the
1879: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
1880: foreign content">in foreign content</a>".</li>
1.1 mike 1881:
1.614 mike 1882: </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 1883:
1884: <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
1885: stack grows downwards; the topmost node on the stack is the first
1886: one added to the stack, and the bottommost node of the stack is the
1887: most recently added node in the stack (notwithstanding when the
1888: stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
1889:
1890: <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
1891: html</a>" <a href="#insertion-mode">insertion mode</a> creates the
1.159 mike 1892: <code><a href="semantics.html#the-html-element-0">html</a></code> root element node, which is then added to the
1.1 mike 1893: stack.</p>
1894:
1895: <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
1.159 mike 1896: elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1 mike 1897: element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
1898: parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
1899: case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
1900: html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
1901:
1.159 mike 1902: <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 1903: node of the stack. It never gets popped off the stack.</p>
1904:
1905: <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
1906: stack.</p>
1907:
1908: <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
1909: element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
1910: 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
1911: open elements</a> (<a href="#fragment-case">fragment case</a>), then the
1912: <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
1.159 mike 1913: of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code> element).</p>
1.1 mike 1914:
1915: <p>Elements in the stack fall into the following categories:</p>
1916:
1917: <dl><dt><dfn id="special">Special</dfn></dt>
1918:
1919: <dd><p>The following HTML elements have varying levels of special
1920: 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>,
1921: <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 1922: <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.159 mike 1923: <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 1924: <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 1925: <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
1.422 mike 1926: <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>,
1927: <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>,
1928: <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>,
1929: <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>,
1930: <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>,
1931: <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>,
1932: <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>,
1933: <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>,
1934: (commented out because this isn't an element that can end up on the
1935: stack, so it doesn't matter) --> <code><a href="text-level-semantics.html#the-img-element">img</a></code>,
1936: <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>,
1937: <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>,
1938: <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>,
1939: <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>,
1940: <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>,
1941: <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>,
1.589 mike 1942: <code><a href="forms.html#the-select-element">select</a></code>, <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
1943: <code><a href="forms.html#the-textarea-element">textarea</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>,
1944: <code><a href="semantics.html#the-title-element-0">title</a></code>, <code><a href="tabular-data.html#the-tr-element">tr</a></code>, <code><a href="semantics.html#the-ul-element">ul</a></code>,
1945: <code>wbr</code>, and <code><a href="obsolete.html#xmp">xmp</a></code>.</p></dd>
1.1 mike 1946:
1947: <dt><dfn id="scoping">Scoping</dfn></dt>
1948: <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
1949: an element in scope">scopes</a> for various parts of the
1.5 mike 1950: 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 1951: <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>,
1952: <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 1953: <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
1954:
1955: <dt><dfn id="formatting">Formatting</dfn></dt>
1956: <dd><p>The following HTML elements are those that end up in the
1957: <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 1958: <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>,
1959: <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>,
1960: <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>,
1961: <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
1962: <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1 mike 1963:
1964: <dt><dfn id="phrasing">Phrasing</dfn></dt>
1965: <dd><p>All other elements found while parsing an HTML
1966: document.</p></dd>
1967:
1.234 mike 1968: </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
1969: specific scope</dfn> consisting of a list of element types <var title="">list</var> when the following algorithm terminates in a
1970: match state:</p>
1.1 mike 1971:
1972: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
1973: node</a> (the bottommost node of the stack).</p></li>
1974:
1975: <li><p>If <var title="">node</var> is the target node, terminate in
1976: a match state.</p></li>
1977:
1.234 mike 1978: <li><p>Otherwise, if <var title="">node</var> is one of the element
1979: types in <var title="">list</var>, terminate in a failure
1980: state.</p></li>
1.1 mike 1981:
1982: <li><p>Otherwise, set <var title="">node</var> to the previous
1983: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
1984: 2. (This will never fail, since the loop will always terminate in
1985: the previous step if the top of the stack — an
1.159 mike 1986: <code><a href="semantics.html#the-html-element-0">html</a></code> element — is reached.)</p></li>
1.1 mike 1987:
1.234 mike 1988: </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
1989: it <a href="#has-an-element-in-the-specific-scope">has an element in the specific scope</a> consisting
1990: of the following element types:</p>
1991:
1992: <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
1993: <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
1994: <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.) -->
1995: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
1996: <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
1997: <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
1998: <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
1999: <li><code><a href="obsolete.html#the-marquee-element">marquee</a></code> in the HTML namespace</li>
2000: <li><code><a href="text-level-semantics.html#the-object-element">object</a></code> in the HTML namespace</li>
2001: <li><code title="">foreignObject</code> in the SVG namespace</li>
2002: </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
2003: item scope</dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
2004: scope</a> consisting of the following element types:</p>
2005:
2006: <ul class="brief"><li>All the element types listed above for the <i><a href="#has-an-element-in-scope">has an element
2007: in scope</a></i> algorithm.</li>
2008: <li><code><a href="semantics.html#the-ol-element">ol</a></code> in the HTML namespace</li>
2009: <li><code><a href="semantics.html#the-ul-element">ul</a></code> in the HTML namespace</li>
2010: </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
2011: scope</em></dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
2012: scope</a> consisting of the following element types:</p>
2013:
2014: <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.) -->
2015: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
2016: </ul><p>Nothing happens if at any time any of the elements in the
1.1 mike 2017: <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
2018: or removed from, the <code>Document</code> tree. In particular, the
2019: stack is not changed in this situation. This can cause, amongst
2020: other strange effects, content to be appended to nodes that are no
2021: longer in the DOM.</p>
2022:
2023: <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
2024: the stack is manipulated in a random-access fashion.</p>
2025:
2026:
1.614 mike 2027: <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 2028:
2029: <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
2030: empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
2031:
2032: <p>The list contains elements in the <a href="#formatting">formatting</a>
2033: category, and scope markers. The scope markers are inserted when
1.159 mike 2034: 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 2035: elements, marquees, table cells, and table captions, and are used to
1.5 mike 2036: prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.159 mike 2037: elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code> elements, marquees, and
1.1 mike 2038: tables.</p>
2039:
2040: <p class="note">The scope markers are unrelated to the concept of an
2041: element being <a href="#has-an-element-in-scope" title="has an element in scope">in
2042: scope</a>.</p>
2043:
2044: <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
2045: elements</a> is associated with the token for which it was
2046: created, so that further elements can be created for that token if
2047: necessary.</p>
2048:
2049: <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
2050: active formatting elements</dfn>, the UA must perform the following
2051: steps:</p>
2052:
2053: <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
2054: elements</a>, then there is nothing to reconstruct; stop this
2055: algorithm.</li>
2056:
2057: <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
2058: active formatting elements</a> is a marker, or if it is an
2059: element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
2060: there is nothing to reconstruct; stop this algorithm.</li>
2061:
2062: <li>Let <var title="">entry</var> be the last (most recently added)
2063: element in the <a href="#list-of-active-formatting-elements">list of active formatting
2064: elements</a>.</li>
2065:
2066: <li>If there are no entries before <var title="">entry</var> in the
2067: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
2068: 8.</li>
2069:
2070: <li>Let <var title="">entry</var> be the entry one earlier than
2071: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
2072: elements</a>.</li>
2073:
2074: <li>If <var title="">entry</var> is neither a marker nor an element
2075: that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
2076: 4.</li>
2077:
2078: <li>Let <var title="">entry</var> be the element one later than
2079: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
2080: elements</a>.</li>
2081:
2082: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
2083: element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
2084:
2085: <li>Append <var title="">new element</var> to the <a href="#current-node">current
2086: node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
2087: elements</a> so that it is the new <a href="#current-node">current
2088: node</a>.</li>
2089:
2090: <li>Replace the entry for <var title="">entry</var> in the list
2091: with an entry for <var title="">new element</var>.</li>
2092:
2093: <li>If the entry for <var title="">new element</var> in the
2094: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
2095: entry in the list, return to step 7.</li>
2096:
2097: </ol><p>This has the effect of reopening all the formatting elements that
2098: were opened in the current body, cell, or caption (whichever is
2099: youngest) that haven't been explicitly closed.</p>
2100:
2101: <p class="note">The way this specification is written, the
2102: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
2103: elements in chronological order with the least recently added
2104: element first and the most recently added element last (except for
2105: while steps 8 to 11 of the above algorithm are being executed, of
2106: course).</p>
2107:
2108: <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
2109: active formatting elements up to the last marker</dfn>, the UA must
2110: perform the following steps:</p>
2111:
2112: <ol><li>Let <var title="">entry</var> be the last (most recently added)
2113: entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
2114:
2115: <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
2116: formatting elements</a>.</li>
2117:
2118: <li>If <var title="">entry</var> was a marker, then stop the
2119: algorithm at this point. The list has been cleared up to the last
2120: marker.</li>
2121:
2122: <li>Go to step 1.</li>
2123:
1.614 mike 2124: </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 2125:
2126: <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
2127: pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
2128: pointer</dfn> are both null.</p>
2129:
1.159 mike 2130: <p>Once a <code><a href="semantics.html#the-head-element-0">head</a></code> element has been parsed (whether
1.1 mike 2131: implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
2132: element pointer</a> gets set to point to this node.</p>
2133:
2134: <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
2135: points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
2136: whose end tag has not yet been seen. It is used to make form
2137: controls associate with forms in the face of dramatically bad
2138: markup, for historical reasons.</p>
2139:
2140:
1.614 mike 2141: <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 2142:
2143: <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
2144: <code>Document</code> with which the parser is associated when the
2145: parser was created, and "disabled" otherwise.</p>
2146:
2147: <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
2148: when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
2149: parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
2150: don't execute in that case.</p>
2151:
2152: <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
2153: created. It is set to "not ok" after certain tokens are seen.</p>
2154:
1.266 mike 2155: </div><div class="impl">
1.1 mike 2156:
1.159 mike 2157: <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 2158:
2159: <p>Implementations must act as if they used the following state
2160: machine to tokenize HTML. The state machine must start in the
2161: <a href="#data-state">data state</a>. Most states consume a single character,
2162: which may have various side-effects, and either switches the state
2163: machine to a new state to <em>reconsume</em> the same character, or
2164: switches it to a new state (to consume the next character), or
2165: repeats the same state (to consume the next character). Some states
2166: have more complicated behavior and can consume several characters
1.541 mike 2167: before switching to another state. In some cases, the tokenizer
2168: state is also changed by the tree construction stage.</p>
1.1 mike 2169:
1.541 mike 2170: <p>The exact behavior of certain states depends on the
2171: <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
2172: elements</a>. Certain states also use a <dfn id="temporary-buffer"><var>temporary
2173: buffer</var></dfn> to track progress.</p>
1.1 mike 2174:
2175: <p>The output of the tokenization step is a series of zero or more
2176: of the following tokens: DOCTYPE, start tag, end tag, comment,
2177: character, end-of-file. DOCTYPE tokens have a name, a public
2178: identifier, a system identifier, and a <i>force-quirks
2179: flag</i>. When a DOCTYPE token is created, its name, public
2180: identifier, and system identifier must be marked as missing (which
2181: is a distinct state from the empty string), and the <i>force-quirks
2182: flag</i> must be set to <i>off</i> (its other state is
2183: <i>on</i>). Start and end tag tokens have a tag name, a
2184: <i>self-closing flag</i>, and a list of attributes, each of which
2185: has a name and a value. When a start or end tag token is created,
2186: its <i>self-closing flag</i> must be unset (its other state is that
2187: it be set), and its attributes list must be empty. Comment and
2188: character tokens have data.</p>
2189:
2190: <p>When a token is emitted, it must immediately be handled by the
2191: <a href="#tree-construction">tree construction</a> stage. The tree construction stage
1.541 mike 2192: can affect the state of the tokenization stage, and can insert
2193: additional characters into the stream. (For example, the
1.1 mike 2194: <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
1.159 mike 2195: using the <a href="embedded-content-0.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
1.1 mike 2196: characters into the stream being tokenized.)</p>
2197:
2198: <p>When a start tag token is emitted with its <i>self-closing
2199: flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
2200: self-closing flag">acknowledged</dfn> when it is processed by the
2201: tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
2202:
2203: <p>When an end tag token is emitted with attributes, that is a
2204: <a href="#parse-error">parse error</a>.</p>
2205:
2206: <p>When an end tag token is emitted with its <i>self-closing
2207: flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
2208:
1.541 mike 2209: <p>An <dfn id="appropriate-end-tag-token">appropriate end tag token</dfn> is an end tag token whose
2210: tag name matches the tag name of the last start tag to have been
2211: emitted from this tokenizer, if any. If no start tag has been
2212: emitted from this tokenizer, then no end tag token is
2213: appropriate.</p>
2214:
1.1 mike 2215: <p>Before each step of the tokenizer, the user agent must first
2216: check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
2217: tokenizer must abort the processing of any nested invocations of the
1.479 mike 2218: tokenizer, yielding control back to the caller.</p>
1.1 mike 2219:
2220: <p>The tokenizer state machine consists of the states defined in the
2221: following subsections.</p>
2222:
1.541 mike 2223:
1.333 mike 2224: <!-- Order of the lists below is supposed to be non-error then
2225: error, by unicode, then EOF, ending with "anything else" -->
1.1 mike 2226:
1.541 mike 2227:
1.614 mike 2228: <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 2229:
2230: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2231:
2232: <dl class="switch"><dt>U+0026 AMPERSAND (&)</dt>
1.541 mike 2233: <dd>Switch to the <a href="#character-reference-in-data-state">character reference in data
1.56 mike 2234: state</a>.</dd>
1.1 mike 2235:
1.541 mike 2236: <dt>U+003C LESS-THAN SIGN (<)</dt>
2237: <dd>Switch to the <a href="#tag-open-state">tag open state</a>.</dd>
2238:
2239: <dt>EOF</dt>
2240: <dd>Emit an end-of-file token.</dd>
2241:
2242: <dt>Anything else</dt>
2243: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2244: token. Stay in the <a href="#data-state">data state</a>.</dd>
1.1 mike 2245:
1.618 mike 2246: </dl><h5 id="character-reference-in-data-state"><span class="secno">9.2.4.2 </span><dfn>Character reference in data state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
2247:
2248: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
2249: <a href="#additional-allowed-character">additional allowed character</a>.</p>
2250:
2251: <p>If nothing is returned, emit a U+0026 AMPERSAND character
2252: token.</p>
2253:
2254: <p>Otherwise, emit the character token that was returned.</p>
2255:
2256: <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
2257:
2258:
2259: <h5 id="rcdata-state"><span class="secno">9.2.4.3 </span><dfn>RCDATA state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 2260:
1.541 mike 2261: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1.1 mike 2262:
1.541 mike 2263: <dl class="switch"><dt>U+0026 AMPERSAND (&)</dt>
1.618 mike 2264: <dd>Switch to the <a href="#character-reference-in-rcdata-state">character reference in RCDATA
1.541 mike 2265: state</a>.</dd>
1.1 mike 2266:
2267: <dt>U+003C LESS-THAN SIGN (<)</dt>
1.541 mike 2268: <dd>Switch to the <a href="#rcdata-less-than-sign-state">RCDATA less-than sign state</a>.</dd>
2269:
2270: <dt>EOF</dt>
2271: <dd>Emit an end-of-file token.</dd>
1.1 mike 2272:
1.541 mike 2273: <dt>Anything else</dt>
2274: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2275: token. Stay in the <a href="#rcdata-state">RCDATA state</a>.</dd>
1.1 mike 2276:
1.618 mike 2277: </dl><h5 id="character-reference-in-rcdata-state"><span class="secno">9.2.4.4 </span><dfn>Character reference in RCDATA state</dfn></h5>
2278:
2279: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
2280: <a href="#additional-allowed-character">additional allowed character</a>.</p>
2281:
2282: <p>If nothing is returned, emit a U+0026 AMPERSAND character
2283: token.</p>
2284:
2285: <p>Otherwise, emit the character token that was returned.</p>
2286:
2287: <p>Finally, switch to the <a href="#rcdata-state">RCDATA state</a>.</p>
2288:
2289:
2290: <h5 id="rawtext-state"><span class="secno">9.2.4.5 </span><dfn>RAWTEXT state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 2291:
1.541 mike 2292: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1.1 mike 2293:
1.541 mike 2294: <dl class="switch"><dt>U+003C LESS-THAN SIGN (<)</dt>
2295: <dd>Switch to the <a href="#rawtext-less-than-sign-state">RAWTEXT less-than sign state</a>.</dd>
1.1 mike 2296:
2297: <dt>EOF</dt>
2298: <dd>Emit an end-of-file token.</dd>
2299:
2300: <dt>Anything else</dt>
1.541 mike 2301: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2302: token. Stay in the <a href="#rawtext-state">RAWTEXT state</a>.</dd>
1.1 mike 2303:
1.618 mike 2304: </dl><h5 id="script-data-state"><span class="secno">9.2.4.6 </span><dfn>Script data state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 2305:
1.541 mike 2306: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1.1 mike 2307:
1.541 mike 2308: <dl class="switch"><dt>U+003C LESS-THAN SIGN (<)</dt>
2309: <dd>Switch to the <a href="#script-data-less-than-sign-state">script data less-than sign state</a>.</dd>
1.1 mike 2310:
1.541 mike 2311: <dt>EOF</dt>
2312: <dd>Emit an end-of-file token.</dd>
1.1 mike 2313:
1.541 mike 2314: <dt>Anything else</dt>
2315: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2316: token. Stay in the <a href="#script-data-state">script data state</a>.</dd>
1.1 mike 2317:
1.618 mike 2318: </dl><h5 id="plaintext-state"><span class="secno">9.2.4.7 </span><dfn>PLAINTEXT state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 2319:
1.541 mike 2320: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1.1 mike 2321:
1.541 mike 2322: <dl class="switch"><dt>EOF</dt>
2323: <dd>Emit an end-of-file token.</dd>
1.1 mike 2324:
1.541 mike 2325: <dt>Anything else</dt>
2326: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2327: token. Stay in the <a href="#plaintext-state">PLAINTEXT state</a>.</dd>
1.1 mike 2328:
1.618 mike 2329: </dl><h5 id="tag-open-state"><span class="secno">9.2.4.8 </span><dfn>Tag open state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 2330:
1.541 mike 2331: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1.1 mike 2332:
1.541 mike 2333: <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
2334: <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
1.1 mike 2335:
1.541 mike 2336: <dt>U+002F SOLIDUS (/)</dt>
2337: <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
1.1 mike 2338:
1.541 mike 2339: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2340: <dd>Create a new start tag token, set its tag name to the
2341: lowercase version of the <a href="#current-input-character">current input character</a> (add 0x0020 to the
2342: character's code point), then switch to the <a href="#tag-name-state">tag name
2343: state</a>. (Don't emit the token yet; further details will
2344: be filled in before it is emitted.)</dd>
1.1 mike 2345:
1.541 mike 2346: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2347: <dd>Create a new start tag token, set its tag name to the
2348: <a href="#current-input-character">current input character</a>, then switch to the <a href="#tag-name-state">tag
2349: name state</a>. (Don't emit the token yet; further details will
2350: be filled in before it is emitted.)</dd>
1.1 mike 2351:
1.541 mike 2352: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2353: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2354: character token and a U+003E GREATER-THAN SIGN character
2355: token. Switch to the <a href="#data-state">data state</a>.</dd>
1.1 mike 2356:
1.541 mike 2357: <dt>U+003F QUESTION MARK (?)</dt>
2358: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2359: comment state</a>.</dd>
1.1 mike 2360:
1.541 mike 2361: <dt>Anything else</dt>
2362: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2363: character token and reconsume the <a href="#current-input-character">current input
2364: character</a> in the <a href="#data-state">data state</a>.</dd>
1.1 mike 2365:
1.618 mike 2366: </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.9 </span><dfn>Close tag open state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 2367:
1.541 mike 2368: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1.1 mike 2369:
2370: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2371: <dd>Create a new end tag token, set its tag name to the lowercase
1.541 mike 2372: version of the <a href="#current-input-character">current input character</a> (add 0x0020 to
2373: the character's code point), then switch to the <a href="#tag-name-state">tag name
1.1 mike 2374: state</a>. (Don't emit the token yet; further details will be
2375: filled in before it is emitted.)</dd>
2376:
2377: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
1.541 mike 2378: <dd>Create a new end tag token, set its tag name to the
2379: <a href="#current-input-character">current input character</a>, then switch to the <a href="#tag-name-state">tag
2380: name state</a>. (Don't emit the token yet; further details will
2381: be filled in before it is emitted.)</dd>
1.1 mike 2382:
2383: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2384: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
2385: state</a>.</dd>
2386:
2387: <dt>EOF</dt>
2388: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2389: character token and a U+002F SOLIDUS character token. Reconsume
2390: the EOF character in the <a href="#data-state">data state</a>.</dd>
2391:
2392: <dt>Anything else</dt>
2393: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2394: comment state</a>.</dd>
2395:
1.618 mike 2396: </dl><h5 id="tag-name-state"><span class="secno">9.2.4.10 </span><dfn>Tag name state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 2397:
2398: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2399:
2400: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2401: <dt>U+000A LINE FEED (LF)</dt>
2402: <dt>U+000C FORM FEED (FF)</dt>
2403: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2404: <dt>U+0020 SPACE</dt>
2405: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2406:
2407: <dt>U+002F SOLIDUS (/)</dt>
2408: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2409:
2410: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2411: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2412: state</a>.</dd>
2413:
2414: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
1.541 mike 2415: <dd>Append the lowercase version of the <a href="#current-input-character">current input
2416: character</a> (add 0x0020 to the character's code point) to the
2417: current tag token's tag name. Stay in the <a href="#tag-name-state">tag name
2418: state</a>.</dd>
2419:
2420: <dt>EOF</dt>
2421: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2422: <a href="#data-state">data state</a>.</dd>
2423:
2424: <dt>Anything else</dt>
2425: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2426: tag token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
2427:
1.618 mike 2428: </dl><h5 id="rcdata-less-than-sign-state"><span class="secno">9.2.4.11 </span><dfn>RCDATA less-than sign state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2429: <!-- identical to the RAWTEXT less-than sign state, except s/RAWTEXT/RCDATA/g -->
2430:
2431: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2432:
2433: <dl class="switch"><dt>U+002F SOLIDUS (/)</dt>
2434: <dd>Set the <var><a href="#temporary-buffer">temporary buffer</a></var> to the empty string. Switch
2435: to the <a href="#rcdata-end-tag-open-state">RCDATA end tag open state</a>.</dd>
2436:
2437: <dt>Anything else</dt>
2438: <dd>Emit a U+003C LESS-THAN SIGN character token and reconsume the
2439: <a href="#current-input-character">current input character</a> in the <a href="#rcdata-state">RCDATA
2440: state</a>.</dd>
2441:
1.618 mike 2442: </dl><h5 id="rcdata-end-tag-open-state"><span class="secno">9.2.4.12 </span><dfn>RCDATA end tag open state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2443: <!-- identical to the RAWTEXT (and Script data) end tag open state, except s/RAWTEXT/RCDATA/g -->
2444:
2445: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2446:
2447: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2448: <dd>Create a new end tag token, and set its tag name to the
2449: lowercase version of the <a href="#current-input-character">current input character</a> (add
2450: 0x0020 to the character's code point). Append the <a href="#current-input-character">current
2451: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2452: switch to the <a href="#rcdata-end-tag-name-state">RCDATA end tag name state</a>. (Don't emit
2453: the token yet; further details will be filled in before it is
2454: emitted.)</dd>
2455:
2456: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2457: <dd>Create a new end tag token, and set its tag name to the
2458: <a href="#current-input-character">current input character</a>. Append the <a href="#current-input-character">current
2459: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2460: switch to the <a href="#rcdata-end-tag-name-state">RCDATA end tag name state</a>. (Don't emit
2461: the token yet; further details will be filled in before it is
2462: emitted.)</dd>
2463:
2464: <dt>Anything else</dt>
2465: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2466: character token, and reconsume the <a href="#current-input-character">current input
2467: character</a> in the <a href="#rcdata-state">RCDATA state</a>.</dd>
2468:
1.618 mike 2469: </dl><h5 id="rcdata-end-tag-name-state"><span class="secno">9.2.4.13 </span><dfn>RCDATA end tag name state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2470: <!-- identical to the RAWTEXT (and Script data) end tag name state, except s/RAWTEXT/RCDATA/g -->
2471:
2472: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2473:
2474: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2475: <dt>U+000A LINE FEED (LF)</dt>
2476: <dt>U+000C FORM FEED (FF)</dt>
2477: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2478: <dt>U+0020 SPACE</dt>
2479: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2480: token</a>, then switch to the <a href="#before-attribute-name-state">before attribute name
2481: state</a>. Otherwise, treat it as per the "anything else" entry
2482: below.</dd>
2483:
2484: <dt>U+002F SOLIDUS (/)</dt>
2485: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2486: token</a>, then switch to the <a href="#self-closing-start-tag-state">self-closing start tag
2487: state</a>. Otherwise, treat it as per the "anything else" entry
2488: below.</dd>
2489:
2490: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2491: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2492: token</a>, then emit the current tag token and switch to the
2493: <a href="#data-state">data state</a>. Otherwise, treat it as per the "anything
2494: else" entry below.</dd>
2495:
2496: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2497: <dd>Append the lowercase version of the <a href="#current-input-character">current input
2498: character</a> (add 0x0020 to the character's code point) to the
2499: current tag token's tag name. Append the <a href="#current-input-character">current input
2500: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
2501: <a href="#rcdata-end-tag-name-state">RCDATA end tag name state</a>.</dd>
2502:
2503: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2504: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2505: tag token's tag name. Append the <a href="#current-input-character">current input
2506: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
2507: <a href="#rcdata-end-tag-name-state">RCDATA end tag name state</a>.</dd>
2508:
2509: <dt>Anything else</dt>
2510: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2511: character token, a character token for each of the characters in
2512: the <var><a href="#temporary-buffer">temporary buffer</a></var> (in the order they were added to
2513: the buffer), and reconsume the <a href="#current-input-character">current input character</a>
2514: in the <a href="#rcdata-state">RCDATA state</a>.</dd>
2515:
1.618 mike 2516: </dl><h5 id="rawtext-less-than-sign-state"><span class="secno">9.2.4.14 </span><dfn>RAWTEXT less-than sign state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2517: <!-- identical to the RCDATA less-than sign state, except s/RCDATA/RAWTEXT/g -->
2518:
2519: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2520:
2521: <dl class="switch"><dt>U+002F SOLIDUS (/)</dt>
2522: <dd>Set the <var><a href="#temporary-buffer">temporary buffer</a></var> to the empty string. Switch
2523: to the <a href="#rawtext-end-tag-open-state">RAWTEXT end tag open state</a>.</dd>
2524:
2525: <dt>Anything else</dt>
2526: <dd>Emit a U+003C LESS-THAN SIGN character token and reconsume the
2527: <a href="#current-input-character">current input character</a> in the <a href="#rawtext-state">RAWTEXT
2528: state</a>.</dd>
2529:
1.618 mike 2530: </dl><h5 id="rawtext-end-tag-open-state"><span class="secno">9.2.4.15 </span><dfn>RAWTEXT end tag open state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2531: <!-- identical to the RCDATA (and Script data) end tag open state, except s/RCDATA/RAWTEXT/g -->
2532:
2533: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2534:
2535: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2536: <dd>Create a new end tag token, and set its tag name to the
2537: lowercase version of the <a href="#current-input-character">current input character</a> (add
2538: 0x0020 to the character's code point). Append the <a href="#current-input-character">current
2539: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2540: switch to the <a href="#rawtext-end-tag-name-state">RAWTEXT end tag name state</a>. (Don't emit
2541: the token yet; further details will be filled in before it is
2542: emitted.)</dd>
2543:
2544: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2545: <dd>Create a new end tag token, and set its tag name to the
2546: <a href="#current-input-character">current input character</a>. Append the <a href="#current-input-character">current
2547: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2548: switch to the <a href="#rawtext-end-tag-name-state">RAWTEXT end tag name state</a>. (Don't emit
2549: the token yet; further details will be filled in before it is
2550: emitted.)</dd>
2551:
2552: <dt>Anything else</dt>
2553: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2554: character token, and reconsume the <a href="#current-input-character">current input
2555: character</a> in the <a href="#rawtext-state">RAWTEXT state</a>.</dd>
2556:
1.618 mike 2557: </dl><h5 id="rawtext-end-tag-name-state"><span class="secno">9.2.4.16 </span><dfn>RAWTEXT end tag name state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2558: <!-- identical to the RCDATA (and Script data) end tag name state, except s/RCDATA/RAWTEXT/g -->
2559:
2560: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2561:
2562: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2563: <dt>U+000A LINE FEED (LF)</dt>
2564: <dt>U+000C FORM FEED (FF)</dt>
2565: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2566: <dt>U+0020 SPACE</dt>
2567: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2568: token</a>, then switch to the <a href="#before-attribute-name-state">before attribute name
2569: state</a>. Otherwise, treat it as per the "anything else" entry
2570: below.</dd>
2571:
2572: <dt>U+002F SOLIDUS (/)</dt>
2573: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2574: token</a>, then switch to the <a href="#self-closing-start-tag-state">self-closing start tag
2575: state</a>. Otherwise, treat it as per the "anything else" entry
2576: below.</dd>
2577:
2578: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2579: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2580: token</a>, then emit the current tag token and switch to the
2581: <a href="#data-state">data state</a>. Otherwise, treat it as per the "anything
2582: else" entry below.</dd>
2583:
2584: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2585: <dd>Append the lowercase version of the <a href="#current-input-character">current input
2586: character</a> (add 0x0020 to the character's code point) to the
2587: current tag token's tag name. Append the <a href="#current-input-character">current input
2588: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
2589: <a href="#rawtext-end-tag-name-state">RAWTEXT end tag name state</a>.</dd>
2590:
2591: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2592: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2593: tag token's tag name. Append the <a href="#current-input-character">current input
2594: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
2595: <a href="#rawtext-end-tag-name-state">RAWTEXT end tag name state</a>.</dd>
2596:
2597: <dt>Anything else</dt>
2598: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2599: character token, a character token for each of the characters in
2600: the <var><a href="#temporary-buffer">temporary buffer</a></var> (in the order they were added to
2601: the buffer), and reconsume the <a href="#current-input-character">current input character</a>
2602: in the <a href="#rawtext-state">RAWTEXT state</a>.</dd>
2603:
1.618 mike 2604: </dl><h5 id="script-data-less-than-sign-state"><span class="secno">9.2.4.17 </span><dfn>Script data less-than sign state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2605:
2606: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2607:
2608: <dl class="switch"><dt>U+002F SOLIDUS (/)</dt>
2609: <dd>Set the <var><a href="#temporary-buffer">temporary buffer</a></var> to the empty string. Switch
2610: to the <a href="#script-data-end-tag-open-state">script data end tag open state</a>.</dd>
2611:
2612: <dt>U+0021 EXCLAMATION MARK (!)</dt>
2613: <dd>Emit a U+003C LESS-THAN SIGN character token and a U+0021
2614: EXCLAMATION MARK character token. Switch to the <a href="#script-data-escape-start-state">script data
2615: escape start state</a>.</dd>
2616:
2617: <dt>Anything else</dt>
2618: <dd>Emit a U+003C LESS-THAN SIGN character token and reconsume the
2619: <a href="#current-input-character">current input character</a> in the <a href="#script-data-state">script data
2620: state</a>.</dd>
2621:
1.618 mike 2622: </dl><h5 id="script-data-end-tag-open-state"><span class="secno">9.2.4.18 </span><dfn>Script data end tag open state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2623: <!-- identical to the RCDATA (and RAWTEXT) end tag open state, except s/RCDATA/Script data/g -->
2624:
2625: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2626:
2627: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2628: <dd>Create a new end tag token, and set its tag name to the
2629: lowercase version of the <a href="#current-input-character">current input character</a> (add
2630: 0x0020 to the character's code point). Append the <a href="#current-input-character">current
2631: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2632: switch to the <a href="#script-data-end-tag-name-state">script data end tag name state</a>. (Don't emit
2633: the token yet; further details will be filled in before it is
2634: emitted.)</dd>
2635:
2636: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2637: <dd>Create a new end tag token, and set its tag name to the
2638: <a href="#current-input-character">current input character</a>. Append the <a href="#current-input-character">current
2639: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2640: switch to the <a href="#script-data-end-tag-name-state">script data end tag name state</a>. (Don't emit
2641: the token yet; further details will be filled in before it is
2642: emitted.)</dd>
2643:
2644: <dt>Anything else</dt>
2645: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2646: character token, and reconsume the <a href="#current-input-character">current input
2647: character</a> in the <a href="#script-data-state">script data state</a>.</dd>
2648:
1.618 mike 2649: </dl><h5 id="script-data-end-tag-name-state"><span class="secno">9.2.4.19 </span><dfn>Script data end tag name state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2650: <!-- identical to the RCDATA (and RAWTEXT) end tag name state, except s/RCDATA/Script data/g -->
2651:
2652: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2653:
2654: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2655: <dt>U+000A LINE FEED (LF)</dt>
2656: <dt>U+000C FORM FEED (FF)</dt>
2657: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2658: <dt>U+0020 SPACE</dt>
2659: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2660: token</a>, then switch to the <a href="#before-attribute-name-state">before attribute name
2661: state</a>. Otherwise, treat it as per the "anything else" entry
2662: below.</dd>
2663:
2664: <dt>U+002F SOLIDUS (/)</dt>
2665: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2666: token</a>, then switch to the <a href="#self-closing-start-tag-state">self-closing start tag
2667: state</a>. Otherwise, treat it as per the "anything else" entry
2668: below.</dd>
2669:
2670: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2671: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2672: token</a>, then emit the current tag token and switch to the
2673: <a href="#data-state">data state</a>. Otherwise, treat it as per the "anything
2674: else" entry below.</dd>
2675:
2676: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2677: <dd>Append the lowercase version of the <a href="#current-input-character">current input
2678: character</a> (add 0x0020 to the character's code point) to the
2679: current tag token's tag name. Append the <a href="#current-input-character">current input
2680: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
1.542 mike 2681: <a href="#script-data-end-tag-name-state">script data end tag name state</a>.</dd>
1.541 mike 2682:
2683: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2684: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2685: tag token's tag name. Append the <a href="#current-input-character">current input
2686: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
1.542 mike 2687: <a href="#script-data-end-tag-name-state">script data end tag name state</a>.</dd>
1.541 mike 2688:
2689: <dt>Anything else</dt>
2690: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2691: character token, a character token for each of the characters in
2692: the <var><a href="#temporary-buffer">temporary buffer</a></var> (in the order they were added to
2693: the buffer), and reconsume the <a href="#current-input-character">current input character</a>
2694: in the <a href="#script-data-state">script data state</a>.</dd>
2695:
1.618 mike 2696: </dl><h5 id="script-data-escape-start-state"><span class="secno">9.2.4.20 </span><dfn>Script data escape start state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2697:
2698: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2699:
2700: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2701: <dd>Emit a U+002D HYPHEN-MINUS character token. Switch to the
2702: <a href="#script-data-escape-start-dash-state">script data escape start dash state</a>.</dd>
2703:
2704: <dt>Anything else</dt>
2705: <dd>Reconsume the <a href="#current-input-character">current input character</a> in the
2706: <a href="#script-data-state">script data state</a>.</dd>
2707:
1.618 mike 2708: </dl><h5 id="script-data-escape-start-dash-state"><span class="secno">9.2.4.21 </span><dfn>Script data escape start dash state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2709:
2710: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2711:
2712: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2713: <dd>Emit a U+002D HYPHEN-MINUS character token. Switch to the
2714: <a href="#script-data-escaped-dash-dash-state">script data escaped dash dash state</a>.</dd>
2715:
2716: <dt>Anything else</dt>
2717: <dd>Reconsume the <a href="#current-input-character">current input character</a> in the
2718: <a href="#script-data-state">script data state</a>.</dd>
2719:
1.618 mike 2720: </dl><h5 id="script-data-escaped-state"><span class="secno">9.2.4.22 </span><dfn>Script data escaped state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2721:
2722: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2723:
2724: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2725: <dd>Emit a U+002D HYPHEN-MINUS character token. Switch to the
2726: <a href="#script-data-escaped-dash-state">script data escaped dash state</a>.</dd>
2727:
1.542 mike 2728: <dt>U+003C LESS-THAN SIGN (<)</dt>
2729: <dd><p>Switch to the <a href="#script-data-escaped-less-than-sign-state">script data escaped less-than sign
2730: state</a>.</p></dd>
2731:
1.541 mike 2732: <dt>EOF</dt>
2733: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2734: <a href="#data-state">data state</a>.</dd>
2735:
2736: <dt>Anything else</dt>
1.542 mike 2737: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2738: token. Stay in the <a href="#script-data-escaped-state">script data escaped state</a>.</dd>
1.541 mike 2739:
1.618 mike 2740: </dl><h5 id="script-data-escaped-dash-state"><span class="secno">9.2.4.23 </span><dfn>Script data escaped dash state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2741:
2742: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2743:
2744: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2745: <dd>Emit a U+002D HYPHEN-MINUS character token. Switch to the
2746: <a href="#script-data-escaped-dash-dash-state">script data escaped dash dash state</a>.</dd>
2747:
1.542 mike 2748: <dt>U+003C LESS-THAN SIGN (<)</dt>
2749: <dd><p>Switch to the <a href="#script-data-escaped-less-than-sign-state">script data escaped less-than sign
2750: state</a>.</p></dd>
2751:
1.541 mike 2752: <dt>EOF</dt>
2753: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2754: <a href="#data-state">data state</a>.</dd>
2755:
2756: <dt>Anything else</dt>
1.542 mike 2757: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2758: token. Switch to the <a href="#script-data-escaped-state">script data escaped state</a>.</dd>
1.541 mike 2759:
1.618 mike 2760: </dl><h5 id="script-data-escaped-dash-dash-state"><span class="secno">9.2.4.24 </span><dfn>Script data escaped dash dash state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.541 mike 2761:
2762: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2763:
2764: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2765: <dd>Emit a U+002D HYPHEN-MINUS character token. Stay in the
2766: <a href="#script-data-escaped-dash-dash-state">script data escaped dash dash state</a>.</dd>
2767:
1.542 mike 2768: <dt>U+003C LESS-THAN SIGN (<)</dt>
2769: <dd><p>Switch to the <a href="#script-data-escaped-less-than-sign-state">script data escaped less-than sign
2770: state</a>.</p></dd>
2771:
1.541 mike 2772: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2773: <dd>Emit a U+003E GREATER-THAN SIGN character token. Switch to the
2774: <a href="#script-data-state">script data state</a>.</dd>
1.1 mike 2775:
2776: <dt>EOF</dt>
2777: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2778: <a href="#data-state">data state</a>.</dd>
2779:
2780: <dt>Anything else</dt>
1.542 mike 2781: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2782: token. Switch to the <a href="#script-data-escaped-state">script data escaped state</a>.</dd>
2783:
1.618 mike 2784: </dl><h5 id="script-data-escaped-less-than-sign-state"><span class="secno">9.2.4.25 </span><dfn>Script data escaped less-than sign state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.542 mike 2785:
2786: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2787:
2788: <dl class="switch"><dt>U+002F SOLIDUS (/)</dt>
2789: <dd>Set the <var><a href="#temporary-buffer">temporary buffer</a></var> to the empty string. Switch
2790: to the <a href="#script-data-escaped-end-tag-open-state">script data escaped end tag open state</a>.</dd>
2791:
2792: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2793: <dd>Emit a U+003C LESS-THAN SIGN character token and the
2794: <a href="#current-input-character">current input character</a> as a character token. Set the
2795: <var><a href="#temporary-buffer">temporary buffer</a></var> to the empty string. Append the
2796: lowercase version of the <a href="#current-input-character">current input character</a> (add
2797: 0x0020 to the character's code point) to the <var><a href="#temporary-buffer">temporary
2798: buffer</a></var>. Switch to the <a href="#script-data-double-escape-start-state">script data double escape start
2799: state</a>.</dd>
2800:
2801: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2802: <dd>Emit a U+003C LESS-THAN SIGN character token and the
2803: <a href="#current-input-character">current input character</a> as a character token. Set the
2804: <var><a href="#temporary-buffer">temporary buffer</a></var> to the empty string. Append the
2805: <a href="#current-input-character">current input character</a> to the <var><a href="#temporary-buffer">temporary
2806: buffer</a></var>. Switch to the <a href="#script-data-double-escape-start-state">script data double escape start
2807: state</a>.</dd>
2808:
2809: <dt>Anything else</dt>
2810: <dd>Emit a U+003C LESS-THAN SIGN character token and reconsume the
2811: <a href="#current-input-character">current input character</a> in the <a href="#script-data-escaped-state">script data
2812: escaped state</a>.</dd>
2813:
1.618 mike 2814: </dl><h5 id="script-data-escaped-end-tag-open-state"><span class="secno">9.2.4.26 </span><dfn>Script data escaped end tag open state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.542 mike 2815:
2816: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2817:
2818: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2819: <dd>Create a new end tag token, and set its tag name to the
2820: lowercase version of the <a href="#current-input-character">current input character</a> (add
2821: 0x0020 to the character's code point). Append the <a href="#current-input-character">current
2822: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2823: switch to the <a href="#script-data-escaped-end-tag-name-state">script data escaped end tag name
2824: state</a>. (Don't emit the token yet; further details will be
2825: filled in before it is emitted.)</dd>
2826:
2827: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2828: <dd>Create a new end tag token, and set its tag name to the
2829: <a href="#current-input-character">current input character</a>. Append the <a href="#current-input-character">current
2830: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2831: switch to the <a href="#script-data-escaped-end-tag-name-state">script data escaped end tag name
2832: state</a>. (Don't emit the token yet; further details will be
2833: filled in before it is emitted.)</dd>
2834:
2835: <dt>Anything else</dt>
2836: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2837: character token, and reconsume the <a href="#current-input-character">current input
2838: character</a> in the <a href="#script-data-escaped-state">script data escaped state</a>.</dd>
2839:
1.618 mike 2840: </dl><h5 id="script-data-escaped-end-tag-name-state"><span class="secno">9.2.4.27 </span><dfn>Script data escaped end tag name state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.542 mike 2841:
2842: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2843:
2844: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2845: <dt>U+000A LINE FEED (LF)</dt>
2846: <dt>U+000C FORM FEED (FF)</dt>
2847: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2848: <dt>U+0020 SPACE</dt>
2849: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2850: token</a>, then switch to the <a href="#before-attribute-name-state">before attribute name
2851: state</a>. Otherwise, treat it as per the "anything else" entry
2852: below.</dd>
2853:
2854: <dt>U+002F SOLIDUS (/)</dt>
2855: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2856: token</a>, then switch to the <a href="#self-closing-start-tag-state">self-closing start tag
2857: state</a>. Otherwise, treat it as per the "anything else" entry
2858: below.</dd>
2859:
2860: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2861: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2862: token</a>, then emit the current tag token and switch to the
2863: <a href="#data-state">data state</a>. Otherwise, treat it as per the "anything
2864: else" entry below.</dd>
2865:
2866: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2867: <dd>Append the lowercase version of the <a href="#current-input-character">current input
2868: character</a> (add 0x0020 to the character's code point) to the
2869: current tag token's tag name. Append the <a href="#current-input-character">current input
2870: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
2871: <a href="#script-data-escaped-end-tag-name-state">script data escaped end tag name state</a>.</dd>
2872:
2873: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2874: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2875: tag token's tag name. Append the <a href="#current-input-character">current input
2876: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
2877: <a href="#script-data-escaped-end-tag-name-state">script data escaped end tag name state</a>.</dd>
2878:
2879: <dt>Anything else</dt>
2880: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2881: character token, a character token for each of the characters in
2882: the <var><a href="#temporary-buffer">temporary buffer</a></var> (in the order they were added to
2883: the buffer), and reconsume the <a href="#current-input-character">current input character</a>
2884: in the <a href="#script-data-escaped-state">script data escaped state</a>.</dd>
2885:
1.618 mike 2886: </dl><h5 id="script-data-double-escape-start-state"><span class="secno">9.2.4.28 </span><dfn>Script data double escape start state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.542 mike 2887:
2888: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2889:
2890: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2891: <dt>U+000A LINE FEED (LF)</dt>
2892: <dt>U+000C FORM FEED (FF)</dt>
2893: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2894: <dt>U+0020 SPACE</dt>
2895: <dt>U+002F SOLIDUS (/)</dt>
2896: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2897: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2898: token. If the <var><a href="#temporary-buffer">temporary buffer</a></var> is the string "<code title="">script</code>", then switch to the <a href="#script-data-double-escaped-state">script data
2899: double escaped state</a>. Otherwise, switch to the <a href="#script-data-escaped-state">script
2900: data escaped state</a>.</dd>
2901:
2902: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2903: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2904: token. Append the lowercase version of the <a href="#current-input-character">current input
2905: character</a> (add 0x0020 to the character's code point) to the
2906: <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the <a href="#script-data-double-escape-start-state">script data double
2907: escape start state</a>.</dd>
2908:
2909: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2910: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2911: token. Append the <a href="#current-input-character">current input character</a> to the
2912: <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the <a href="#script-data-double-escape-start-state">script data double
2913: escape start state</a>.</dd>
2914:
2915: <dt>Anything else</dt>
2916: <dd>Reconsume the <a href="#current-input-character">current input character</a> in the
2917: <a href="#script-data-escaped-state">script data escaped state</a>.</dd>
2918:
1.618 mike 2919: </dl><h5 id="script-data-double-escaped-state"><span class="secno">9.2.4.29 </span><dfn>Script data double escaped state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.542 mike 2920:
2921: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2922:
2923: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2924: <dd>Emit a U+002D HYPHEN-MINUS character token. Switch to the
2925: <a href="#script-data-double-escaped-dash-state">script data double escaped dash state</a>.</dd>
2926:
2927: <dt>U+003C LESS-THAN SIGN (<)</dt>
2928: <dd><p>Emit a U+003C LESS-THAN SIGN character token. Switch to the
2929: <a href="#script-data-double-escaped-less-than-sign-state">script data double escaped less-than sign
2930: state</a>.</p></dd>
2931:
2932: <dt>EOF</dt>
2933: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2934: <a href="#data-state">data state</a>.</dd>
2935:
2936: <dt>Anything else</dt>
2937: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2938: token. Stay in the <a href="#script-data-double-escaped-state">script data double escaped
2939: state</a>.</dd>
2940:
1.618 mike 2941: </dl><h5 id="script-data-double-escaped-dash-state"><span class="secno">9.2.4.30 </span><dfn>Script data double escaped dash state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.542 mike 2942:
2943: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2944:
2945: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2946: <dd>Emit a U+002D HYPHEN-MINUS character token. Switch to the
2947: <a href="#script-data-double-escaped-dash-dash-state">script data double escaped dash dash state</a>.</dd>
2948:
2949: <dt>U+003C LESS-THAN SIGN (<)</dt>
2950: <dd><p>Emit a U+003C LESS-THAN SIGN character token. Switch to the
2951: <a href="#script-data-double-escaped-less-than-sign-state">script data double escaped less-than sign
2952: state</a>.</p></dd>
2953:
2954: <dt>EOF</dt>
2955: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2956: <a href="#data-state">data state</a>.</dd>
2957:
2958: <dt>Anything else</dt>
2959: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2960: token. Switch to the <a href="#script-data-double-escaped-state">script data double escaped
2961: state</a>.</dd>
2962:
1.618 mike 2963: </dl><h5 id="script-data-double-escaped-dash-dash-state"><span class="secno">9.2.4.31 </span><dfn>Script data double escaped dash dash state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.542 mike 2964:
2965: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2966:
2967: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2968: <dd>Emit a U+002D HYPHEN-MINUS character token. Stay in the
2969: <a href="#script-data-double-escaped-dash-dash-state">script data double escaped dash dash state</a>.</dd>
2970:
2971: <dt>U+003C LESS-THAN SIGN (<)</dt>
2972: <dd><p>Emit a U+003C LESS-THAN SIGN character token. Switch to the
2973: <a href="#script-data-double-escaped-less-than-sign-state">script data double escaped less-than sign
2974: state</a>.</p></dd>
2975:
2976: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2977: <dd>Emit a U+003E GREATER-THAN SIGN character token. Switch to the
2978: <a href="#script-data-state">script data state</a>.</dd>
2979:
2980: <dt>EOF</dt>
2981: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2982: <a href="#data-state">data state</a>.</dd>
2983:
2984: <dt>Anything else</dt>
2985: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2986: token. Switch to the <a href="#script-data-double-escaped-state">script data double escaped
2987: state</a>.</dd>
2988:
1.618 mike 2989: </dl><h5 id="script-data-double-escaped-less-than-sign-state"><span class="secno">9.2.4.32 </span><dfn>Script data double escaped less-than sign state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.542 mike 2990:
2991: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2992:
2993: <dl class="switch"><dt>U+002F SOLIDUS (/)</dt>
2994: <dd>Emit a U+002F SOLIDUS character token. Set the <var><a href="#temporary-buffer">temporary
2995: buffer</a></var> to the empty string. Switch to the <a href="#script-data-double-escape-end-state">script data
2996: double escape end state</a>.</dd>
2997:
2998: <dt>Anything else</dt>
2999: <dd>Reconsume the <a href="#current-input-character">current input character</a> in the
3000: <a href="#script-data-double-escaped-state">script data double escaped state</a>.</dd>
3001:
1.618 mike 3002: </dl><h5 id="script-data-double-escape-end-state"><span class="secno">9.2.4.33 </span><dfn>Script data double escape end state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.542 mike 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: <dt>U+002F SOLIDUS (/)</dt>
3012: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3013: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
3014: token. If the <var><a href="#temporary-buffer">temporary buffer</a></var> is the string "<code title="">script</code>", then switch to the <a href="#script-data-escaped-state">script data
3015: escaped state</a>. Otherwise, switch to the <a href="#script-data-double-escaped-state">script data
3016: double escaped state</a>.</dd>
3017:
3018: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
3019: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
3020: token. Append the lowercase version of the <a href="#current-input-character">current input
3021: character</a> (add 0x0020 to the character's code point) to the
3022: <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the <a href="#script-data-double-escape-end-state">script data double
3023: escape end state</a>.</dd>
3024:
3025: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
3026: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
3027: token. Append the <a href="#current-input-character">current input character</a> to the
3028: <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the <a href="#script-data-double-escape-end-state">script data double
3029: escape end state</a>.</dd>
3030:
3031: <dt>Anything else</dt>
3032: <dd>Reconsume the <a href="#current-input-character">current input character</a> in the
3033: <a href="#script-data-double-escaped-state">script data double escaped state</a>.</dd>
1.1 mike 3034:
1.618 mike 3035: </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.34 </span><dfn>Before attribute name state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3036:
3037: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3038:
3039: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3040: <dt>U+000A LINE FEED (LF)</dt>
3041: <dt>U+000C FORM FEED (FF)</dt>
3042: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3043: <dt>U+0020 SPACE</dt>
3044: <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
3045:
3046: <dt>U+002F SOLIDUS (/)</dt>
3047: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
3048:
3049: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3050: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
3051: state</a>.</dd>
3052:
3053: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
3054: <dd>Start a new attribute in the current tag token. Set that
3055: attribute's name to the lowercase version of the <a href="#current-input-character">current input
3056: character</a> (add 0x0020 to the character's code point), and its
3057: value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
3058: state</a>.</dd>
3059:
3060: <dt>U+0022 QUOTATION MARK (")</dt>
3061: <dt>U+0027 APOSTROPHE (')</dt>
3062: <dt>U+003C LESS-THAN SIGN (<)</dt>
3063: <dt>U+003D EQUALS SIGN (=)</dt>
3064: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
3065: entry below.</dd>
3066:
3067: <dt>EOF</dt>
3068: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3069: <a href="#data-state">data state</a>.</dd>
3070:
3071: <dt>Anything else</dt>
3072: <dd>Start a new attribute in the current tag token. Set that
3073: attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
3074: the empty string. Switch to the <a href="#attribute-name-state">attribute name
3075: state</a>.</dd>
3076:
1.618 mike 3077: </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.35 </span><dfn>Attribute name state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3078:
3079: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3080:
3081: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3082: <dt>U+000A LINE FEED (LF)</dt>
3083: <dt>U+000C FORM FEED (FF)</dt>
3084: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3085: <dt>U+0020 SPACE</dt>
3086: <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
3087:
3088: <dt>U+002F SOLIDUS (/)</dt>
3089: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
3090:
3091: <dt>U+003D EQUALS SIGN (=)</dt>
3092: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
3093:
3094: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3095: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
3096: state</a>.</dd>
3097:
3098: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
1.541 mike 3099: <dd>Append the lowercase version of the <a href="#current-input-character">current input
3100: character</a> (add 0x0020 to the character's code point) to the
3101: current attribute's name. Stay in the <a href="#attribute-name-state">attribute name
1.1 mike 3102: state</a>.</dd>
3103:
3104: <dt>U+0022 QUOTATION MARK (")</dt>
3105: <dt>U+0027 APOSTROPHE (')</dt>
3106: <dt>U+003C LESS-THAN SIGN (<)</dt>
3107: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
3108: entry below.</dd>
3109:
3110: <dt>EOF</dt>
3111: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3112: <a href="#data-state">data state</a>.</dd>
3113:
3114: <dt>Anything else</dt>
1.541 mike 3115: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3116: attribute's name. Stay in the <a href="#attribute-name-state">attribute name
3117: state</a>.</dd>
1.1 mike 3118:
3119: </dl><p>When the user agent leaves the attribute name state (and before
3120: emitting the tag token, if appropriate), the complete attribute's
3121: name must be compared to the other attributes on the same token;
3122: if there is already an attribute on the token with the exact same
3123: name, then this is a <a href="#parse-error">parse error</a> and the new
3124: attribute must be dropped, along with the value that gets
3125: associated with it (if any).</p>
3126:
3127:
1.618 mike 3128: <h5 id="after-attribute-name-state"><span class="secno">9.2.4.36 </span><dfn>After attribute name state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3129:
3130: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3131:
3132: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3133: <dt>U+000A LINE FEED (LF)</dt>
3134: <dt>U+000C FORM FEED (FF)</dt>
3135: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3136: <dt>U+0020 SPACE</dt>
3137: <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
3138:
3139: <dt>U+002F SOLIDUS (/)</dt>
3140: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
3141:
3142: <dt>U+003D EQUALS SIGN (=)</dt>
3143: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
3144:
3145: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3146: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
3147: state</a>.</dd>
3148:
3149: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
3150: <dd>Start a new attribute in the current tag token. Set that
1.541 mike 3151: attribute's name to the lowercase version of the <a href="#current-input-character">current
3152: input character</a> (add 0x0020 to the character's code point),
3153: and its value to the empty string. Switch to the <a href="#attribute-name-state">attribute
3154: name state</a>.</dd>
1.1 mike 3155:
3156: <dt>U+0022 QUOTATION MARK (")</dt>
3157: <dt>U+0027 APOSTROPHE (')</dt>
3158: <dt>U+003C LESS-THAN SIGN (<)</dt>
3159: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
3160: entry below.</dd>
3161:
3162: <dt>EOF</dt>
3163: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3164: <a href="#data-state">data state</a>.</dd>
3165:
3166: <dt>Anything else</dt>
3167: <dd>Start a new attribute in the current tag token. Set that
1.541 mike 3168: attribute's name to the <a href="#current-input-character">current input character</a>, and
3169: its value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
1.1 mike 3170: state</a>.</dd>
3171:
1.618 mike 3172: </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.37 </span><dfn>Before attribute value state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3173:
3174: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3175:
3176: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3177: <dt>U+000A LINE FEED (LF)</dt>
3178: <dt>U+000C FORM FEED (FF)</dt>
3179: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3180: <dt>U+0020 SPACE</dt>
3181: <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
3182:
3183: <dt>U+0022 QUOTATION MARK (")</dt>
3184: <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
3185:
3186: <dt>U+0026 AMPERSAND (&)</dt>
3187: <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
1.541 mike 3188: and reconsume this <a href="#current-input-character">current input character</a>.</dd>
1.1 mike 3189:
3190: <dt>U+0027 APOSTROPHE (')</dt>
3191: <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
3192:
3193: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3194: <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
3195: the <a href="#data-state">data state</a>.</dd>
3196:
3197: <dt>U+003C LESS-THAN SIGN (<)</dt>
3198: <dt>U+003D EQUALS SIGN (=)</dt>
1.463 mike 3199: <dt>U+0060 GRAVE ACCENT (`)</dt>
1.1 mike 3200: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
3201: entry below.</dd>
3202:
3203: <dt>EOF</dt>
3204: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3205: <a href="#data-state">data state</a>.</dd>
3206:
3207: <dt>Anything else</dt>
3208: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3209: attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
3210: state</a>.</dd>
3211:
1.618 mike 3212: </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.38 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
1.1 mike 3213:
3214: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3215:
3216: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
3217: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
3218: state</a>.</dd>
3219:
3220: <dt>U+0026 AMPERSAND (&)</dt>
3221: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
3222: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
3223: being U+0022 QUOTATION MARK (").</dd>
3224:
3225: <dt>EOF</dt>
3226: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3227: <a href="#data-state">data state</a>.</dd>
3228:
3229: <dt>Anything else</dt>
1.541 mike 3230: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3231: attribute's value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value
3232: (double-quoted) state</a>.</dd>
1.1 mike 3233:
1.618 mike 3234: </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.39 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
1.1 mike 3235:
3236: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3237:
3238: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
3239: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
3240: state</a>.</dd>
3241:
3242: <dt>U+0026 AMPERSAND (&)</dt>
3243: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
3244: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
3245: being U+0027 APOSTROPHE (').</dd>
3246:
3247: <dt>EOF</dt>
3248: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3249: <a href="#data-state">data state</a>.</dd>
3250:
3251: <dt>Anything else</dt>
1.541 mike 3252: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3253: attribute's value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value
3254: (single-quoted) state</a>.</dd>
1.1 mike 3255:
1.618 mike 3256: </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.40 </span><dfn>Attribute value (unquoted) state</dfn></h5>
1.1 mike 3257:
3258: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3259:
3260: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3261: <dt>U+000A LINE FEED (LF)</dt>
3262: <dt>U+000C FORM FEED (FF)</dt>
3263: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3264: <dt>U+0020 SPACE</dt>
3265: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
3266:
3267: <dt>U+0026 AMPERSAND (&)</dt>
3268: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
1.299 mike 3269: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
3270: being U+003E GREATER-THAN SIGN (>).</dd>
1.1 mike 3271:
3272: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3273: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
3274: state</a>.</dd>
3275:
3276: <dt>U+0022 QUOTATION MARK (")</dt>
3277: <dt>U+0027 APOSTROPHE (')</dt>
3278: <dt>U+003C LESS-THAN SIGN (<)</dt>
3279: <dt>U+003D EQUALS SIGN (=)</dt>
1.463 mike 3280: <dt>U+0060 GRAVE ACCENT (`)</dt>
1.1 mike 3281: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
3282: entry below.</dd>
3283:
3284: <dt>EOF</dt>
3285: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3286: <a href="#data-state">data state</a>.</dd>
3287:
3288: <dt>Anything else</dt>
1.541 mike 3289: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3290: attribute's value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
1.1 mike 3291: state</a>.</dd>
3292:
1.618 mike 3293: </dl><h5 id="character-reference-in-attribute-value-state"><span class="secno">9.2.4.41 </span><dfn>Character reference in attribute value state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3294:
3295: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
3296:
3297: <p>If nothing is returned, append a U+0026 AMPERSAND character to
3298: the current attribute's value.</p>
3299:
3300: <p>Otherwise, append the returned character token to the current
3301: attribute's value.</p>
3302:
3303: <p>Finally, switch back to the attribute value state that you were
3304: in when were switched into this state.</p>
3305:
3306:
1.618 mike 3307: <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.42 </span><dfn>After attribute value (quoted) state</dfn></h5>
1.1 mike 3308:
3309: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3310:
3311: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3312: <dt>U+000A LINE FEED (LF)</dt>
3313: <dt>U+000C FORM FEED (FF)</dt>
3314: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3315: <dt>U+0020 SPACE</dt>
3316: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
3317:
3318: <dt>U+002F SOLIDUS (/)</dt>
3319: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
3320:
3321: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3322: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
3323: state</a>.</dd>
3324:
3325: <dt>EOF</dt>
3326: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3327: <a href="#data-state">data state</a>.</dd>
3328:
3329: <dt>Anything else</dt>
3330: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
3331: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
3332:
1.618 mike 3333: </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.43 </span><dfn>Self-closing start tag state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3334:
3335: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3336:
3337: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
3338: <dd>Set the <i>self-closing flag</i> of the current tag
3339: token. Emit the current tag token. Switch to the <a href="#data-state">data
3340: state</a>.</dd>
3341:
3342: <dt>EOF</dt>
3343: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3344: <a href="#data-state">data state</a>.</dd>
3345:
3346: <dt>Anything else</dt>
3347: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
3348: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
3349:
1.618 mike 3350: </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.44 </span><dfn>Bogus comment state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3351:
3352: <p>Consume every character up to and including the first U+003E
3353: GREATER-THAN SIGN character (>) or the end of the file (EOF),
3354: whichever comes first. Emit a comment token whose data is the
3355: concatenation of all the characters starting from and including
3356: the character that caused the state machine to switch into the
3357: bogus comment state, up to and including the character immediately
3358: before the last consumed character (i.e. up to the character just
3359: before the U+003E or EOF character). (If the comment was started
3360: by the end of the file (EOF), the token is empty.)</p>
3361:
3362: <p>Switch to the <a href="#data-state">data state</a>.</p>
3363:
3364: <p>If the end of the file was reached, reconsume the EOF
3365: character.</p>
3366:
3367:
1.618 mike 3368: <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.45 </span><dfn>Markup declaration open state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3369:
1.588 mike 3370: <p>If the next two characters are both U+002D HYPHEN-MINUS
3371: characters (-), consume those two characters, create a comment token
1.1 mike 3372: whose data is the empty string, and switch to the <a href="#comment-start-state">comment
3373: start state</a>.</p>
3374:
3375: <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
3376: case-insensitive</a> match for the word "DOCTYPE", then consume
3377: those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
3378:
3379: <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
3380: content</a>" and the <a href="#current-node">current node</a> is not an element
3381: in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
1.585 mike 3382: an <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string "[CDATA[" (the
3383: five uppercase letters "CDATA" with a U+005B LEFT SQUARE BRACKET
3384: character before and after), then consume those characters and
3385: switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1 mike 3386:
3387: <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
3388: <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
3389: consumed, if any, is the first character that will be in the
3390: comment.</p>
3391:
3392:
1.618 mike 3393: <h5 id="comment-start-state"><span class="secno">9.2.4.46 </span><dfn>Comment start state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3394:
3395: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3396:
3397: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
3398: <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
3399:
3400: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3401: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
3402: <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
3403: -->
3404:
3405: <dt>EOF</dt>
3406: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
3407: the EOF character in the <a href="#data-state">data state</a>.</dd>
3408:
3409: <dt>Anything else</dt>
1.541 mike 3410: <dd>Append the <a href="#current-input-character">current input character</a> to the comment
3411: token's data. Switch to the <a href="#comment-state">comment state</a>.</dd>
1.1 mike 3412:
1.618 mike 3413: </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.47 </span><dfn>Comment start dash state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3414:
3415: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3416:
3417: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
3418: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
3419:
3420: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3421: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
3422: the <a href="#data-state">data state</a>.</dd>
3423:
3424: <dt>EOF</dt>
3425: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
3426: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
3427: in comment end state -->
3428:
3429: <dt>Anything else</dt>
1.541 mike 3430: <dd>Append a U+002D HYPHEN-MINUS character (-) and the
3431: <a href="#current-input-character">current input character</a> to the comment token's
3432: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
1.1 mike 3433:
1.618 mike 3434: </dl><h5 id="comment-state"><span class="secno">9.2.4.48 </span><dfn id="comment">Comment state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3435:
3436: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3437:
3438: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
3439: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
3440:
3441: <dt>EOF</dt>
3442: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
3443: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
3444: in comment end state -->
3445:
3446: <dt>Anything else</dt>
1.541 mike 3447: <dd>Append the <a href="#current-input-character">current input character</a> to the comment
3448: token's data. Stay in the <a href="#comment-state">comment state</a>.</dd>
1.1 mike 3449:
1.618 mike 3450: </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.49 </span><dfn>Comment end dash state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3451:
3452: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3453:
3454: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
3455: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
3456:
3457: <dt>EOF</dt>
3458: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
3459: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
3460: in comment end state -->
3461:
3462: <dt>Anything else</dt>
1.541 mike 3463: <dd>Append a U+002D HYPHEN-MINUS character (-) and the
3464: <a href="#current-input-character">current input character</a> to the comment token's
3465: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
1.1 mike 3466:
1.618 mike 3467: </dl><h5 id="comment-end-state"><span class="secno">9.2.4.50 </span><dfn>Comment end state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3468:
3469: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3470:
3471: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
3472: <dd>Emit the comment token. Switch to the <a href="#data-state">data
3473: state</a>.</dd>
3474:
3475: <dt>U+0009 CHARACTER TABULATION</dt>
3476: <dt>U+000A LINE FEED (LF)</dt>
3477: <dt>U+000C FORM FEED (FF)</dt>
3478: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3479: <dt>U+0020 SPACE</dt>
1.588 mike 3480: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS
3481: characters (-) and the <a href="#current-input-character">current input character</a> to the
1.541 mike 3482: comment token's data. Switch to the <a href="#comment-end-space-state">comment end space
3483: state</a>.</dd>
1.1 mike 3484:
3485: <dt>U+0021 EXCLAMATION MARK (!)</dt>
3486: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
3487: state</a>.</dd>
3488:
1.333 mike 3489: <dt>U+002D HYPHEN-MINUS (-)</dt>
3490: <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
1.464 mike 3491: character (-) to the comment token's data. Stay in the
1.333 mike 3492: <a href="#comment-end-state">comment end state</a>.</dd>
3493:
1.1 mike 3494: <dt>EOF</dt>
3495: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
3496: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
3497: security reasons: otherwise, hostile user could put a <script> in
3498: a comment e.g. in a blog comment and then DOS the server so that
3499: the end tag isn't read, and then the commented <script> tag would
3500: be treated as live code -->
3501:
3502: <dt>Anything else</dt>
1.588 mike 3503: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS
3504: characters (-) and the <a href="#current-input-character">current input character</a> to the
1.541 mike 3505: comment token's data. Switch to the <a href="#comment-state">comment
3506: state</a>.</dd>
1.1 mike 3507:
1.618 mike 3508: </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.51 </span><dfn>Comment end bang state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3509:
3510: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3511:
1.333 mike 3512: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
1.588 mike 3513: <dd>Append two U+002D HYPHEN-MINUS characters (-) and a U+0021
1.464 mike 3514: EXCLAMATION MARK character (!) to the comment token's data. Switch
1.1 mike 3515: to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
3516:
1.333 mike 3517: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3518: <dd>Emit the comment token. Switch to the <a href="#data-state">data
3519: state</a>.</dd>
3520:
1.1 mike 3521: <dt>EOF</dt>
3522: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
3523: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
3524: comment in comment end state -->
3525:
3526: <dt>Anything else</dt>
1.588 mike 3527: <dd>Append two U+002D HYPHEN-MINUS characters (-), a U+0021
1.541 mike 3528: EXCLAMATION MARK character (!), and the <a href="#current-input-character">current input
3529: character</a> to the comment token's data. Switch to the
3530: <a href="#comment-state">comment state</a>.</dd>
1.1 mike 3531:
1.618 mike 3532: </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.52 </span><dfn>Comment end space state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3533:
3534: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3535:
1.333 mike 3536: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
1.1 mike 3537: <dt>U+000A LINE FEED (LF)</dt>
3538: <dt>U+000C FORM FEED (FF)</dt>
3539: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3540: <dt>U+0020 SPACE</dt>
1.541 mike 3541: <dd>Append the <a href="#current-input-character">current input character</a> to the comment token's data. Stay in
1.1 mike 3542: the <a href="#comment-end-space-state">comment end space state</a>.</dd>
3543:
1.333 mike 3544: <dt>U+002D HYPHEN-MINUS (-)</dt>
3545: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
3546:
3547: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3548: <dd>Emit the comment token. Switch to the <a href="#data-state">data
3549: state</a>.</dd>
3550:
1.1 mike 3551: <dt>EOF</dt>
3552: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
3553: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
3554: comment in comment end state -->
3555:
3556: <dt>Anything else</dt>
1.541 mike 3557: <dd>Append the <a href="#current-input-character">current input character</a> to the comment token's data. Switch
1.1 mike 3558: to the <a href="#comment-state">comment state</a>.</dd>
3559:
1.618 mike 3560: </dl><h5 id="doctype-state"><span class="secno">9.2.4.53 </span><dfn>DOCTYPE state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3561:
3562: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3563:
3564: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3565: <dt>U+000A LINE FEED (LF)</dt>
3566: <dt>U+000C FORM FEED (FF)</dt>
3567: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3568: <dt>U+0020 SPACE</dt>
3569: <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
3570:
3571: <dt>EOF</dt>
3572: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
3573: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
3574: the EOF character in the <a href="#data-state">data state</a>.</dd>
3575:
3576: <dt>Anything else</dt>
1.608 mike 3577: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in the
3578: <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
1.1 mike 3579:
1.618 mike 3580: </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.54 </span><dfn>Before DOCTYPE name state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3581:
3582: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3583:
3584: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3585: <dt>U+000A LINE FEED (LF)</dt>
3586: <dt>U+000C FORM FEED (FF)</dt>
3587: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3588: <dt>U+0020 SPACE</dt>
3589: <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
3590:
3591: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
3592: <dd>Create a new DOCTYPE token. Set the token's name to the
1.541 mike 3593: lowercase version of the <a href="#current-input-character">current input character</a> (add 0x0020 to the
1.1 mike 3594: character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
3595: state</a>.</dd>
3596:
1.333 mike 3597: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3598: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
3599: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
3600: the <a href="#data-state">data state</a>.</dd>
3601:
1.1 mike 3602: <dt>EOF</dt>
3603: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
3604: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
3605: the EOF character in the <a href="#data-state">data state</a>.</dd>
3606:
3607: <dt>Anything else</dt>
3608: <dd>Create a new DOCTYPE token. Set the token's name to the
3609: <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
3610: state</a>.</dd>
3611:
1.618 mike 3612: </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.55 </span><dfn>DOCTYPE name state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3613:
3614: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3615:
3616: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3617: <dt>U+000A LINE FEED (LF)</dt>
3618: <dt>U+000C FORM FEED (FF)</dt>
3619: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3620: <dt>U+0020 SPACE</dt>
3621: <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
3622:
3623: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3624: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3625: state</a>.</dd>
3626:
3627: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
1.541 mike 3628: <dd>Append the lowercase version of the <a href="#current-input-character">current input
3629: character</a> (add 0x0020 to the character's code point) to the
3630: current DOCTYPE token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name
3631: state</a>.</dd>
1.1 mike 3632:
3633: <dt>EOF</dt>
3634: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3635: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3636: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3637:
3638: <dt>Anything else</dt>
1.541 mike 3639: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3640: DOCTYPE token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name
3641: state</a>.</dd>
1.1 mike 3642:
1.618 mike 3643: </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.56 </span><dfn>After DOCTYPE name state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3644:
3645: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3646:
3647: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3648: <dt>U+000A LINE FEED (LF)</dt>
3649: <dt>U+000C FORM FEED (FF)</dt>
3650: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3651: <dt>U+0020 SPACE</dt>
3652: <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
3653:
3654: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3655: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3656: state</a>.</dd>
3657:
3658: <dt>EOF</dt>
3659: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3660: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3661: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3662:
3663: <dt>Anything else</dt>
3664: <dd>
3665:
3666: <p>If the six characters starting from the <a href="#current-input-character">current input
3667: character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
3668: for the word "PUBLIC", then consume those characters and switch to
1.444 mike 3669: the <a href="#after-doctype-public-keyword-state">after DOCTYPE public keyword state</a>.</p>
1.1 mike 3670:
3671: <p>Otherwise, if the six characters starting from the
3672: <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
3673: case-insensitive</a> match for the word "SYSTEM", then consume
1.444 mike 3674: those characters and switch to the <a href="#after-doctype-system-keyword-state">after DOCTYPE system
3675: keyword state</a>.</p>
1.1 mike 3676:
3677: <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
3678: DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
3679: the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
3680:
3681: </dd>
3682:
1.618 mike 3683: </dl><h5 id="after-doctype-public-keyword-state"><span class="secno">9.2.4.57 </span><dfn>After DOCTYPE public keyword state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.444 mike 3684:
3685: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3686:
3687: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3688: <dt>U+000A LINE FEED (LF)</dt>
3689: <dt>U+000C FORM FEED (FF)</dt>
3690: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3691: <dt>U+0020 SPACE</dt>
3692: <dd>Switch to the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier
3693: state</a>.</dd>
3694:
1.620 mike 3695: <dt>U+0022 QUOTATION MARK (")</dt>
3696: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's public
3697: identifier to the empty string (not missing), then switch to the
3698: <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier (double-quoted) state</a>.</dd>
3699:
3700: <dt>U+0027 APOSTROPHE (')</dt>
3701: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's public
3702: identifier to the empty string (not missing), then switch to the
3703: <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier (single-quoted) state</a>.</dd>
3704:
3705: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3706: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3707: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3708: token. Switch to the <a href="#data-state">data state</a>.</dd>
3709:
1.444 mike 3710: <dt>EOF</dt>
3711: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3712: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3713: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3714:
3715: <dt>Anything else</dt>
1.620 mike 3716: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3717: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3718: DOCTYPE state</a>.</dd>
1.444 mike 3719:
1.618 mike 3720: </dl><h5 id="before-doctype-public-identifier-state"><span class="secno">9.2.4.58 </span><dfn>Before DOCTYPE public identifier state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3721:
3722: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3723:
3724: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3725: <dt>U+000A LINE FEED (LF)</dt>
3726: <dt>U+000C FORM FEED (FF)</dt>
3727: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3728: <dt>U+0020 SPACE</dt>
3729: <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
3730:
3731: <dt>U+0022 QUOTATION MARK (")</dt>
3732: <dd>Set the DOCTYPE token's public identifier to the empty string
3733: (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
3734: (double-quoted) state</a>.</dd>
3735:
3736: <dt>U+0027 APOSTROPHE (')</dt>
3737: <dd>Set the DOCTYPE token's public identifier to the empty string
3738: (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
3739: (single-quoted) state</a>.</dd>
3740:
3741: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3742: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3743: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3744: token. Switch to the <a href="#data-state">data state</a>.</dd>
3745:
3746: <dt>EOF</dt>
3747: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3748: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3749: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3750:
3751: <dt>Anything else</dt>
3752: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3753: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3754: DOCTYPE state</a>.</dd>
3755:
1.618 mike 3756: </dl><h5 id="doctype-public-identifier-double-quoted-state"><span class="secno">9.2.4.59 </span><dfn>DOCTYPE public identifier (double-quoted) state</dfn></h5>
1.1 mike 3757:
3758: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3759:
3760: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
3761: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
3762:
3763: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3764: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3765: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3766: token. Switch to the <a href="#data-state">data state</a>.</dd>
3767:
3768: <dt>EOF</dt>
3769: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3770: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3771: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3772:
3773: <dt>Anything else</dt>
3774: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3775: token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
3776: identifier (double-quoted) state</a>.</dd>
3777:
1.618 mike 3778: </dl><h5 id="doctype-public-identifier-single-quoted-state"><span class="secno">9.2.4.60 </span><dfn>DOCTYPE public identifier (single-quoted) state</dfn></h5>
1.1 mike 3779:
3780: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3781:
3782: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
3783: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
3784:
3785: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3786: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3787: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3788: token. Switch to the <a href="#data-state">data state</a>.</dd>
3789:
3790: <dt>EOF</dt>
3791: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3792: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3793: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3794:
3795: <dt>Anything else</dt>
3796: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3797: token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
3798: identifier (single-quoted) state</a>.</dd>
3799:
1.618 mike 3800: </dl><h5 id="after-doctype-public-identifier-state"><span class="secno">9.2.4.61 </span><dfn>After DOCTYPE public identifier state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3801:
3802: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3803:
3804: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3805: <dt>U+000A LINE FEED (LF)</dt>
3806: <dt>U+000C FORM FEED (FF)</dt>
3807: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3808: <dt>U+0020 SPACE</dt>
1.541 mike 3809: <dd>Switch to the <a href="#between-doctype-public-and-system-identifiers-state">between DOCTYPE public and system
3810: identifiers state</a>.</dd>
1.444 mike 3811:
3812: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3813: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3814: state</a>.</dd>
3815:
3816: <dt>U+0022 QUOTATION MARK (")</dt>
3817: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
3818: identifier to the empty string (not missing), then switch to the
3819: <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier (double-quoted) state</a>.</dd>
3820:
3821: <dt>U+0027 APOSTROPHE (')</dt>
3822: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
3823: identifier to the empty string (not missing), then switch to the
3824: <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier (single-quoted) state</a>.</dd>
3825:
3826: <dt>EOF</dt>
3827: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3828: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3829: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3830:
3831: <dt>Anything else</dt>
3832: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3833: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3834: DOCTYPE state</a>.</dd>
3835:
1.618 mike 3836: </dl><h5 id="between-doctype-public-and-system-identifiers-state"><span class="secno">9.2.4.62 </span><dfn>Between DOCTYPE public and system identifiers state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.444 mike 3837:
3838: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3839:
3840: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3841: <dt>U+000A LINE FEED (LF)</dt>
3842: <dt>U+000C FORM FEED (FF)</dt>
3843: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3844: <dt>U+0020 SPACE</dt>
1.541 mike 3845: <dd>Stay in the <a href="#between-doctype-public-and-system-identifiers-state">between DOCTYPE public and system identifiers
3846: state</a>.</dd>
1.444 mike 3847:
3848: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3849: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3850: state</a>.</dd>
1.1 mike 3851:
3852: <dt>U+0022 QUOTATION MARK (")</dt>
3853: <dd>Set the DOCTYPE token's system identifier to the empty string
3854: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
3855: (double-quoted) state</a>.</dd>
3856:
3857: <dt>U+0027 APOSTROPHE (')</dt>
3858: <dd>Set the DOCTYPE token's system identifier to the empty string
3859: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
3860: (single-quoted) state</a>.</dd>
3861:
3862: <dt>EOF</dt>
3863: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3864: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3865: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3866:
3867: <dt>Anything else</dt>
3868: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3869: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3870: DOCTYPE state</a>.</dd>
3871:
1.618 mike 3872: </dl><h5 id="after-doctype-system-keyword-state"><span class="secno">9.2.4.63 </span><dfn>After DOCTYPE system keyword state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.444 mike 3873:
3874: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3875:
3876: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3877: <dt>U+000A LINE FEED (LF)</dt>
3878: <dt>U+000C FORM FEED (FF)</dt>
3879: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3880: <dt>U+0020 SPACE</dt>
3881: <dd>Switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier
3882: state</a>.</dd>
3883:
1.620 mike 3884: <dt>U+0022 QUOTATION MARK (")</dt>
3885: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
3886: identifier to the empty string (not missing), then switch to the
3887: <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier (double-quoted) state</a>.</dd>
3888:
3889: <dt>U+0027 APOSTROPHE (')</dt>
3890: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
3891: identifier to the empty string (not missing), then switch to the
3892: <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier (single-quoted) state</a>.</dd>
3893:
3894: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3895: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3896: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3897: token. Switch to the <a href="#data-state">data state</a>.</dd>
3898:
1.444 mike 3899: <dt>EOF</dt>
3900: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3901: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3902: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3903:
3904: <dt>Anything else</dt>
1.620 mike 3905: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3906: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3907: DOCTYPE state</a>.</dd>
1.444 mike 3908:
1.618 mike 3909: </dl><h5 id="before-doctype-system-identifier-state"><span class="secno">9.2.4.64 </span><dfn>Before DOCTYPE system identifier state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3910:
3911: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3912:
3913: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3914: <dt>U+000A LINE FEED (LF)</dt>
3915: <dt>U+000C FORM FEED (FF)</dt>
3916: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3917: <dt>U+0020 SPACE</dt>
3918: <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
3919:
3920: <dt>U+0022 QUOTATION MARK (")</dt>
3921: <dd>Set the DOCTYPE token's system identifier to the empty string
3922: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
3923: (double-quoted) state</a>.</dd>
3924:
3925: <dt>U+0027 APOSTROPHE (')</dt>
3926: <dd>Set the DOCTYPE token's system identifier to the empty string
3927: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
3928: (single-quoted) state</a>.</dd>
3929:
3930: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3931: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3932: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3933: token. Switch to the <a href="#data-state">data state</a>.</dd>
3934:
3935: <dt>EOF</dt>
3936: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3937: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3938: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3939:
3940: <dt>Anything else</dt>
3941: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3942: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3943: DOCTYPE state</a>.</dd>
3944:
1.618 mike 3945: </dl><h5 id="doctype-system-identifier-double-quoted-state"><span class="secno">9.2.4.65 </span><dfn>DOCTYPE system identifier (double-quoted) state</dfn></h5>
1.1 mike 3946:
3947: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3948:
3949: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
1.541 mike 3950: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier
3951: state</a>.</dd>
1.1 mike 3952:
3953: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3954: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3955: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3956: token. Switch to the <a href="#data-state">data state</a>.</dd>
3957:
3958: <dt>EOF</dt>
3959: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3960: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3961: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3962:
3963: <dt>Anything else</dt>
1.541 mike 3964: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3965: DOCTYPE token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
1.1 mike 3966: identifier (double-quoted) state</a>.</dd>
3967:
1.618 mike 3968: </dl><h5 id="doctype-system-identifier-single-quoted-state"><span class="secno">9.2.4.66 </span><dfn>DOCTYPE system identifier (single-quoted) state</dfn></h5>
1.1 mike 3969:
3970: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3971:
3972: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
1.541 mike 3973: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier
3974: state</a>.</dd>
1.1 mike 3975:
3976: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3977: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3978: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3979: token. Switch to the <a href="#data-state">data state</a>.</dd>
3980:
3981: <dt>EOF</dt>
3982: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3983: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3984: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3985:
3986: <dt>Anything else</dt>
1.541 mike 3987: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3988: DOCTYPE token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
1.1 mike 3989: identifier (single-quoted) state</a>.</dd>
3990:
1.618 mike 3991: </dl><h5 id="after-doctype-system-identifier-state"><span class="secno">9.2.4.67 </span><dfn>After DOCTYPE system identifier state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 3992:
3993: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3994:
3995: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3996: <dt>U+000A LINE FEED (LF)</dt>
3997: <dt>U+000C FORM FEED (FF)</dt>
3998: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3999: <dt>U+0020 SPACE</dt>
1.541 mike 4000: <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier
4001: state</a>.</dd>
1.1 mike 4002:
4003: <dt>U+003E GREATER-THAN SIGN (>)</dt>
4004: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
4005: state</a>.</dd>
4006:
4007: <dt>EOF</dt>
4008: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
4009: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
4010: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
4011:
4012: <dt>Anything else</dt>
4013: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
4014: state</a>. (This does <em>not</em> set the DOCTYPE token's
4015: <i>force-quirks flag</i> to <i>on</i>.)</dd>
4016:
1.618 mike 4017: </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.68 </span><dfn>Bogus DOCTYPE state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 4018:
4019: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
4020:
4021: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
4022: <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
4023: state</a>.</dd>
4024:
4025: <dt>EOF</dt>
4026: <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
4027: <a href="#data-state">data state</a>.</dd>
4028:
4029: <dt>Anything else</dt>
4030: <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
4031:
1.618 mike 4032: </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.69 </span><dfn>CDATA section state</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 4033:
4034: <p>Consume every character up to the next occurrence of the three
4035: character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
4036: BRACKET U+003E GREATER-THAN SIGN (<code title="">]]></code>), or the
4037: end of the file (EOF), whichever comes first. Emit a series of
4038: character tokens consisting of all the characters consumed except
4039: the matching three character sequence at the end (if one was found
4040: before the end of the file).</p>
4041:
4042: <p>Switch to the <a href="#data-state">data state</a>.</p>
4043:
4044: <p>If the end of the file was reached, reconsume the EOF
4045: character.</p>
4046:
4047:
4048:
1.618 mike 4049: <h5 id="tokenizing-character-references"><span class="secno">9.2.4.70 </span>Tokenizing character references</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 4050:
4051: <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
4052: reference</dfn>. This definition is used when parsing character
1.299 mike 4053: references <a href="#character-reference-in-data-state" title="character reference in data state">in
1.1 mike 4054: text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
4055: state">in attributes</a>.</p>
4056:
4057: <p>The behavior depends on the identity of the next character (the
4058: one immediately after the U+0026 AMPERSAND character):</p>
4059:
4060: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
4061: <dt>U+000A LINE FEED (LF)</dt>
4062: <dt>U+000C FORM FEED (FF)</dt>
4063: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
4064: <dt>U+0020 SPACE</dt>
4065: <dt>U+003C LESS-THAN SIGN</dt>
4066: <dt>U+0026 AMPERSAND</dt>
4067: <dt>EOF</dt>
4068: <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
4069:
4070: <dd>Not a character reference. No characters are consumed, and
4071: nothing is returned. (This is not an error, either.)</dd>
4072:
4073:
4074: <dt>U+0023 NUMBER SIGN (#)</dt>
4075:
4076: <dd>
4077:
4078: <p>Consume the U+0023 NUMBER SIGN.</p>
4079:
4080: <p>The behavior further depends on the character after the U+0023
4081: NUMBER SIGN:</p>
4082:
4083: <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
4084: <dt>U+0058 LATIN CAPITAL LETTER X</dt>
4085:
4086: <dd>
4087:
4088: <p>Consume the X.</p>
4089:
4090: <p>Follow the steps below, but using the range of characters
1.464 mike 4091: U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), U+0061 LATIN
4092: SMALL LETTER A to U+0066 LATIN SMALL LETTER F, and U+0041 LATIN
4093: CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F (in other
4094: words, 0-9, A-F, a-f).</p>
1.1 mike 4095:
4096: <p>When it comes to interpreting the number, interpret it as a
4097: hexadecimal number.</p>
4098:
4099: </dd>
4100:
4101:
4102: <dt>Anything else</dt>
4103:
4104: <dd>
4105:
4106: <p>Follow the steps below, but using the range of characters
1.464 mike 4107: U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9).</p>
1.1 mike 4108:
4109: <p>When it comes to interpreting the number, interpret it as a
4110: decimal number.</p>
4111:
4112: </dd>
4113:
4114: </dl><p>Consume as many characters as match the range of characters
4115: given above.</p>
4116:
4117: <p>If no characters match the range, then don't consume any
4118: characters (and unconsume the U+0023 NUMBER SIGN character and, if
4119: appropriate, the X character). This is a <a href="#parse-error">parse
4120: error</a>; nothing is returned.</p>
4121:
4122: <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
4123: that too. If it isn't, there is a <a href="#parse-error">parse
4124: error</a>.</p>
4125:
4126: <p>If one or more characters match the range, then take them all
4127: and interpret the string of characters as a number (either
4128: hexadecimal or decimal as appropriate).</p>
4129:
4130: <p>If that number is one of the numbers in the first column of the
4131: following table, then this is a <a href="#parse-error">parse error</a>. Find the
4132: row with that number in the first column, and return a character
4133: token for the Unicode character given in the second column of that
4134: row.</p>
4135:
4136: <table><thead><tr><th>Number </th><th colspan="2">Unicode character
4137: </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
4138: </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
1.464 mike 4139: </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN (€)
1.1 mike 4140: </td></tr><tr><td>0x81 </td><td>U+0081 </td><td><control>
1.464 mike 4141: </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK (‚)
4142: </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK (ƒ)
4143: </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK („)
4144: </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS (…)
4145: </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER (†)
4146: </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER (‡)
4147: </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT (ˆ)
4148: </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN (‰)
4149: </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON (Š)
4150: </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK (‹)
4151: </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE (Œ)
1.1 mike 4152: </td></tr><tr><td>0x8D </td><td>U+008D </td><td><control>
1.464 mike 4153: </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON (Ž)
1.1 mike 4154: </td></tr><tr><td>0x8F </td><td>U+008F </td><td><control>
4155: </td></tr><tr><td>0x90 </td><td>U+0090 </td><td><control>
1.464 mike 4156: </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK (‘)
4157: </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK (’)
4158: </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK (“)
4159: </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK (”)
4160: </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET (•)
4161: </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH (–)
4162: </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH (—)
4163: </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE (˜)
4164: </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN (™)
4165: </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON (š)
4166: </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK (›)
4167: </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE (œ)
1.1 mike 4168: </td></tr><tr><td>0x9D </td><td>U+009D </td><td><control>
1.464 mike 4169: </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON (ž)
4170: </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS (Ÿ)
1.315 mike 4171: </td></tr></tbody></table><p>Otherwise, if the number is in the range 0xD800 to 0xDFFF<!--
4172: surrogates not allowed; see the comment in the "preprocessing the
4173: input stream" section for details --> or is greater than 0x10FFFF,
4174: then this is a <a href="#parse-error">parse error</a>. Return a U+FFFD
4175: REPLACEMENT CHARACTER.</p>
1.18 mike 4176:
4177: <p>Otherwise, return a character token for the Unicode character
1.1 mike 4178: whose code point is that number.
4179:
4180: <!-- this is the same as the equivalent list in the input stream
4181: section -->
4182: If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
4183: allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
4184: allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
1.315 mike 4185: 0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xFDD0 to
4186: 0xFDEF, or is one of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF,
4187: 0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE,
4188: 0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF,
4189: 0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE,
4190: 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF,
4191: 0x10FFFE, or 0x10FFFF, then this is a <a href="#parse-error">parse
4192: error</a>.</p>
1.1 mike 4193:
4194: </dd>
4195:
4196:
4197: <dt>Anything else</dt>
4198:
4199: <dd>
4200:
4201: <p>Consume the maximum number of characters possible, with the
4202: consumed characters matching one of the identifiers in the first
4203: column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
4204: <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
4205:
4206: <p>If no match can be made, then this is a <a href="#parse-error">parse
4207: error</a>. No characters are consumed, and nothing is
4208: returned.</p>
4209:
1.588 mike 4210: <p>If the last character matched is not a U+003B SEMICOLON
4211: character (;), there is a <a href="#parse-error">parse error</a>.</p>
1.1 mike 4212:
4213: <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
4214: attribute</a>, and the last character matched is not a U+003B
1.588 mike 4215: SEMICOLON character (;), and the next character is in the range
4216: U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), U+0041 LATIN
4217: CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z, or U+0061 LATIN
4218: SMALL LETTER A to U+007A LATIN SMALL LETTER Z, then, for
4219: historical reasons, all the characters that were matched after the
4220: U+0026 AMPERSAND character (&) must be unconsumed, and nothing
4221: is returned.</p>
1.1 mike 4222:
4223: <p>Otherwise, return a character token for the character
4224: corresponding to the character reference name (as given by the
4225: second column of the <a href="named-character-references.html#named-character-references">named character references</a>
4226: table).</p>
4227:
4228: <div class="example">
4229:
4230: <p>If the markup contains <code title="">I'm &notit; I tell
4231: you</code>, the character reference is parsed as "not", as in,
4232: <code title="">I'm ¬it; I tell you</code>. But if the markup
4233: was <code title="">I'm &notin; I tell you</code>, the
4234: character reference would be parsed as "notin;", resulting in
4235: <code title="">I'm ∉ I tell you</code>.</p>
4236:
4237: </div>
4238:
4239: </dd>
4240:
1.266 mike 4241: </dl></div><div class="impl">
4242:
1.363 mike 4243: <!-- v2: One thing that this doesn't define is handling deeply
4244: nested documents. There are compatibility requirements around that:
4245: you can't throw away the elements altogether, consider Tux made only
4246: with opening <font> elements, one per character. Seems that the best
4247: thing to do is to close some formatting elements from the middle of
4248: the stack when you hit a limit, or something. -->
4249:
1.614 mike 4250: <h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 4251:
4252: <p>The input to the tree construction stage is a sequence of tokens
4253: from the <a href="#tokenization">tokenization</a> stage. The tree construction
4254: stage is associated with a DOM <code>Document</code> object when a
4255: parser is created. The "output" of this stage consists of
4256: dynamically modifying or extending that document's DOM tree.</p>
4257:
4258: <p>This specification does not define when an interactive user agent
4259: has to render the <code>Document</code> so that it is available to
4260: the user, or when it has to begin accepting user input.</p>
4261:
4262: <p>As each token is emitted from the tokenizer, the user agent must
4263: process the token according to the rules given in the section
4264: corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
4265:
4266: <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
4267: character</dfn> into a node, if that node has a child immediately
4268: before where the character is to be inserted, and that child is a
4269: <code>Text</code> node, and that <code>Text</code> node was the last
4270: node that the parser inserted into the document, then the character
4271: must be appended to that <code>Text</code> node; otherwise, a new
4272: <code>Text</code> node whose data is just that character must be
4273: inserted in the appropriate place.</p>
4274:
4275: <div class="example">
4276:
4277: <p>Here are some sample inputs to the parser and the corresponding
4278: number of text nodes that they result in, assuming a user agent
4279: that executes scripts.</p>
4280:
4281: <table><thead><tr><th>Input </th><th>Number of text nodes
4282: </th></tr></thead><tbody><tr><td><pre>A<script>
4283: var script = document.getElementsByTagName('script')[0];
4284: document.body.removeChild(script);
4285: </script>B</pre>
4286: </td><td>Two adjacent text nodes in the document, containing "A" and "B".
4287: </td></tr><tr><td><pre>A<script>
4288: var text = document.createTextNode('B');
4289: document.body.appendChild(text);
4290: </script>C</pre>
4291: </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
4292: </td></tr><tr><td><pre>A<script>
4293: var text = document.getElementsByTagName('script')[0].firstChild;
4294: text.data = 'B';
4295: document.body.appendChild(text);
4296: </script>B</pre>
4297: </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
4298: </td></tr><tr><td><pre>A<table>B<tr>C</tr>C</table></pre>
4299: </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>.)
4300: </td></tr><tr><td><pre>A<table><tr> B</tr> B</table></pre>
4301: </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>.)
4302: </td></tr><tr><td><pre>A<table><tr> B</tr> </em>C</table></pre>
4303: </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.)
4304: </td></tr></tbody></table></div>
4305:
4306: <p id="mutation-during-parsing">DOM mutation events must not fire
4307: for changes caused by the UA parsing the document. (Conceptually,
4308: the parser is not mutating the DOM, it is constructing it.) This
1.159 mike 4309: 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 4310:
4311: <p class="note">Not all of the tag names mentioned below are
4312: conformant tag names in this specification; many are included to
4313: handle legacy content. They still form part of the algorithm that
4314: implementations are required to implement to claim conformance.</p>
4315:
4316: <p class="note">The algorithm described below places no limit on the
4317: depth of the DOM tree generated, or on the length of tag names,
4318: attribute names, attribute values, text nodes, etc. While
4319: implementors are encouraged to avoid arbitrary limits, it is
4320: recognized that <a href="infrastructure.html#hardwareLimitations">practical
1.445 mike 4321: concerns</a> will likely force user agents to impose nesting depth
4322: constraints.</p>
1.1 mike 4323:
4324:
1.614 mike 4325: <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 4326:
4327: <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
4328: element for the token">create an element for a token</dfn> in a
4329: particular namespace, the UA must create a node implementing the
4330: interface appropriate for the element type corresponding to the tag
4331: name of the token in the given namespace (as given in the
4332: specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
4333: element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
4334: defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
4335: the tag name being the name of that element, with the node being in
4336: the given namespace, and with the attributes on the node being those
4337: given in the given token.</p>
4338:
4339: <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
1.426 mike 4340: namespace</a> that is not defined in this specification (or
4341: <a href="infrastructure.html#other-applicable-specifications">other applicable specifications</a>) is
1.44 mike 4342: <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1 mike 4343: interface is not defined by that namespace's specification must use
4344: the interface <code>Element</code>.</p>
4345:
4346: <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
4347: created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
4348: invoked once the attributes are set. (This initializes the element's
4349: <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
4350: attributes.)</p>
4351:
4352: <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
4353: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
4354: for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
4355: append this node to the <a href="#current-node">current node</a>, and push it onto
4356: the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
4357: <a href="#current-node">current node</a>.</p>
4358:
4359: <p>The steps below may also require that the UA insert an HTML
4360: element in a particular place, in which case the UA must follow the
4361: same steps except that it must insert or append the new node in the
4362: location specified instead of appending it to the <a href="#current-node">current
4363: node</a>. (This happens in particular during the parsing of
4364: tables with invalid content.)</p>
4365:
4366: <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
4367: algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
4368: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
4369: 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
4370: <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
4371: created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
4372: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
4373: inserting it wherever it is to be inserted.</p>
4374:
4375: <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
4376: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
4377: for the token</a> in the given namespace, and then append this
4378: node to the <a href="#current-node">current node</a>, and push it onto the
4379: <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
4380: <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>
4381: whose value is not exactly the same as the element's namespace, that
4382: is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
4383: element has an <code title="">xmlns:xlink</code> attribute in the
4384: <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
4385: Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
4386:
4387: <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
4388: attributes</dfn> for a token, then, if the token has an attribute
4389: named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
4390:
4391: <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
4392: attributes</dfn> for a token, then, for each attribute on the token
4393: whose attribute name is one of the ones in the first column of the
4394: following table, change the attribute's name to the name given in
4395: the corresponding cell in the second column. (This fixes the case of
4396: SVG attributes that are not all lowercase.)</p>
4397:
4398: <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
4399: </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
4400: </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
4401: </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
4402: </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
4403: </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
4404: </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
4405: </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
4406: </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
4407: </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
4408: </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
4409: </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
4410: </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
4411: </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
4412: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
4413: </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
4414: </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
4415: </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
4416: </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
4417: </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
4418: </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
4419: </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
4420: </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
4421: </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
4422: </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
4423: </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
4424: </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
4425: </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
4426: </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
4427: </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
4428: </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
4429: </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
4430: </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
4431: </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
4432: </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
4433: </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
4434: </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
4435: </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
4436: </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
4437: </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
4438: </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
4439: </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
4440: </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
4441: </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
4442: </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
4443: </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
4444: </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
4445: </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
4446: </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
4447: </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
4448: </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
4449: </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
4450: </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
4451: </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
4452: </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
4453: </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
4454: </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
4455: </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
4456: </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
4457: </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
4458: </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
4459: </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
4460: </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
4461: </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
4462: foreign attributes</dfn> for a token, then, if any of the attributes
4463: on the token match the strings given in the first column of the
4464: following table, let the attribute be a namespaced attribute, with
4465: the prefix being the string given in the corresponding cell in the
4466: second column, the local name being the string given in the
4467: corresponding cell in the third column, and the namespace being the
4468: namespace given in the corresponding cell in the fourth
4469: column. (This fixes the use of namespaced attributes, in particular
4470: <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
4471: the <span>XML namespace</span></a>.)</p>
4472:
4473: <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
4474: </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>
4475: </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>
4476: </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>
4477: </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>
4478: </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>
4479: </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>
4480: </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>
4481: </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 -->
4482: </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>
4483: </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>
4484: </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>
4485: </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 4486: </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 4487: <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
4488: following steps. These algorithms are always invoked in response to
4489: a start tag token.</p>
4490:
4491: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
4492:
1.91 mike 4493: <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
1.541 mike 4494: text element parsing algorithm</a>, switch the tokenizer to the
4495: <a href="#rawtext-state">RAWTEXT state</a>; otherwise the algorithm invoked
4496: was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>,
4497: switch the tokenizer to the <a href="#rcdata-state">RCDATA state</a>.</p></li>
1.1 mike 4498:
4499: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
4500: <a href="#insertion-mode">insertion mode</a>.</p>
4501:
1.540 mike 4502: </li><li><p>Then, switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: text">text</a>".</p></li>
1.1 mike 4503:
1.614 mike 4504: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 4505:
4506: <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
4507: tags</dfn>, then, while the <a href="#current-node">current node</a> is a
1.422 mike 4508: <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 4509: <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
4510: <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
4511: <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
4512: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4513: elements</a>.</p>
4514:
4515: <p>If a step requires the UA to generate implied end tags but lists
4516: an element to exclude from the process, then the UA must perform the
4517: above steps as if that element was not in the above list.</p>
4518:
4519:
1.614 mike 4520: <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 4521:
4522: <p>Foster parenting happens when content is misnested in tables.</p>
4523:
4524: <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
4525: parent">foster parented</dfn>, the node <var title="">node</var>
4526: must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
4527:
4528: <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
4529: 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
4530: elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
4531: such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
4532: the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
4533: case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
4534: element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
1.159 mike 4535: <code><a href="semantics.html#the-html-element-0">html</a></code> element). Otherwise, if there is a
1.1 mike 4536: <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
4537: elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
4538: <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
4539: node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
4540: the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
4541: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
4542:
4543: <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
4544: 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
4545: elements</a>, then <var title="">node</var> must be inserted
4546: immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
4547: the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
4548: element</a></i>; otherwise, <var title="">node</var> must be
4549: <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
4550:
4551:
4552:
1.614 mike 4553: <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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 4554:
4555: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
4556: mode: initial">initial</a>", tokens must be handled as follows:</p>
4557:
4558: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4559: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4560: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4561: <dd>
4562: <p>Ignore the token.</p>
4563: </dd>
4564:
4565: <dt>A comment token</dt>
4566: <dd>
4567: <p>Append a <code>Comment</code> node to the <code>Document</code>
4568: object with the <code title="">data</code> attribute set to the
4569: data given in the comment token.</p>
4570: </dd>
4571:
4572: <dt>A DOCTYPE token</dt>
4573: <dd>
4574:
4575: <p>If the DOCTYPE token's name is not a
4576: <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
4577: missing, or the token's system identifier is neither missing nor a
4578: <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
1.465 mike 4579: "<code><a href="infrastructure.html#about:legacy-compat">about:legacy-compat</a></code>", and none of the sets of
1.1 mike 4580: conditions in the following list are matched, then there is a
4581: <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
4582: following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
4583: permitted DOCTYPE</dfn>.</p>
4584:
4585: <ul><!-- only things that trigger no-quirks mode and were valid in
4586: 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 4587: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 4588: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD HTML 4.0//EN</code>", and the
4589: token's system identifier is either missing or the
4590: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
4591:
4592: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 4593: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 4594: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD HTML 4.01//EN</code>", and the
4595: token's system identifier is either missing or the
4596: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
4597:
4598: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 4599: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 4600: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD XHTML 1.0 Strict//EN</code>",
4601: and the token's system identifier is the
4602: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
4603:
4604: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 4605: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 4606: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD XHTML 1.1//EN</code>", and the
4607: token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
4608: string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
4609:
4610: </ul><p>Conformance checkers may, based on the values (including
4611: presence or lack thereof) of the DOCTYPE token's name, public
4612: identifier, or system identifier, switch to a conformance checking
4613: mode for another language (e.g. based on the DOCTYPE token a
4614: conformance checker could recognize that the document is an
1.183 mike 4615: HTML4-era document, and defer to an HTML4 conformance
1.1 mike 4616: checker.)</p>
4617:
4618: <p>Append a <code>DocumentType</code> node to the
4619: <code>Document</code> node, with the <code title="">name</code>
4620: attribute set to the name given in the DOCTYPE token, or the empty
4621: string if the name was missing; the <code title="">publicId</code>
4622: attribute set to the public identifier given in the DOCTYPE token,
4623: or the empty string if the public identifier was missing; the
4624: <code title="">systemId</code> attribute set to the system
4625: identifier given in the DOCTYPE token, or the empty string if the
4626: system identifier was missing; and the other attributes specific
4627: to <code>DocumentType</code> objects set to null and empty lists
4628: as appropriate. Associate the <code>DocumentType</code> node with
4629: the <code>Document</code> object so that it is returned as the
4630: value of the <code title="">doctype</code> attribute of the
4631: <code>Document</code> object.</p>
4632:
4633: <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
4634: one of the conditions in the following list, then set the
4635: <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
4636:
4637: <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
4638: <li> The name is set to anything other than "<code title="">HTML</code>". </li>
4639: <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
4640: <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
4641: <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
4642: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
4643: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
4644: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
4645: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
4646: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
4647: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
4648: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
4649: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
4650: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
4651: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
4652: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
4653: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
4654: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
4655: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
4656: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
4657: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
4658: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
4659: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
4660: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
4661: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
4662: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
4663: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
4664: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
4665: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
4666: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
4667: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
4668: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
4669: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
4670: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
4671: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
4672: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
4673: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
4674: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
4675: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
4676: <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
4677: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
4678: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
4679: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
4680: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
4681: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
4682: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
4683: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
4684: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
4685: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
4686: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
4687: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
4688: <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
4689: <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
4690: <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
4691: <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
4692: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
4693: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
4694: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
4695: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
4696: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
4697: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
4698: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
4699: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
4700: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
4701: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
4702: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
4703: <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
4704: <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
4705: <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
4706: <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
4707: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
4708: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
4709: <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
4710: <li> The public identifier is set to: "<code title="">HTML</code>" </li>
4711: <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
4712: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
4713: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
4714: </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
4715: in the following list, then set the <code>Document</code> to
4716: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
4717:
4718: <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
4719: <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
4720: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
4721: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
4722: </ul><p>The name, system identifier, and public identifier strings must
4723: be compared to the values given in the lists above in an
4724: <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
4725: whose value is the empty string is not considered missing for the
4726: purposes of the conditions above.</p>
4727:
4728: <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>
4729:
4730: </dd>
4731:
4732: <dt>Anything else</dt>
4733: <dd>
4734:
4735: <p><a href="#parse-error">Parse error</a>.</p>
4736:
4737: <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
4738:
4739: <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
4740: reprocess the current token.</p>
4741:
4742: </dd>
4743:
1.614 mike 4744: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 4745:
4746: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
4747: mode: before html">before html</a>", tokens must be handled as follows:</p>
4748:
4749: <dl class="switch"><dt>A DOCTYPE token</dt>
4750: <dd>
4751: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4752: </dd>
4753:
4754: <dt>A comment token</dt>
4755: <dd>
4756: <p>Append a <code>Comment</code> node to the <code>Document</code>
4757: object with the <code title="">data</code> attribute set to the
4758: data given in the comment token.</p>
4759: </dd>
4760:
4761: <dt>A character token that is one of U+0009 CHARACTER
4762: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4763: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4764: <dd>
4765: <p>Ignore the token.</p>
4766: </dd>
4767:
4768: <dt>A start tag whose tag name is "html"</dt>
4769: <dd>
4770:
4771: <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
4772: namespace</a>. Append it to the <code>Document</code>
4773: object. Put this element in the <a href="#stack-of-open-elements">stack of open
4774: elements</a>.</p>
4775:
4776: <p id="parser-appcache">If the <code>Document</code> is being
4777: loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
4778: <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
4779: has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
4780: then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
4781: attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
4782: 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 4783: algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
4784: any <a href="infrastructure.html#url-fragment" title="url-fragment"><fragment></a> component
4785: removed; otherwise, if there is no such attribute or resolving it
4786: fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
4787: cache selection algorithm</a> with no manifest. The algorithm
4788: must be passed the <code>Document</code> object.</p>
1.1 mike 4789:
4790: <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>
4791:
4792: </dd>
4793:
1.334 mike 4794: <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
4795: <dd>
4796: <p>Act as described in the "anything else" entry below.</p>
4797: </dd>
4798:
4799: <dt>Any other end tag</dt>
4800: <dd>
4801: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4802: </dd>
4803:
1.1 mike 4804: <dt>Anything else</dt>
4805: <dd>
4806:
1.159 mike 4807: <p>Create an <code><a href="semantics.html#the-html-element-0">html</a></code> element. Append it to the
1.1 mike 4808: <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
4809: of open elements</a>.</p>
4810:
4811: <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
4812: context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
4813: algorithm</a> with no manifest, passing it the
4814: <code>Document</code> object.</p>
4815:
4816: <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
4817: reprocess the current token.</p>
4818:
4819: </dd>
4820:
4821: </dl><p>The root element can end up being removed from the
4822: <code>Document</code> object, e.g. by scripts; nothing in particular
4823: happens in such cases, content continues being appended to the nodes
4824: as described in the next section.</p>
4825:
4826:
1.614 mike 4827: <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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 4828:
4829: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
4830: mode: before head">before head</a>", tokens must be handled as follows:</p>
4831:
4832: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4833: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4834: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4835: <dd>
4836: <p>Ignore the token.</p> <!-- :-( -->
4837: </dd>
4838:
4839: <dt>A comment token</dt>
4840: <dd>
4841: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4842: node</a> with the <code title="">data</code> attribute set to
4843: the data given in the comment token.</p>
4844: </dd>
4845:
4846: <dt>A DOCTYPE token</dt>
4847: <dd>
4848: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4849: </dd>
4850:
4851: <dt>A start tag whose tag name is "html"</dt>
4852: <dd>
4853: <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
4854: mode</a>.</p>
4855: </dd>
4856:
4857: <dt>A start tag whose tag name is "head"</dt>
4858: <dd>
4859:
4860: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4861:
4862: <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
1.159 mike 4863: to the newly created <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 4864:
4865: <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>
4866:
4867: </dd>
4868:
4869: <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
4870: <dd>
4871:
4872: <p>Act as if a start tag token with the tag name "head" and no
4873: attributes had been seen, then reprocess the current token.</p>
4874:
4875: </dd>
4876:
4877: <dt>Any other end tag</dt>
4878: <dd>
4879:
4880: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4881:
4882: </dd>
4883:
4884: <dt>Anything else</dt>
4885: <dd>
4886:
4887: <p>Act as if a start tag token with the tag name "head" and no
4888: attributes had been seen, then reprocess the current
4889: token.</p>
4890:
4891: </dd>
4892:
1.614 mike 4893: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 4894:
4895: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
4896: mode: in head">in head</a>", tokens must be handled as follows:</p>
4897:
4898: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4899: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4900: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4901: <dd>
4902: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
4903: the <a href="#current-node">current node</a>.</p>
4904: </dd>
4905:
4906: <dt>A comment token</dt>
4907: <dd>
4908: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4909: node</a> with the <code title="">data</code> attribute set to
4910: the data given in the comment token.</p>
4911: </dd>
4912:
4913: <dt>A DOCTYPE token</dt>
4914: <dd>
4915: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4916: </dd>
4917:
4918: <dt>A start tag whose tag name is "html"</dt>
4919: <dd>
4920: <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
4921: mode</a>.</p>
4922: </dd>
4923:
4924: <dt>A start tag whose tag name is one of: "base", "command",
4925: "link"</dt>
4926: <dd>
4927:
4928: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4929: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4930: elements</a>.</p>
4931:
4932: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4933: token's <i>self-closing flag</i></a>, if it is set.</p>
4934:
4935: </dd>
4936:
4937: <dt>A start tag whose tag name is "meta"</dt>
4938: <dd>
4939:
4940: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4941: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4942: elements</a>.</p>
4943:
4944: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4945: token's <i>self-closing flag</i></a>, if it is set.</p>
4946:
4947: <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
4948: value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
4949: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
4950: encoding</a> to the encoding given by the value of the
4951: <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
4952:
4953: <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
4954: applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
4955: Content-Type</a> to its value returns a supported encoding
4956: <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
4957: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
4958: encoding</a> to the encoding <var title="">encoding</var>.</p>
4959:
4960: </dd>
4961:
4962: <dt>A start tag whose tag name is "title"</dt>
4963: <dd>
4964: <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
4965: </dd>
4966:
4967: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
4968: <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
4969: <dd>
1.91 mike 4970: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 4971: </dd>
4972:
4973: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
4974: <dd>
4975:
4976: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4977:
4978: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
4979: noscript</a>".</p>
4980:
4981: </dd>
4982:
4983: <dt id="scriptTag">A start tag whose tag name is "script"</dt>
4984: <dd>
4985:
4986: <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
4987: <a href="#html-namespace-0">HTML namespace</a>.</p></li>
4988:
4989: <li>
4990:
4991: <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
4992:
4993: <p class="note">This ensures that, if the script is external,
1.159 mike 4994: any <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>
1.1 mike 4995: calls in the script will execute in-line, instead of blowing the
4996: document away, as would happen in most other cases. It also
4997: prevents the script from executing until the end tag is
4998: seen.</p>
4999:
5000: </li>
5001:
5002: <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
5003: fragment parsing algorithm</a>, then mark the
1.484 mike 5004: <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-started">"already
5005: started"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
1.1 mike 5006:
5007: <li><p>Append the new element to the <a href="#current-node">current node</a>
5008: and push it onto the <a href="#stack-of-open-elements">stack of open
5009: elements</a>.</p></li>
5010:
1.541 mike 5011: <li><p>Switch the tokenizer to the <a href="#script-data-state">script data
5012: state</a>.</p></li>
1.1 mike 5013:
5014: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
5015: <a href="#insertion-mode">insertion mode</a>.</p>
5016:
1.540 mike 5017: </li><li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: text">text</a>".</p></li>
1.1 mike 5018:
5019: </ol></dd>
5020:
5021: <dt>An end tag whose tag name is "head"</dt>
5022: <dd>
5023:
5024: <p>Pop the <a href="#current-node">current node</a> (which will be the
1.159 mike 5025: <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 5026: elements</a>.</p>
5027:
5028: <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>
5029:
5030: </dd>
5031:
5032: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
5033: <dd>
5034: <p>Act as described in the "anything else" entry below.</p>
5035: </dd>
5036:
5037: <dt>A start tag whose tag name is "head"</dt>
5038: <dt>Any other end tag</dt>
5039: <dd>
5040: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5041: </dd>
5042:
5043: <dt>Anything else</dt>
5044: <dd>
5045:
5046: <!-- can't get here with an EOF and a fragment case -->
5047:
5048: <p>Act as if an end tag token with the tag name "head" had
5049: been seen, and reprocess the current token.</p>
5050:
5051: </dd>
5052:
1.614 mike 5053: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 5054:
5055: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
5056: mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
5057:
5058: <dl class="switch"><dt>A DOCTYPE token</dt>
5059: <dd>
5060: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5061: </dd>
5062:
5063: <dt>A start tag whose tag name is "html"</dt>
5064: <dd>
5065: <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
5066: mode</a>.</p>
5067: </dd>
5068:
5069: <dt>An end tag whose tag name is "noscript"</dt>
5070: <dd>
5071:
5072: <p>Pop the <a href="#current-node">current node</a> (which will be a
5073: <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
5074: elements</a>; the new <a href="#current-node">current node</a> will be a
1.159 mike 5075: <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 5076:
5077: <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>
5078:
5079: </dd>
5080:
5081: <dt>A character token that is one of U+0009 CHARACTER
5082: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
5083: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
5084: <dt>A comment token</dt>
5085: <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
5086: <dd>
5087: <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
5088: mode</a>.</p>
5089: </dd>
5090:
5091: <dt>An end tag whose tag name is "br"</dt>
5092: <dd>
5093: <p>Act as described in the "anything else" entry below.</p>
5094: </dd>
5095:
5096: <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
5097: <dt>Any other end tag</dt>
5098: <dd>
5099: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5100: </dd>
5101:
5102: <dt>Anything else</dt>
5103: <dd>
5104:
5105: <!-- can't get here with an EOF and a fragment case -->
5106:
5107: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
5108: name "noscript" had been seen and reprocess the current
5109: token.</p>
5110:
5111: </dd>
5112:
1.614 mike 5113: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 5114:
5115: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
5116: mode: after head">after head</a>", tokens must be handled as follows:</p>
5117:
5118: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
5119: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
5120: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
5121: <dd>
5122: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
5123: the <a href="#current-node">current node</a>.</p>
5124: </dd>
5125:
5126: <dt>A comment token</dt>
5127: <dd>
5128: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
5129: node</a> with the <code title="">data</code> attribute set to
5130: the data given in the comment token.</p>
5131: </dd>
5132:
5133: <dt>A DOCTYPE token</dt>
5134: <dd>
5135: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5136: </dd>
5137:
5138: <dt>A start tag whose tag name is "html"</dt>
5139: <dd>
5140: <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
5141: mode</a>.</p>
5142: </dd>
5143:
5144: <dt>A start tag whose tag name is "body"</dt>
5145: <dd>
5146:
5147: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5148:
5149: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5150:
5151: <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>
5152:
5153: </dd>
5154:
5155: <dt>A start tag whose tag name is "frameset"</dt>
5156: <dd>
5157:
5158: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5159:
5160: <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>
5161:
5162: </dd>
5163:
5164: <dt>A start tag token whose tag name is one of: "base", "link",
5165: "meta", "noframes", "script", "style", "title"</dt>
5166: <dd>
5167:
5168: <p><a href="#parse-error">Parse error</a>.</p>
5169:
5170: <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
5171: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
5172:
5173: <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
5174: mode</a>.</p>
5175:
5176: <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
5177: of open elements</a>.</p>
5178:
5179: <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
5180: pointer</a> cannot be null at this point.</p>
5181:
5182: </dd>
5183:
5184: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
5185: <dd>
5186: <p>Act as described in the "anything else" entry below.</p>
5187: </dd>
5188:
5189: <dt>A start tag whose tag name is "head"</dt>
5190: <dt>Any other end tag</dt>
5191: <dd>
5192: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5193: </dd>
5194:
5195: <dt>Anything else</dt>
5196: <dd>
5197: <p>Act as if a start tag token with the tag name "body" and no
5198: attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
5199: flag</a> back to "ok", and then reprocess the current
5200: token.</p>
5201: </dd>
5202:
1.614 mike 5203: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 5204:
5205: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
5206: mode: in body">in body</a>", tokens must be handled as follows:</p>
5207:
5208: <dl class="switch"><dt>A character token</dt>
5209: <dd>
5210:
5211: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5212: any.</p>
5213:
5214: <p><a href="#insert-a-character" title="insert a character">Insert the token's
5215: character</a> into the <a href="#current-node">current node</a>.</p>
5216:
5217: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
5218: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
5219: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
5220: flag</a> to "not ok".</p>
5221:
5222: </dd>
5223:
5224: <dt>A comment token</dt>
5225: <dd>
5226: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
5227: node</a> with the <code title="">data</code> attribute set to
5228: the data given in the comment token.</p>
5229: </dd>
5230:
5231: <dt>A DOCTYPE token</dt>
5232: <dd>
5233: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5234: </dd>
5235:
5236: <dt>A start tag whose tag name is "html"</dt>
5237: <dd>
5238: <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
5239: check to see if the attribute is already present on the top
5240: element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
5241: add the attribute and its corresponding value to that element.</p>
5242: </dd>
5243:
5244: <dt>A start tag token whose tag name is one of: "base", "command",
5245: "link", "meta", "noframes", "script", "style", "title"</dt>
5246: <dd>
5247: <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
5248: mode</a>.</p>
5249: </dd>
5250:
5251: <dt>A start tag whose tag name is "body"</dt>
5252: <dd>
5253:
5254: <p><a href="#parse-error">Parse error</a>.</p>
5255:
5256: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159 mike 5257: elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1 mike 5258: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
5259: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
5260:
5261: <p>Otherwise, for each attribute on the token, check to see if
1.159 mike 5262: the attribute is already present on the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 5263: element (the second element) on the <a href="#stack-of-open-elements">stack of open
5264: elements</a>. If it is not, add the attribute and its
5265: corresponding value to that element.</p>
5266:
5267: </dd>
5268:
5269: <dt>A start tag whose tag name is "frameset"</dt>
5270: <dd>
5271:
5272: <p><a href="#parse-error">Parse error</a>.</p>
5273:
5274: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159 mike 5275: elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1 mike 5276: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
5277: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
5278:
5279: <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
5280: the token.</p>
5281:
5282: <p>Otherwise, run the following steps:</p>
5283:
5284: <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
5285: elements</a> from its parent node, if it has one.</p></li>
5286:
5287: <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
5288: open elements</a>, from the <a href="#current-node">current node</a> up to,
1.159 mike 5289: but not including, the root <code><a href="semantics.html#the-html-element-0">html</a></code> element.</p>
1.1 mike 5290:
5291: </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
5292: token.</p></li>
5293:
5294: <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>
5295:
5296: </li></ol></dd>
5297:
5298: <dt>An end-of-file token</dt>
5299: <dd>
5300:
5301: <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
1.422 mike 5302: 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>
5303: 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 5304: <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
5305: <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
5306: <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 5307: <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 5308: this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
1.422 mike 5309: fragment cases) -->
1.1 mike 5310:
5311: <p><a href="#stop-parsing">Stop parsing</a>.</p>
5312:
5313: </dd>
5314:
5315: <dt>An end tag whose tag name is "body"</dt>
5316: <dd>
5317:
5318: <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
5319: in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
5320: token.</p>
5321:
5322: <!-- if we get here, the insertion mode here is forcibly "in
5323: body". -->
5324:
5325: <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
1.422 mike 5326: elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
1.1 mike 5327: <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
5328: <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
5329: <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
5330: <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
5331: <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
5332: <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 5333: <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
5334: <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 5335: error</a>.</p> <!-- (some of those are fragment cases, e.g. for
5336: <tbody> you'd have hit the first paragraph since the <body>
1.422 mike 5337: wouldn't be in scope, unless it was a fragment case) -->
1.1 mike 5338:
5339: <!-- If we ever change the frameset-ok flag to an insertion mode,
5340: then we'd have to somehow keep track of its state when we switch
5341: to after-body. -->
5342:
5343: <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>
5344:
5345: </dd>
5346:
5347: <dt>An end tag whose tag name is "html"</dt>
5348: <dd>
5349:
5350: <p>Act as if an end tag with tag name "body" had been seen,
5351: then, if that token wasn't ignored, reprocess the current
5352: token.</p>
5353:
5354: <p class="note">The fake end tag token here can only be
5355: ignored in the <a href="#fragment-case">fragment case</a>.</p>
5356:
5357: </dd>
5358:
5359: <!-- start tags for non-phrasing flow content elements -->
5360:
5361: <!-- the normal ones -->
5362: <dt>A start tag whose tag name is one of: "address", "article",
1.86 mike 5363: "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305 mike 5364: "details", "dir", "div", "dl", "fieldset", "figure", "footer",
5365: "header", "hgroup", "menu", "nav", "ol", "p", "section", "ul"</dt>
1.1 mike 5366: <dd>
5367:
5368: <!-- As of May 2008 this doesn't match any browser exactly, but is
5369: as close to what IE does as I can get without doing the non-tree
5370: DOM nonsense, and thus should actually afford better compatibility
5371: when implemented by the other browsers. -->
5372:
5373: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5374: an element in scope">has a <code>p</code> element in
5375: scope</a>, then act as if an end tag with the tag name
5376: "p" had been seen.</p>
5377:
5378: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5379:
5380: </dd>
5381:
5382: <!-- as normal, but close h1-h6 if it's the current node -->
5383: <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
5384: "h5", "h6"</dt>
5385: <dd>
5386:
5387: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5388: an element in scope">has a <code>p</code> element in
5389: scope</a>, then act as if an end tag with the tag name
5390: "p" had been seen.</p>
5391:
5392: <p>If the <a href="#current-node">current node</a> is an element whose tag name
5393: is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
5394: <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
5395: the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
5396: <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
5397:
5398: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5399:
5400: </dd>
5401:
5402: <!-- as normal, but drops leading newline -->
5403: <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
5404: <dd>
5405:
5406: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5407: an element in scope">has a <code>p</code> element in
5408: scope</a>, then act as if an end tag with the tag name
5409: "p" had been seen.</p>
5410:
5411: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5412:
5413: <p>If the next token is a U+000A LINE FEED (LF) character
5414: token, then ignore that token and move on to the next
5415: one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
5416: ignored as an authoring convenience.)</p>
5417:
5418: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5419:
5420: </dd>
5421:
5422: <!-- as normal, but interacts with the form element pointer -->
5423: <dt>A start tag whose tag name is "form"</dt>
5424: <dd>
5425:
5426: <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
5427: pointer</a> is not null, then this is a <a href="#parse-error">parse
5428: error</a>; ignore the token.</p>
5429:
5430: <p>Otherwise:</p>
5431:
5432: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5433: an element in scope">has a <code>p</code> element in
5434: scope</a>, then act as if an end tag with the tag name
5435: "p" had been seen.</p>
5436:
5437: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
5438: <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
5439: point to the element created.</p>
5440:
5441: </dd>
5442:
5443: <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
5444: <dt>A start tag whose tag name is "li"</dt>
5445: <dd>
5446:
5447: <p>Run the following algorithm:</p>
5448:
5449: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
5450:
5451: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
5452: node</a> (the bottommost node of the stack).</p></li>
5453:
1.578 mike 5454: <li><p><i>Loop</i>: If <var title="">node</var> is an
5455: <code><a href="semantics.html#the-li-element">li</a></code> element, then act as if an end tag with the tag
5456: name "li" had been seen, then jump to the last step.</p></li>
1.1 mike 5457:
1.578 mike 5458: <li><p>If <var title="">node</var> is not in the
1.1 mike 5459: <a href="#formatting">formatting</a> category, and is not in the
5460: <a href="#phrasing">phrasing</a> category, and is not an
1.306 mike 5461: <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 5462: element, then jump to the last step.</p></li> <!-- an element
5463: <foo> is in this list if the following markup:
5464:
5465: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
5466:
5467: ...results in the second <li> not being (in any way) a descendant
5468: of the first <li>, or if <foo> is a formatting element that gets
5469: reopened later. -->
5470:
5471: <li><p>Otherwise, set <var title="">node</var> to the previous
5472: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
5473: the step labeled <i>loop</i>.</p></li>
5474:
5475: <li>
5476:
5477: <p>This is the last step.</p>
5478:
5479: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5480: an element in scope">has a <code>p</code> element in
5481: scope</a>, then act as if an end tag with the tag name
5482: "p" had been seen.</p>
5483:
5484: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
5485: token.</p>
5486:
5487: </li>
5488:
5489: </ol></dd>
5490:
5491: <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases -->
1.422 mike 5492: <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
1.1 mike 5493: <dd>
5494:
5495: <p>Run the following algorithm:</p>
5496:
5497: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
5498:
5499: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
5500: node</a> (the bottommost node of the stack).</p></li>
5501:
5502: <li><p><i>Loop</i>: If <var title="">node</var> is a
1.422 mike 5503: <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
5504: tag with the same tag name as <var title="">node</var> had been
5505: seen, then jump to the last step.</p></li>
1.1 mike 5506:
5507: <li><p>If <var title="">node</var> is not in the
5508: <a href="#formatting">formatting</a> category, and is not in the
5509: <a href="#phrasing">phrasing</a> category, and is not an
1.306 mike 5510: <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 5511: element, then jump to the last step.</p></li> <!-- an element
5512: <foo> is in this list if the following markup:
5513:
5514: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
5515:
5516: ...results in the second <dt> not being (in any way) a descendant
5517: of the first <dt>, or if <foo> is a formatting element that gets
5518: reopened later. -->
5519:
5520: <li><p>Otherwise, set <var title="">node</var> to the previous
5521: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
5522: the step labeled <i>loop</i>.</p></li>
5523:
5524: <li>
5525:
5526: <p>This is the last step.</p>
5527:
5528: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5529: an element in scope">has a <code>p</code> element in
5530: scope</a>, then act as if an end tag with the tag name
5531: "p" had been seen.</p>
5532:
5533: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
5534: token.</p>
5535:
5536: </li>
5537:
5538: </ol></dd>
5539:
5540: <!-- same as normal, but effectively ends parsing -->
5541: <dt>A start tag whose tag name is "plaintext"</dt>
5542: <dd>
5543:
5544: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5545: an element in scope">has a <code>p</code> element in
5546: scope</a>, then act as if an end tag with the tag name
5547: "p" had been seen.</p>
5548:
5549: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5550:
1.541 mike 5551: <p>Switch the tokenizer to the <a href="#plaintext-state">PLAINTEXT state</a>.</p>
1.1 mike 5552:
1.541 mike 5553: <p class="note">Once a start tag with the tag name "plaintext" has
5554: been seen, that will be the last token ever seen other than
5555: character tokens (and the end-of-file token), because there is no
5556: way to switch out of the <a href="#plaintext-state">PLAINTEXT state</a>.</p>
1.1 mike 5557:
5558: </dd>
5559:
5560: <!-- end tags for non-phrasing flow content elements -->
5561:
5562: <!-- the normal ones -->
5563: <dt>An end tag whose tag name is one of: "address", "article",
1.86 mike 5564: "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305 mike 5565: "details", "dir", "div", "dl", "fieldset", "figure", "footer",
5566: "header", "hgroup", "listing", "menu", "nav", "ol", "pre",
5567: "section", "ul"</dt>
1.1 mike 5568: <dd>
5569:
5570: <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>
5571: with the same tag name as that of the token, then this is a
5572: <a href="#parse-error">parse error</a>; ignore the token.</p>
5573:
5574: <p>Otherwise, run these steps:</p>
5575:
5576: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5577:
5578: <li><p>If the <a href="#current-node">current node</a> is not an element with
5579: the same tag name as that of the token, then this is a
5580: <a href="#parse-error">parse error</a>.</p></li>
5581:
5582: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5583: until an element with the same tag name as the token has been
5584: popped from the stack.</p></li>
5585:
5586: </ol></dd>
5587:
5588: <!-- removes the form element pointer instead of the matching node -->
5589: <dt>An end tag whose tag name is "form"</dt>
5590: <dd>
5591:
5592: <p>Let <var title="">node</var> be the element that the
5593: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
5594: to.</p>
5595:
5596: <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
5597: to null.</p>
5598:
5599: <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
5600: elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
5601: scope">have <var title="">node</var> in scope</a>, then this is
5602: a <a href="#parse-error">parse error</a>; ignore the token.</p>
5603:
5604: <p>Otherwise, run these steps:</p>
5605:
5606: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5607:
5608: <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
5609: error</a>.</p></li>
5610:
5611: <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
5612: open elements</a>.</p></li>
5613:
5614: </ol></dd>
5615:
5616: <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
5617: <dt>An end tag whose tag name is "p"</dt>
5618: <dd>
5619:
5620: <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>
5621: with the same tag name as that of the token, then this is a
5622: <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
5623: "p" had been seen, then reprocess the current token.</p>
5624:
5625: <p>Otherwise, run these steps:</p>
5626:
5627: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
5628: for elements with the same tag name as the token.</p></li>
5629:
5630: <li><p>If the <a href="#current-node">current node</a> is not an element with
5631: the same tag name as that of the token, then this is a
5632: <a href="#parse-error">parse error</a>.</p></li>
5633:
5634: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5635: until an element with the same tag name as the token has been
5636: popped from the stack.</p></li>
5637:
5638: </ol></dd>
5639:
1.234 mike 5640: <!-- as normal, but needs care as the elements have optional tags, and are further scoped by <ol>/<ul> -->
5641: <dt>An end tag whose tag name is "li"</dt>
5642: <dd>
5643:
5644: <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
5645: item scope</a> with the same tag name as that of the token,
5646: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
5647:
5648: <p>Otherwise, run these steps:</p>
5649:
5650: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
5651: for elements with the same tag name as the token.</p></li>
5652:
5653: <li><p>If the <a href="#current-node">current node</a> is not an element with
5654: the same tag name as that of the token, then this is a
5655: <a href="#parse-error">parse error</a>.</p></li>
5656:
5657: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5658: until an element with the same tag name as the token has been
5659: popped from the stack.</p></li>
5660:
5661: </ol></dd>
5662:
1.1 mike 5663: <!-- as normal, but needs care as the elements have optional tags -->
1.422 mike 5664: <dt>An end tag whose tag name is one of: "dd", "dt"</dt>
1.1 mike 5665: <dd>
5666:
5667: <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>
5668: with the same tag name as that of the token, then this is a
5669: <a href="#parse-error">parse error</a>; ignore the token.</p>
5670:
5671: <p>Otherwise, run these steps:</p>
5672:
5673: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
5674: for elements with the same tag name as the token.</p></li>
5675:
5676: <li><p>If the <a href="#current-node">current node</a> is not an element with
5677: the same tag name as that of the token, then this is a
5678: <a href="#parse-error">parse error</a>.</p></li>
5679:
5680: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5681: until an element with the same tag name as the token has been
5682: popped from the stack.</p></li>
5683:
5684: </ol></dd>
5685:
5686: <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
5687: <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
5688: <dd>
5689:
5690: <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>
5691: whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
5692: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
5693:
5694: <p>Otherwise, run these steps:</p>
5695:
5696: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5697:
5698: <li><p>If the <a href="#current-node">current node</a> is not an element with
5699: the same tag name as that of the token, then this is a
5700: <a href="#parse-error">parse error</a>.</p></li>
5701:
5702: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5703: until an element whose tag name is one of "h1", "h2", "h3", "h4",
5704: "h5", or "h6" has been popped from the stack.</p></li>
5705:
5706: </ol></dd>
5707:
5708: <dt>An end tag whose tag name is "sarcasm"</dt>
5709: <dd>
5710: <p>Take a deep breath, then act as described in the "any other end
5711: tag" entry below.</p>
5712: </dd>
5713:
5714: <!-- ADOPTION AGENCY ELEMENTS
5715: Mozilla-only: bdo blink del ins sub sup q
5716: Safari-only: code dfn kbd nobr samp var wbr
5717: Both: a b big em font i s small strike strong tt u -->
5718:
5719: <dt>A start tag whose tag name is "a"</dt>
5720: <dd>
5721:
5722: <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
5723: contains an element whose tag name is "a" between the end of
5724: the list and the last marker on the list (or the start of the
5725: list if there is no marker on the list), then this is a
5726: <a href="#parse-error">parse error</a>; act as if an end tag with the tag
5727: name "a" had been seen, then remove that element from the
5728: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
5729: <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
5730: already remove it (it might not have if the element is not
5731: <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
5732: scope</a>).</p>
5733:
5734: <p class="example">In the non-conforming stream
5735: <code><a href="a">a<table><a href="b">b</table>x</code>,
5736: the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
5737: the second one, and the "x" character would be inside a link
5738: to "b", not to "a". This is despite the fact that the outer
5739: <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
5740: regular <code></a></code> end tag at the start of the table
5741: wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
5742:
5743: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5744: any.</p>
5745:
5746: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
5747: element to the <a href="#list-of-active-formatting-elements">list of active formatting
5748: elements</a>.</p>
5749:
5750: </dd>
5751:
5752: <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
5753: "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
5754: <dd>
5755:
5756: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5757: any.</p>
5758:
5759: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
5760: element to the <a href="#list-of-active-formatting-elements">list of active formatting
5761: elements</a>.</p>
5762:
5763: </dd>
5764:
5765: <dt>A start tag whose tag name is "nobr"</dt>
5766: <dd>
5767:
5768: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5769: any.</p>
5770:
5771: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5772: element in scope">has a <code>nobr</code> element in scope</a>,
5773: then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
5774: the tag name "nobr" had been seen, then once again
5775: <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
5776: any.</p>
5777:
5778: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
5779: element to the <a href="#list-of-active-formatting-elements">list of active formatting
5780: elements</a>.</p>
5781:
5782: </dd>
5783:
5784: <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
5785: "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
5786: "strike", "strong", "tt", "u"</dt>
5787: <dd>
5788:
5789: <p>Follow these steps:</p>
5790:
5791: <ol><li>
5792:
5793: <p>Let the <var title="">formatting element</var> be the
5794: last element in the <a href="#list-of-active-formatting-elements">list of active formatting
5795: elements</a> that:</p>
5796:
5797: <ul><li>is between the end of the list and the last scope
5798: marker in the list, if any, or the start of the list
5799: otherwise, and</li>
5800:
5801: <li>has the same tag name as the token.</li>
5802:
5803: </ul><p>If there is no such node, or, if that node is also in the
5804: <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
5805: <a href="#parse-error">parse error</a>; ignore the token, and abort these
5806: steps.</p>
5807:
5808: <p>Otherwise, if there is such a node, but that node is not
5809: in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
5810: <a href="#parse-error">parse error</a>; remove the element from the list,
5811: and abort these steps.</p>
5812:
5813: <p>Otherwise, there is a <var title="">formatting
5814: element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
5815: open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
5816: element in scope">in scope</a>. If the element is not the
5817: <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
5818: error</a>. In any case, proceed with the algorithm as
5819: written in the following steps.</p>
5820:
5821: </li>
5822:
5823: <li><p>Let the <var title="">furthest block</var> be the
5824: topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
5825: is lower in the stack than the <var title="">formatting
5826: element</var>, and is not an element in the
5827: <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
5828: categories. There might not be one.</p></li>
5829:
5830: <li><p>If there is no <var title="">furthest block</var>,
5831: then the UA must skip the subsequent steps and instead just
5832: pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
5833: elements</a>, from the <a href="#current-node">current node</a> up to and
5834: including the <var title="">formatting element</var>, and
5835: remove the <var title="">formatting element</var> from the
5836: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
5837:
5838: <li><p>Let the <var title="">common ancestor</var> be the element
5839: immediately above the <var title="">formatting element</var> in the
5840: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
5841:
5842: <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
5843: formatting elements</a> relative to the elements on either
5844: side of it in the list.</p></li>
5845:
5846: <li>
5847:
5848: <p>Let <var title="">node</var> and <var title="">last node</var> be the
5849: <var title="">furthest block</var>. Follow these steps:</p>
5850:
5851: <ol><li>Let <var title="">node</var> be the element immediately
5852: above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
1.436 mike 5853: elements</a>, or if <var title="">node</var> is no longer in
5854: the <a href="#stack-of-open-elements">stack of open elements</a> (e.g. because it got
5855: removed by the next step), the element that was immediately
5856: above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
5857: elements</a> before <var title="">node</var> was
5858: removed.</li>
1.1 mike 5859:
5860: <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
5861: active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
5862: elements</a> and then go back to step 1.</li>
5863:
5864: <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
5865: in the overall algorithm.</li>
5866:
5867: <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
5868: bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
5869: elements</a>.</li>
5870:
5871: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
5872: element <var title="">node</var> was created, replace the entry
5873: for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
5874: formatting elements</a> with an entry for the new element,
5875: replace the entry for <var title="">node</var> in the
5876: <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
5877: element, and let <var title="">node</var> be the new
5878: element.</li>
5879:
5880: <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
5881: parent node if any.</li>
5882:
5883: <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
5884:
5885: <li>Return to step 1 of this inner set of steps.</li>
5886:
5887: </ol></li>
5888:
5889: <li>
5890:
5891: <p>If the <var title="">common ancestor</var> node is a
5892: <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>,
5893: <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,
5894: <a href="#foster-parent">foster parent</a> whatever <var title="">last
5895: node</var> ended up being in the previous step, first removing
5896: it from its previous parent node if any.</p>
5897:
5898: <p>Otherwise, append whatever <var title="">last node</var>
5899: ended up being in the previous step to the <var title="">common
5900: ancestor</var> node, first removing it from its previous parent
5901: node if any.</p>
5902:
5903: </li>
5904:
5905: <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
5906: <var title="">formatting element</var> was created.</p></li>
5907:
5908: <li><p>Take all of the child nodes of the <var title="">furthest
5909: block</var> and append them to the element created in the last
5910: step.</p></li>
5911:
5912: <li><p>Append that new element to the <var title="">furthest
5913: block</var>.</p></li>
5914:
5915: <li><p>Remove the <var title="">formatting element</var> from the
5916: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
5917: new element into the <a href="#list-of-active-formatting-elements">list of active formatting
5918: elements</a> at the position of the aforementioned
5919: bookmark.</p></li>
5920:
5921: <li><p>Remove the <var title="">formatting element</var> from the
5922: <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
5923: into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
5924: the position of the <var title="">furthest block</var> in that
5925: stack.</p></li>
5926:
5927: <li><p>Jump back to step 1 in this series of steps.</p></li>
5928:
1.334 mike 5929: </ol><p class="note">Because of the way this algorithm causes elements
1.304 mike 5930: to change parents, it has been dubbed the "adoption agency
5931: algorithm" (in contrast with other possible algorithms for dealing
5932: with misnested content, which included the "incest algorithm", the
1.1 mike 5933: "secret affair algorithm", and the "Heisenberg algorithm").</p>
5934:
5935: </dd>
5936:
5937: <dt>A start tag whose tag name is "button"</dt>
5938: <dd>
5939:
5940: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5941: an element in scope">has a <code>button</code> element in
5942: scope</a>, then this is a <a href="#parse-error">parse error</a>;
5943: act as if an end tag with the tag name "button" had been seen,
5944: then reprocess the token.</p>
5945:
5946: <p>Otherwise:</p>
5947:
5948: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5949: any.</p>
5950:
5951: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5952:
5953: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5954: formatting elements</a>.</p>
5955:
5956: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5957:
5958: </dd>
5959:
5960: <dt>A start tag token whose tag name is one of: "applet",
5961: "marquee", "object"</dt>
5962: <dd>
5963:
5964: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5965: any.</p>
5966:
5967: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5968:
5969: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5970: formatting elements</a>.</p>
5971:
5972: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5973:
5974: </dd>
5975:
5976: <dt>An end tag token whose tag name is one of: "applet", "button",
5977: "marquee", "object"</dt>
5978: <dd>
5979:
5980: <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>
5981: with the same tag name as that of the token, then this is a
5982: <a href="#parse-error">parse error</a>; ignore the token.</p>
5983:
5984: <p>Otherwise, run these steps:</p>
5985:
5986: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5987:
5988: <li><p>If the <a href="#current-node">current node</a> is not an element with
5989: the same tag name as that of the token, then this is a
5990: <a href="#parse-error">parse error</a>.</p></li>
5991:
5992: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5993: until an element with the same tag name as the token has been
5994: popped from the stack.</p></li>
5995:
5996: <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
5997: last marker</a>.</li>
5998:
5999: </ol></dd>
6000:
6001: <dt>A start tag whose tag name is "table"</dt>
6002: <dd>
6003:
6004: <p>If the <code>Document</code> is <em>not</em> set to
6005: <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
6006: elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
6007: <code>p</code> element in scope</a>, then act as if an end tag
6008: with the tag name "p" had been seen.</p> <!-- i hate myself (this
6009: quirk was basically caused by acid2; if i'd realised we could
6010: change the specs when i wrote acid2, we could have avoided having
6011: any parsing-mode quirks) -Hixie -->
6012:
6013: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6014:
6015: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
6016:
6017: <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>
6018:
6019: </dd>
6020:
6021: <dt>A start tag whose tag name is one of: "area", "basefont",
1.589 mike 6022: "bgsound", "br", "embed", "img", "input", "keygen", "wbr"</dt>
1.1 mike 6023: <dd>
6024:
6025: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6026: any.</p>
6027:
6028: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
6029: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6030: elements</a>.</p>
6031:
6032: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6033: token's <i>self-closing flag</i></a>, if it is set.</p>
6034:
6035: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
1.589 mike 6036: shouldn't really do it for <area>, <basefont>, and <bgsound> -->
1.1 mike 6037:
6038: </dd>
6039:
6040: <dt>A start tag whose tag name is one of: "param", "source"</dt>
6041: <dd>
6042:
6043: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
6044: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6045: elements</a>.</p>
6046:
6047: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6048: token's <i>self-closing flag</i></a>, if it is set.</p>
6049:
6050: </dd>
6051:
6052: <dt>A start tag whose tag name is "hr"</dt>
6053: <dd>
6054:
6055: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
6056: an element in scope">has a <code>p</code> element in
6057: scope</a>, then act as if an end tag with the tag name
6058: "p" had been seen.</p>
6059:
6060: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
6061: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6062: elements</a>.</p>
6063:
6064: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6065: token's <i>self-closing flag</i></a>, if it is set.</p>
6066:
6067: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
6068:
6069: </dd>
6070:
6071: <dt>A start tag whose tag name is "image"</dt>
6072: <dd>
6073: <p><a href="#parse-error">Parse error</a>. Change the token's tag name
6074: to "img" and reprocess it. (Don't ask.)</p> <!-- As of
6075: 2005-12, studies showed that around 0.2% of pages used the
6076: <image> element. -->
6077: </dd>
6078:
6079: <dt id="isindex">A start tag whose tag name is "isindex"</dt>
6080: <dd>
6081:
6082: <p><a href="#parse-error">Parse error</a>.</p>
6083:
6084: <p>If the <a href="#form-element-pointer"><code title="">form</code> element
6085: pointer</a> is not null, then ignore the token.</p>
6086:
6087: <p>Otherwise:</p>
6088:
6089: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6090: token's <i>self-closing flag</i></a>, if it is set.</p> <!--
6091: purely to reduce the number of errors (we don't care if they
6092: included the /, they're not supposed to be including the tag at
6093: all! -->
6094:
6095: <p>Act as if a start tag token with the tag name "form" had been seen.</p>
6096:
6097: <p>If the token has an attribute called "action", set the
6098: <code title="attr-form-action">action</code> attribute on the
6099: resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
6100: "action" attribute of the token.</p>
6101:
6102: <p>Act as if a start tag token with the tag name "hr" had been
6103: seen.</p>
6104:
6105: <p>Act as if a start tag token with the tag name "label" had been
6106: seen.</p>
6107:
6108: <p>Act as if a stream of character tokens had been seen (see below
6109: for what they should say).</p>
6110:
6111: <p>Act as if a start tag token with the tag name "input" had been
6112: seen, with all the attributes from the "isindex" token except
6113: "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
6114: <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
6115:
6116: <p>Act as if a stream of character tokens had been seen (see
6117: below for what they should say).</p>
6118:
6119: <p>Act as if an end tag token with the tag name "label" had been
6120: seen.</p>
6121:
6122: <p>Act as if a start tag token with the tag name "hr" had been
6123: seen.</p>
6124:
6125: <p>Act as if an end tag token with the tag name "form" had been
6126: seen.</p>
6127:
6128: <p>If the token has an attribute with the name "prompt", then the
6129: first stream of characters must be the same string as given in
6130: that attribute, and the second stream of characters must be
6131: empty. Otherwise, the two streams of character tokens together
6132: should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
6133: equivalent of "This is a searchable index. Insert your search
6134: keywords here: (input field)" in the user's preferred
6135: language.</p>
6136:
6137: </dd>
6138:
6139: <dt>A start tag whose tag name is "textarea"</dt>
6140: <dd>
6141:
6142: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
6143: token.</p></li>
6144:
6145: <li><p>If the next token is a U+000A LINE FEED (LF) character
6146: token, then ignore that token and move on to the next
6147: one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
6148: ignored as an authoring convenience.)</p></li>
6149:
1.671 mike 6150: <li><p>Switch the tokenizer to the <a href="#rcdata-state">RCDATA
1.541 mike 6151: state</a>.</p></li>
1.1 mike 6152:
6153: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
6154: current <a href="#insertion-mode">insertion mode</a>.</p>
6155:
6156: </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
6157: ok".</p></li>
6158:
1.540 mike 6159: <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: text">text</a>".</p></li>
1.1 mike 6160:
6161: </ol></dd>
6162:
6163: <dt>A start tag whose tag name is "xmp"</dt>
6164: <dd>
6165:
1.233 mike 6166: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
6167: an element in scope">has a <code>p</code> element in
6168: scope</a>, then act as if an end tag with the tag name
6169: "p" had been seen.</p>
6170:
1.1 mike 6171: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6172: any.</p>
6173:
6174: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
6175:
1.91 mike 6176: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 6177:
6178: </dd>
6179:
6180: <dt>A start tag whose tag name is "iframe"</dt>
6181: <dd>
6182:
6183: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
6184:
1.91 mike 6185: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 6186:
6187: </dd>
6188:
6189: <dt>A start tag whose tag name is "noembed"</dt>
6190: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
6191: <dd>
6192:
1.91 mike 6193: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 6194:
6195: </dd>
6196:
6197: <dt>A start tag whose tag name is "select"</dt>
6198: <dd>
6199:
6200: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6201: any.</p>
6202:
6203: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6204:
6205: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
6206:
6207: <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>",
6208: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
6209: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
6210: row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
6211: cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
6212: "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
6213: table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
6214: to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
6215:
6216: </dd>
6217:
6218: <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
6219: <dd>
6220:
6221: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
6222: element in scope">has an <code>option</code> element in
6223: scope</a>, then act as if an end tag with the tag name "option"
6224: had been seen.</p>
6225:
6226: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6227: any.</p>
6228:
6229: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6230:
6231: </dd>
6232:
6233: <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
6234: <dd>
6235:
6236: <!-- the parsing rules for ruby really don't match IE much at all,
6237: but in practice the markup used is very simple and so strict
6238: compatibility with IE isn't required. For example, as defined
6239: here we get very, very different behaviour than IE for
6240: pathological cases like:
6241:
6242: <ruby><ol><li><p>a<rt>b
6243: <ruby>a<rt>b<p>c
6244:
6245: But in practice most ruby markup falls into these cases:
6246:
6247: <ruby>a<rt>b</ruby>
6248: <ruby>a<rp>b<rt>c<rp>d</ruby>
6249: <ruby>a<rt>b</rt></ruby>
6250: <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
6251:
6252: -->
6253:
6254: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
6255: element in scope">has a <code>ruby</code> element in scope</a>,
6256: then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
6257: node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
6258: <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
6259: node</a> up to the node immediately before the bottommost
6260: <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
6261: elements</a>.</p>
6262:
6263: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6264:
6265: </dd>
6266:
6267: <dt>An end tag whose tag name is "br"</dt>
6268: <dd>
6269: <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
6270: the tag name "br" had been seen. Ignore the end tag token.</p>
6271: </dd>
6272:
6273: <dt>A start tag whose tag name is "math"</dt>
6274: <dd>
6275:
6276: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6277: any.</p>
6278:
6279: <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
6280: fixes the case of MathML attributes that are not all
6281: lowercase.)</p>
6282:
6283: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
6284: fixes the use of namespaced attributes, in particular XLink.)</p>
6285:
6286: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
6287: <a href="#mathml-namespace">MathML namespace</a>.</p>
6288:
6289: <!-- If we ever change the frameset-ok flag to an insertion mode,
6290: the following change would be implied, except we'd have to do it
6291: even in the face of a self-closed tag:
6292: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
6293: -->
6294:
6295: <p>If the token has its <i>self-closing flag</i> set, pop the
6296: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6297: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
6298: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
6299:
6300: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
6301: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
6302: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
6303: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
6304: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
6305: foreign content">in foreign content</a>".</p>
6306:
6307: </dd>
6308:
6309: <dt>A start tag whose tag name is "svg"</dt>
6310: <dd>
6311:
6312: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6313: any.</p>
6314:
6315: <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
6316: the case of SVG attributes that are not all lowercase.)</p>
6317:
6318: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
6319: fixes the use of namespaced attributes, in particular XLink in
6320: SVG.)</p>
6321:
6322: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
6323: <a href="#svg-namespace">SVG namespace</a>.</p>
6324:
6325: <!-- If we ever change the frameset-ok flag to an insertion mode,
6326: the following change would be implied, except we'd have to do it
6327: even in the face of a self-closed tag:
6328: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
6329: -->
6330:
6331: <p>If the token has its <i>self-closing flag</i> set, pop the
6332: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6333: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
6334: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
6335:
6336: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
6337: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
6338: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
6339: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
6340: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
6341: foreign content">in foreign content</a>".</p>
6342:
6343: </dd>
6344:
6345: <dt>A start <!--or end--> tag whose tag name is one of: "caption",
6346: "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
6347: "thead", "tr"</dt>
6348: <!--<dt>An end tag whose tag name is one of: "area", "base",
6349: "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
6350: "img", "input", "isindex", "keygen", "link", "meta", "noembed",
1.589 mike 6351: "noframes", "param", "script", "select", "source", "style",
6352: "table", "textarea", "title", "wbr"</dt>-->
1.1 mike 6353: <!--<dt>An end tag whose tag name is "noscript", if the
6354: <span>scripting flag</span> is enabled</dt>-->
6355: <dd>
6356: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6357: <!-- end tags are commented out because since they can never end
6358: up on the stack anyway, the default end tag clause will
6359: automatically handle them. we don't want to have text in the spec
6360: that is just an optimisation, as that detracts from the spec
6361: itself -->
6362: </dd>
6363:
6364: <dt>Any other start tag</dt>
6365: <dd>
6366:
6367: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6368: any.</p>
6369:
6370: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6371:
6372: <p class="note">This element will be a <a href="#phrasing">phrasing</a>
6373: element.</p>
6374:
6375: </dd>
6376:
6377: <dt>Any other end tag</dt>
6378: <dd>
6379:
6380: <p>Run the following steps:</p>
6381:
6382: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
6383: node</a> (the bottommost node of the stack).</p></li>
6384:
6385: <li><p>If <var title="">node</var> has the same tag name as
6386: the end tag token, then:</p>
6387:
6388: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
6389:
6390: <li><p>If the tag name of the end tag token does not match
6391: the tag name of the <a href="#current-node">current node</a>, this is a
6392: <a href="#parse-error">parse error</a>.</p></li>
6393:
6394: <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
6395: to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
6396:
6397: </ol></li>
6398:
6399: <li><p>Otherwise, if <var title="">node</var> is in neither the
6400: <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
6401: category, then this is a <a href="#parse-error">parse error</a>; ignore the
6402: token, and abort these steps.</p></li>
6403:
6404: <li><p>Set <var title="">node</var> to the previous entry in the
6405: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
6406:
6407: <li><p>Return to step 2.</p></li>
6408:
6409: </ol></dd>
6410:
1.614 mike 6411: </dl><h5 id="parsing-main-incdata"><span class="secno">9.2.5.11 </span>The "<dfn title="insertion mode: text">text</dfn>" insertion mode</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 6412:
6413: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.540 mike 6414: mode: text">text</a>", tokens must be handled as follows:</p>
1.1 mike 6415:
6416: <dl class="switch"><dt>A character token</dt>
6417: <dd>
6418:
6419: <p><a href="#insert-a-character" title="insert a character">Insert the token's
6420: character</a> into the <a href="#current-node">current node</a>.</p>
6421:
6422: </dd>
6423:
6424: <dt>An end-of-file token</dt>
6425: <dd>
6426:
6427: <!-- can't be the fragment case -->
6428: <p><a href="#parse-error">Parse error</a>.</p>
6429:
6430: <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
1.484 mike 6431: element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-started">"already
6432: started"</a>.</p>
1.1 mike 6433:
6434: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6435: elements</a>.</p>
6436:
6437: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
6438: insertion mode</a> and reprocess the current token.</p>
6439:
6440: </dd>
6441:
6442: <dt>An end tag whose tag name is "script"</dt>
6443: <dd>
6444:
6445: <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
6446: (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
6447:
6448: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6449: elements</a>.</p>
6450:
6451: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
6452: insertion mode</a>.</p>
6453:
6454: <p>Let the <var title="">old insertion point</var> have the
6455: same value as the current <a href="#insertion-point">insertion point</a>. Let
6456: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
6457: input character</a>.</p>
6458:
6459: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
6460: one.</p>
6461:
6462: <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 6463: which might cause <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters
1.1 mike 6464: to be inserted into the tokenizer</a>, and might cause the
6465: tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
6466:
6467: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
6468: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
6469: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
6470:
6471: <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
6472: <a href="#insertion-point">insertion point</a> to its previous value. This value
6473: might be the "undefined" value.)</p>
6474:
6475: <p id="scriptTagParserResumes">At this stage, if there is a
1.484 mike 6476: <a href="semantics.html#pending-parsing-blocking-script">pending parsing-blocking script</a>, then:</p>
1.1 mike 6477:
6478: <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
6479:
6480: <dd>
6481:
6482: <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
6483: processing of any nested invocations of the tokenizer, yielding
6484: control back to the caller. (Tokenization will resume when the
6485: caller returns to the "outer" tree construction stage.)</p>
6486:
6487: <p class="note">The tree construction stage of this particular
6488: parser is <a href="#nestedParsing">being called reentrantly</a>,
1.159 mike 6489: 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 6490:
6491: </dd>
6492:
6493:
6494: <dt>Otherwise:</dt>
6495:
6496: <dd>
6497:
6498: <p>Follow these steps:</p>
6499:
1.484 mike 6500: <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-parsing-blocking-script">pending
6501: parsing-blocking script</a>. There is no longer a <a href="semantics.html#pending-parsing-blocking-script">pending
6502: parsing-blocking script</a>.</p></li>
6503:
6504: <li><p>Block the <a href="#tokenization" title="tokenization">tokenizer</a>
6505: for this instance of the <a href="#html-parser">HTML parser</a>, such that
6506: the <a href="browsers.html#event-loop">event loop</a> will not run <a href="browsers.html#concept-task" title="concept-task">tasks</a> that invoke the <a href="#tokenization" title="tokenization">tokenizer</a>.</p></li>
6507:
6508: <li><p><a href="browsers.html#spin-the-event-loop">Spin the event loop</a> until there is no <a href="semantics.html#a-style-sheet-blocking-scripts" title="a style sheet blocking scripts">style sheet blocking
6509: scripts</a> and <var title="">the script</var>'s
6510: <a href="semantics.html#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag is set.</p></li>
6511:
6512: <li><p>Unblock the <a href="#tokenization" title="tokenization">tokenizer</a>
6513: for this instance of the <a href="#html-parser">HTML parser</a>, such that
6514: <a href="browsers.html#concept-task" title="concept-task">tasks</a> that invoke the <a href="#tokenization" title="tokenization">tokenizer</a> can again be
6515: run.</p></li>
1.1 mike 6516:
6517: <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
6518: <a href="#next-input-character">next input character</a>.</p></li>
6519:
6520: <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
6521: by one (it should be zero before this step, so this sets it to
6522: one).</p></li>
6523:
1.484 mike 6524: <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute</a>
6525: <var title="">the script</var>.</p></li>
1.1 mike 6526:
6527: <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
6528: by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
6529: zero (which it always should be at this point), then set the
6530: <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
6531:
6532: </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
6533: again.</p></li>
6534:
1.484 mike 6535: <li><p>If there is once again a <a href="semantics.html#pending-parsing-blocking-script">pending parsing-blocking
1.1 mike 6536: script</a>, then repeat these steps from step 1.</p></li>
6537:
6538: </ol></dd>
6539:
6540: </dl></dd>
6541:
6542: <dt>Any other end tag</dt>
6543: <dd>
6544:
6545: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6546: elements</a>.</p>
6547:
6548: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
6549: insertion mode</a>.</p>
6550:
6551: </dd>
6552:
1.614 mike 6553: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 6554:
6555: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
6556: mode: in table">in table</a>", tokens must be handled as follows:</p>
6557:
6558: <dl class="switch"><dt>A character token</dt>
6559: <dd>
6560:
6561: <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
6562: be an empty list of tokens.</p>
6563:
6564: <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
6565: <a href="#insertion-mode">insertion mode</a>.</p>
6566:
6567: <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
6568: reprocess the token.</p>
6569:
6570: </dd>
6571:
6572: <dt>A comment token</dt>
6573: <dd>
6574: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6575: node</a> with the <code title="">data</code> attribute set to
6576: the data given in the comment token.</p>
6577: </dd>
6578:
6579: <dt>A DOCTYPE token</dt>
6580: <dd>
6581: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6582: </dd>
6583:
6584: <dt>A start tag whose tag name is "caption"</dt>
6585: <dd>
6586:
6587: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
6588: below.)</p>
6589:
6590: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
6591: formatting elements</a>.</p>
6592:
6593: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
6594: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
6595:
6596: </dd>
6597:
6598: <dt>A start tag whose tag name is "colgroup"</dt>
6599: <dd>
6600:
6601: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
6602: below.)</p>
6603:
6604: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
6605: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
6606: group</a>".</p>
6607:
6608: </dd>
6609:
6610: <dt>A start tag whose tag name is "col"</dt>
6611: <dd>
6612: <p>Act as if a start tag token with the tag name "colgroup"
6613: had been seen, then reprocess the current token.</p>
6614: </dd>
6615:
6616: <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
6617: <dd>
6618:
6619: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
6620: below.)</p>
6621:
6622: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
6623: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
6624: body</a>".</p>
6625:
6626: </dd>
6627:
6628: <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
6629: <dd>
6630: <p>Act as if a start tag token with the tag name "tbody" had
6631: been seen, then reprocess the current token.</p>
6632: </dd>
6633:
6634: <dt>A start tag whose tag name is "table"</dt>
6635: <dd>
6636:
6637: <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
6638: the tag name "table" had been seen, then, if that token wasn't
6639: ignored, reprocess the current token.</p>
6640:
6641: <p class="note">The fake end tag token here can only be
6642: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6643:
6644: </dd>
6645:
6646: <dt>An end tag whose tag name is "table"</dt>
6647: <dd>
6648:
6649: <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
6650: scope</a> with the same tag name as the token, this is a
6651: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6652: case</a>)</p>
6653:
6654: <p>Otherwise:</p>
6655:
6656: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
6657: element has been popped from the stack.</p>
6658:
6659: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
6660:
6661: </dd>
6662:
6663: <dt>An end tag whose tag name is one of: "body", "caption",
6664: "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
6665: "thead", "tr"</dt>
6666: <dd>
6667: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6668: </dd>
6669:
6670: <dt>A start tag whose tag name is one of: "style", "script"</dt>
6671: <dd>
6672:
6673: <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
6674: mode</a>.</p>
6675:
6676: </dd>
6677:
6678: <dt>A start tag whose tag name is "input"</dt>
6679: <dd>
6680:
6681: <p>If the token does not have an attribute with the name "type",
6682: or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
6683: case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
6684: else" entry below.</p>
6685:
6686: <p>Otherwise:</p>
6687:
6688: <p><a href="#parse-error">Parse error</a>.</p>
6689:
6690: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6691:
6692: <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
6693: open elements</a>.</p>
6694:
6695: </dd>
6696:
1.603 mike 6697: <dt>A start tag whose tag name is "form"</dt>
6698: <dd>
6699:
6700: <p><a href="#parse-error">Parse error</a>.</p>
6701:
6702: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6703:
1.637 mike 6704: <p>Pop that <code><a href="forms.html#the-form-element">form</a></code> element off the <a href="#stack-of-open-elements">stack of
1.603 mike 6705: open elements</a>.</p>
6706:
6707: </dd>
6708:
1.1 mike 6709: <dt>An end-of-file token</dt>
6710: <dd>
6711:
6712: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 6713: <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 6714: error</a>.</p>
6715:
6716: <p class="note">It can only be the <a href="#current-node">current node</a> in
6717: the <a href="#fragment-case">fragment case</a>.</p>
6718:
6719: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6720:
6721: </dd>
6722:
6723: <dt>Anything else</dt>
6724: <dd>
6725:
6726: <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
6727: rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
6728: body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
6729: <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
6730: <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
6731: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
6732: into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
6733:
6734: </dd>
6735:
6736: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
6737: back to a table context</dfn>, it means that the UA must, while
6738: 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 6739: element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1 mike 6740: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6741:
6742: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 6743: <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 6744: case</a>.</p>
6745:
6746:
6747:
1.614 mike 6748: <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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 6749:
6750: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
6751: mode: in table text">in table text</a>", tokens must be handled
6752: as follows:</p>
6753:
6754: <dl class="switch"><dt>A character token</dt>
6755: <dd>
6756:
6757: <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
6758: tokens</a></var> list.</p>
6759:
6760: </dd>
6761:
6762:
6763: <dt>Anything else</dt>
6764: <dd>
6765:
6766: <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
6767: tokens</a></var> list are character tokens that are not one of U+0009
6768: CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
6769: (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
6770: reprocess those character tokens using the rules given in the
6771: "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
6772: table">in table</a>" insertion mode.</p>
6773:
6774: <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
6775: characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
6776: tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
6777:
6778: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
6779: insertion mode</a> and reprocess the token.</p>
6780:
6781: </dd>
6782:
1.614 mike 6783: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 6784:
6785: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
6786: mode: in caption">in caption</a>", tokens must be handled as follows:</p>
6787:
6788: <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
6789: <dd>
6790:
6791: <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
6792: scope</a> with the same tag name as the token, this is a
6793: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6794: case</a>)</p>
6795:
6796: <p>Otherwise:</p>
6797:
6798: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
6799:
6800: <p>Now, if the <a href="#current-node">current node</a> is not a
6801: <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
6802: error</a>.</p>
6803:
6804: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
6805: element has been popped from the stack.</p>
6806:
6807: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
6808: the last marker</a>.</p>
6809:
6810: <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>
6811:
6812: </dd>
6813:
6814: <dt>A start tag whose tag name is one of: "caption", "col",
6815: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
6816: <dt>An end tag whose tag name is "table"</dt>
6817: <dd>
6818:
6819: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
6820: name "caption" had been seen, then, if that token wasn't
6821: ignored, reprocess the current token.</p>
6822:
6823: <p class="note">The fake end tag token here can only be
6824: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6825:
6826: </dd>
6827:
6828: <dt>An end tag whose tag name is one of: "body", "col",
6829: "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
6830: "tr"</dt>
6831: <dd>
6832: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6833: </dd>
6834:
6835: <dt>Anything else</dt>
6836: <dd>
6837: <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
6838: mode</a>.</p>
6839: </dd>
6840:
1.614 mike 6841: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 6842:
6843: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
6844: mode: in column group">in column group</a>", tokens must be handled as follows:</p>
6845:
6846: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6847: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6848: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6849: <dd>
6850: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6851: the <a href="#current-node">current node</a>.</p>
6852: </dd>
6853:
6854: <dt>A comment token</dt>
6855: <dd>
6856: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6857: node</a> with the <code title="">data</code> attribute set to
6858: the data given in the comment token.</p>
6859: </dd>
6860:
6861: <dt>A DOCTYPE token</dt>
6862: <dd>
6863: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6864: </dd>
6865:
6866: <dt>A start tag whose tag name is "html"</dt>
6867: <dd>
6868: <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
6869: mode</a>.</p>
6870: </dd>
6871:
6872: <dt>A start tag whose tag name is "col"</dt>
6873: <dd>
6874:
6875: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
6876: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6877: elements</a>.</p>
6878:
6879: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6880: token's <i>self-closing flag</i></a>, if it is set.</p>
6881:
6882: </dd>
6883:
6884: <dt>An end tag whose tag name is "colgroup"</dt>
6885: <dd>
6886:
6887: <p>If the <a href="#current-node">current node</a> is the root
1.159 mike 6888: <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 6889: error</a>; ignore the token. (<a href="#fragment-case">fragment
6890: case</a>)</p>
6891:
6892: <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
6893: 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
6894: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
6895: "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
6896:
6897: </dd>
6898:
6899: <dt>An end tag whose tag name is "col"</dt>
6900: <dd>
6901: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6902: </dd>
6903:
6904: <dt>An end-of-file token</dt>
6905: <dd>
6906:
1.159 mike 6907: <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 6908: element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
6909: case</a>)</p>
6910:
6911: <p>Otherwise, act as described in the "anything else" entry
6912: below.</p>
6913:
6914: </dd>
6915:
6916: <dt>Anything else</dt>
6917: <dd>
6918:
6919: <p>Act as if an end tag with the tag name "colgroup" had been
6920: seen, and then, if that token wasn't ignored, reprocess the
6921: current token.</p>
6922:
6923: <p class="note">The fake end tag token here can only be
6924: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6925:
6926: </dd>
6927:
1.614 mike 6928: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 6929:
6930: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
6931: mode: in table body">in table body</a>", tokens must be handled as follows:</p>
6932:
6933: <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
6934: <dd>
6935:
6936: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6937: context</a>. (See below.)</p>
6938:
6939: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
6940: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
6941: in row">in row</a>".</p>
6942:
6943: </dd>
6944:
6945: <dt>A start tag whose tag name is one of: "th", "td"</dt>
6946: <dd>
6947: <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
6948: the tag name "tr" had been seen, then reprocess the current
6949: token.</p>
6950: </dd>
6951:
6952: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
6953: "thead"</dt>
6954: <dd>
6955:
6956: <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
6957: scope</a> with the same tag name as the token, this is a
6958: <a href="#parse-error">parse error</a>. Ignore the token.</p>
6959:
6960: <p>Otherwise:</p>
6961:
6962: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6963: context</a>. (See below.)</p>
6964:
6965: <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
6966: open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
6967: to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
6968:
6969: </dd>
6970:
6971: <dt>A start tag whose tag name is one of: "caption", "col",
6972: "colgroup", "tbody", "tfoot", "thead"</dt>
6973: <dt>An end tag whose tag name is "table"</dt>
6974: <dd>
6975:
6976: <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
6977: <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
6978: element in table scope</a>, this is a <a href="#parse-error">parse
6979: error</a>. Ignore the token. (<a href="#fragment-case">fragment
6980: case</a>)</p>
6981:
6982: <p>Otherwise:</p>
6983:
6984: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6985: context</a>. (See below.)</p>
6986:
6987: <p>Act as if an end tag with the same tag name as the
6988: <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
6989: been seen, then reprocess the current token.</p>
6990:
6991: </dd>
6992:
6993: <dt>An end tag whose tag name is one of: "body", "caption",
6994: "col", "colgroup", "html", "td", "th", "tr"</dt>
6995: <dd>
6996: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6997: </dd>
6998:
6999: <dt>Anything else</dt>
7000: <dd>
7001: <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
7002: mode</a>.</p>
7003: </dd>
7004:
7005: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
7006: back to a table body context</dfn>, it means that the UA must,
7007: 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 7008: <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 7009: element, pop elements from the <a href="#stack-of-open-elements">stack of open
7010: elements</a>.</p>
7011:
7012: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 7013: <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 7014: case</a>.</p>
7015:
7016:
1.614 mike 7017: <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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7018:
7019: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
7020: mode: in row">in row</a>", tokens must be handled as follows:</p>
7021:
7022: <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
7023: <dd>
7024:
7025: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
7026: context</a>. (See below.)</p>
7027:
7028: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
7029: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
7030: in cell">in cell</a>".</p>
7031:
7032: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
7033: formatting elements</a>.</p>
7034:
7035: </dd>
7036:
7037: <dt>An end tag whose tag name is "tr"</dt>
7038: <dd>
7039:
7040: <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
7041: scope</a> with the same tag name as the token, this is a
7042: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
7043: case</a>)</p>
7044:
7045: <p>Otherwise:</p>
7046:
7047: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
7048: context</a>. (See below.)</p>
7049:
7050: <p>Pop the <a href="#current-node">current node</a> (which will be a
7051: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
7052: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
7053: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
7054: body</a>".</p>
7055:
7056: </dd>
7057:
7058: <dt>A start tag whose tag name is one of: "caption", "col",
7059: "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
7060: <dt>An end tag whose tag name is "table"</dt>
7061: <dd>
7062:
7063: <p>Act as if an end tag with the tag name "tr" had been seen,
7064: then, if that token wasn't ignored, reprocess the current
7065: token.</p>
7066:
7067: <p class="note">The fake end tag token here can only be
7068: ignored in the <a href="#fragment-case">fragment case</a>.</p>
7069:
7070: </dd>
7071:
7072: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
7073: "thead"</dt>
7074: <dd>
7075:
7076: <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
7077: scope</a> with the same tag name as the token, this is a
7078: <a href="#parse-error">parse error</a>. Ignore the token.</p>
7079:
7080: <p>Otherwise, act as if an end tag with the tag name "tr" had
7081: been seen, then reprocess the current token.</p>
7082:
7083: </dd>
7084:
7085: <dt>An end tag whose tag name is one of: "body", "caption",
7086: "col", "colgroup", "html", "td", "th"</dt>
7087: <dd>
7088: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7089: </dd>
7090:
7091: <dt>Anything else</dt>
7092: <dd>
7093: <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
7094: mode</a>.</p>
7095: </dd>
7096:
7097: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
7098: back to a table row context</dfn>, it means that the UA must,
7099: 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 7100: element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1 mike 7101: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
7102:
7103: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 7104: <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 7105: case</a>.</p>
7106:
7107:
1.614 mike 7108: <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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7109:
7110: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
7111: mode: in cell">in cell</a>", tokens must be handled as follows:</p>
7112:
7113: <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
7114: <dd>
7115:
7116: <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
7117: scope</a> with the same tag name as that of the token, then
7118: this is a <a href="#parse-error">parse error</a> and the token must be
7119: ignored.</p>
7120:
7121: <p>Otherwise:</p>
7122:
7123: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
7124:
7125: <p>Now, if the <a href="#current-node">current node</a> is not an element
7126: with the same tag name as the token, then this is a
7127: <a href="#parse-error">parse error</a>.</p>
7128:
7129: <p>Pop elements from this stack until an element with the same
7130: tag name as the token has been popped from the stack.</p>
7131:
7132: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
7133: the last marker</a>.</p>
7134:
7135: <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
7136: <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
7137: this point.)</p>
7138:
7139: </dd>
7140:
7141: <dt>A start tag whose tag name is one of: "caption", "col",
7142: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
7143: <dd>
7144:
7145: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
7146: <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
7147: a <code>td</code> or <code>th</code> element in table
7148: scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
7149: the token. (<a href="#fragment-case">fragment case</a>)</p>
7150:
7151: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
7152: reprocess the current token.</p>
7153:
7154: </dd>
7155:
7156: <dt>An end tag whose tag name is one of: "body", "caption",
7157: "col", "colgroup", "html"</dt>
7158: <dd>
7159: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7160: </dd>
7161:
7162: <dt>An end tag whose tag name is one of: "table", "tbody",
7163: "tfoot", "thead", "tr"</dt>
7164: <dd>
7165:
7166: <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
7167: scope</a> with the same tag name as that of the token
7168: (which can only happen for "tbody", "tfoot" and "thead", or,
7169: in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
7170: error</a> and the token must be ignored.</p>
7171:
7172: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
7173: reprocess the current token.</p>
7174:
7175: </dd>
7176:
7177: <dt>Anything else</dt>
7178: <dd>
7179: <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
7180: mode</a>.</p>
7181: </dd>
7182:
7183: </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
7184: mean to run the following algorithm:</p>
7185:
7186: <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>
7187: element in table scope</a>, then act as if an end tag token
7188: with the tag name "td" had been seen.</p></li>
7189:
7190: <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
7191: <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
7192: <code>th</code> element in table scope</a>; act as if an end
7193: tag token with the tag name "th" had been seen.</p></li>
7194:
7195: </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
7196: 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
7197: the same time, nor can it have neither when the <a href="#insertion-mode">insertion
7198: mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
7199: cell</a>".</p>
7200:
7201:
1.614 mike 7202: <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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7203:
7204: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
7205: mode: in select">in select</a>", tokens must be handled as follows:</p>
7206:
7207: <dl class="switch"><dt>A character token</dt>
7208: <dd>
7209: <p><a href="#insert-a-character" title="insert a character">Insert the token's
7210: character</a> into the <a href="#current-node">current node</a>.</p>
7211: </dd>
7212:
7213: <dt>A comment token</dt>
7214: <dd>
7215: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
7216: node</a> with the <code title="">data</code> attribute set to
7217: the data given in the comment token.</p>
7218: </dd>
7219:
7220: <dt>A DOCTYPE token</dt>
7221: <dd>
7222: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7223: </dd>
7224:
7225: <dt>A start tag whose tag name is "html"</dt>
7226: <dd>
7227: <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
7228: mode</a>.</p>
7229: </dd>
7230:
7231: <dt>A start tag whose tag name is "option"</dt>
7232: <dd>
7233:
7234: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
7235: element, act as if an end tag with the tag name "option" had
7236: been seen.</p>
7237:
7238: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
7239:
7240: </dd>
7241:
7242: <dt>A start tag whose tag name is "optgroup"</dt>
7243: <dd>
7244:
7245: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
7246: element, act as if an end tag with the tag name "option" had
7247: been seen.</p>
7248:
7249: <p>If the <a href="#current-node">current node</a> is an
7250: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
7251: tag name "optgroup" had been seen.</p>
7252:
7253: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
7254:
7255: </dd>
7256:
7257: <dt>An end tag whose tag name is "optgroup"</dt>
7258: <dd>
7259:
7260: <p>First, if the <a href="#current-node">current node</a> is an
7261: <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
7262: it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
7263: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
7264: the tag name "option" had been seen.</p>
7265:
7266: <p>If the <a href="#current-node">current node</a> is an
7267: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
7268: <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
7269: <a href="#parse-error">parse error</a>; ignore the token.</p>
7270:
7271: </dd>
7272:
7273: <dt>An end tag whose tag name is "option"</dt>
7274: <dd>
7275:
7276: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
7277: element, then pop that node from the <a href="#stack-of-open-elements">stack of open
7278: elements</a>. Otherwise, this is a <a href="#parse-error">parse
7279: error</a>; ignore the token.</p>
7280:
7281: </dd>
7282:
7283: <dt>An end tag whose tag name is "select"</dt>
7284: <dd>
7285:
7286: <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
7287: scope</a> with the same tag name as the token, this is a
7288: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
7289: case</a>)</p>
7290:
7291: <p>Otherwise:</p>
7292:
7293: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
7294: until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
7295: stack.</p>
7296:
7297: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
7298:
7299: </dd>
7300:
7301: <dt>A start tag whose tag name is "select"</dt>
7302: <dd>
7303:
7304: <p><a href="#parse-error">Parse error</a>. Act as if the token had been
7305: an end tag with the tag name "select" instead.</p>
7306:
7307: </dd>
7308:
7309: <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
7310: <dd>
1.73 mike 7311:
7312: <p><a href="#parse-error">Parse error</a>.</p>
7313:
1.124 mike 7314: <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>
7315: element in table scope</a>, ignore the token. (<a href="#fragment-case">fragment
7316: case</a>)</p>
1.73 mike 7317:
7318: <p>Otherwise, act as if an end tag with the tag name "select" had
7319: been seen, and reprocess the token.</p>
7320:
1.1 mike 7321: </dd>
7322:
7323: <dt>A start tag token whose tag name is "script"</dt>
7324: <dd>
7325: <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
7326: mode</a>.</p>
7327: </dd>
7328:
7329: <dt>An end-of-file token</dt>
7330: <dd>
7331:
7332: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 7333: <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 7334: error</a>.</p>
7335:
7336: <p class="note">It can only be the <a href="#current-node">current node</a> in
7337: the <a href="#fragment-case">fragment case</a>.</p>
7338:
7339: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7340:
7341: </dd>
7342:
7343: <dt>Anything else</dt>
7344: <dd>
7345: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7346: </dd>
7347:
1.614 mike 7348: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7349:
7350: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
7351: mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
7352:
7353: <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
7354: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
7355: <dd>
7356: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
7357: name "select" had been seen, and reprocess the token.</p>
7358: </dd>
7359:
7360: <dt>An end tag whose tag name is one of: "caption", "table",
7361: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
7362: <dd>
7363:
7364: <p><a href="#parse-error">Parse error</a>.</p>
7365:
7366: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
7367: element in table scope</a> with the same tag name as that
7368: of the token, then act as if an end tag with the tag name
7369: "select" had been seen, and reprocess the token. Otherwise,
7370: ignore the token.</p>
7371:
7372: </dd>
7373:
7374: <dt>Anything else</dt>
7375: <dd>
7376: <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
7377: mode</a>.</p>
7378: </dd>
7379:
1.614 mike 7380: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7381:
7382: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
7383: mode: in foreign content">in foreign content</a>", tokens must be
7384: handled as follows:</p>
7385:
7386: <dl class="switch"><dt>A character token</dt>
7387: <dd>
7388:
7389: <p><a href="#insert-a-character" title="insert a character">Insert the token's
7390: character</a> into the <a href="#current-node">current node</a>.</p>
7391:
7392: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
7393: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
7394: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
7395: flag</a> to "not ok".</p>
7396:
7397: </dd>
7398:
7399: <dt>A comment token</dt>
7400: <dd>
7401: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
7402: node</a> with the <code title="">data</code> attribute set to
7403: the data given in the comment token.</p>
7404: </dd>
7405:
7406: <dt>A DOCTYPE token</dt>
7407: <dd>
7408: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7409: </dd>
7410:
7411: <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>
7412: <dd>
7413:
7414: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
7415: elements</a>.</p>
7416:
7417: <p>Let the <var title="">old insertion point</var> have the
7418: same value as the current <a href="#insertion-point">insertion point</a>. Let
7419: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
7420: input character</a>.</p>
7421:
7422: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
7423: one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
7424:
7425: <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
7426: the <code title="">script</code> element</a> according to the SVG
1.187 mike 7427: rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
1.1 mike 7428:
1.159 mike 7429: <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 7430: tokenizer</a>, the parser will not be executed reentrantly,
7431: since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
7432:
7433: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
7434: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
7435: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
7436:
7437: <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
7438: <a href="#insertion-point">insertion point</a> to its previous value. This value
7439: might be the "undefined" value.)</p>
7440:
7441: </dd>
7442:
7443: <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>
7444: <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>
7445: <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>
7446: <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>
7447: <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>
7448: <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>
7449: <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>
7450: <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>
7451: <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>
7452: <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>
7453: <dt>An end tag</dt>
7454: <dd>
7455:
7456: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
7457: <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
7458:
7459: <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
7460: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
1.336 mike 7461: content</a>", but there is no element <a href="#has-an-element-in-scope" title="has an
7462: element in scope">in scope</a> that has a namespace other than
7463: the <a href="#html-namespace-0">HTML namespace</a>, switch the <a href="#insertion-mode">insertion
1.1 mike 7464: mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
7465:
7466: </dd>
7467:
7468: <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
7469: "blockquote", "body"<!--by inspection-->, "br", "center", "code",
1.422 mike 7470: "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
7471: uniformly throughout the parser -->, "em", "embed", "h1", "h2",
7472: "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
1.1 mike 7473: completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
7474: "li", "listing"<!-- so that pre and listing can be handled
7475: uniformly throughout the parser -->, "menu", "meta", "nobr",
7476: "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
7477: the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
7478: "span", "strong", "strike"<!-- so that s and strike can be handled
7479: uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
1.305 mike 7480: "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt> <!-- this
7481: list was determined empirically by studying over 6,000,000,000
1.422 mike 7482: pages that were specifically not XML pages -->
7483: <dt>A start tag whose tag name is "font", if the token has any
7484: attributes named "color", "face", or "size"</dt> <!-- the
7485: attributes here are required so that SVG <font> will go through as
7486: SVG but legacy <font>s won't -->
7487: <dt>An end-of-file token</dt> <dd>
1.1 mike 7488:
7489: <p><a href="#parse-error">Parse error</a>.</p>
7490:
7491: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
7492: the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
7493: namespace</a>.</p>
7494:
7495: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
7496: insertion mode</a>, and reprocess the token.</p>
7497:
7498: </dd>
7499:
7500: <dt>Any other start tag</dt>
7501: <dd>
7502:
7503: <p>If the <a href="#current-node">current node</a> is an element in the
7504: <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
7505: attributes</a> for the token. (This fixes the case of MathML
7506: attributes that are not all lowercase.)</p>
7507:
7508: <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
7509: namespace</a>, and the token's tag name is one of the ones in
7510: the first column of the following table, change the tag name to
7511: the name given in the corresponding cell in the second
7512: column. (This fixes the case of SVG elements that are not all
7513: lowercase.)</p>
7514:
7515: <table><thead><tr><th> Tag name </th><th> Element name
7516: </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
7517: </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
7518: </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
7519: </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
7520: </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
7521: </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
7522: </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
7523: </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
7524: </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
7525: </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
7526: </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
7527: </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
7528: </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
7529: </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
7530: </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
7531: </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
7532: </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
7533: </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
7534: </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
7535: </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
7536: </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
7537: </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
7538: </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
7539: </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
7540: </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
7541: </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
7542: </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
7543: </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
7544: </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
7545: </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
7546: </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
7547: </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
7548: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
7549: </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
7550: </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
7551: <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
7552: </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
7553: </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
7554: namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
7555: token. (This fixes the case of SVG attributes that are not all
7556: lowercase.)</p>
7557:
7558: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
7559: fixes the use of namespaced attributes, in particular XLink in
7560: SVG.)</p>
7561:
7562: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
7563: same namespace as the <a href="#current-node">current node</a>.</p>
7564:
7565: <p>If the token has its <i>self-closing flag</i> set, pop the
7566: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
7567: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
7568: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
7569:
7570: </dd>
7571:
1.614 mike 7572: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7573:
7574: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
7575: mode: after body">after body</a>", tokens must be handled as follows:</p>
7576:
7577: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
7578: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7579: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7580: <dd>
7581: <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
7582: mode</a>.</p>
7583: </dd>
7584:
7585: <dt>A comment token</dt>
7586: <dd>
7587: <p>Append a <code>Comment</code> node to the first element in
1.159 mike 7588: 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 7589: element), with the <code title="">data</code> attribute set to
7590: the data given in the comment token.</p>
7591: </dd>
7592:
7593: <dt>A DOCTYPE token</dt>
7594: <dd>
7595: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7596: </dd>
7597:
7598: <dt>A start tag whose tag name is "html"</dt>
7599: <dd>
7600: <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
7601: mode</a>.</p>
7602: </dd>
7603:
7604: <dt>An end tag whose tag name is "html"</dt>
7605: <dd>
7606:
7607: <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
7608: fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
7609: error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
7610:
7611: <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
7612: body</a>".</p>
7613:
7614: </dd>
7615:
7616: <dt>An end-of-file token</dt>
7617: <dd>
7618: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7619: </dd>
7620:
7621: <dt>Anything else</dt>
7622: <dd>
7623:
7624: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
7625: mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
7626: body</a>" and reprocess the token.</p>
7627:
7628: </dd>
7629:
1.614 mike 7630: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7631:
7632: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
7633: mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
7634:
7635: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
7636: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7637: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7638: <dd>
7639: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
7640: the <a href="#current-node">current node</a>.</p>
7641: </dd>
7642:
7643: <dt>A comment token</dt>
7644: <dd>
7645: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
7646: node</a> with the <code title="">data</code> attribute set to
7647: the data given in the comment token.</p>
7648: </dd>
7649:
7650: <dt>A DOCTYPE token</dt>
7651: <dd>
7652: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7653: </dd>
7654:
7655: <dt>A start tag whose tag name is "html"</dt>
7656: <dd>
7657: <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
7658: mode</a>.</p>
7659: </dd>
7660:
7661: <dt>A start tag whose tag name is "frameset"</dt>
7662: <dd>
7663: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
7664: </dd>
7665:
7666: <dt>An end tag whose tag name is "frameset"</dt>
7667: <dd>
7668:
7669: <p>If the <a href="#current-node">current node</a> is the root
1.159 mike 7670: <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 7671: error</a>; ignore the token. (<a href="#fragment-case">fragment
7672: case</a>)</p>
7673:
7674: <p>Otherwise, pop the <a href="#current-node">current node</a> from the
7675: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
7676:
7677: <p>If the parser was <em>not</em> originally created as part
7678: of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
7679: (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5 mike 7680: node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1 mike 7681: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
7682: frameset</a>".</p>
7683:
7684: </dd>
7685:
7686: <dt>A start tag whose tag name is "frame"</dt>
7687: <dd>
7688:
7689: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
7690: Immediately pop the <a href="#current-node">current node</a> off the
7691: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
7692:
7693: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
7694: token's <i>self-closing flag</i></a>, if it is set.</p>
7695:
7696: </dd>
7697:
7698: <dt>A start tag whose tag name is "noframes"</dt>
7699: <dd>
7700: <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
7701: mode</a>.</p>
7702: </dd>
7703:
7704: <dt>An end-of-file token</dt>
7705: <dd>
7706:
7707: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 7708: <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 7709: error</a>.</p>
7710:
7711: <p class="note">It can only be the <a href="#current-node">current node</a> in
7712: the <a href="#fragment-case">fragment case</a>.</p>
7713:
7714: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7715:
7716: </dd>
7717:
7718: <dt>Anything else</dt>
7719: <dd>
7720: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7721: </dd>
7722:
1.614 mike 7723: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7724:
7725: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
7726: mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
7727:
7728: <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
7729: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
7730: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7731: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7732: <dd>
7733: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
7734: the <a href="#current-node">current node</a>.</p>
7735: </dd>
7736:
7737: <dt>A comment token</dt>
7738: <dd>
7739: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
7740: node</a> with the <code title="">data</code> attribute set to
7741: the data given in the comment token.</p>
7742: </dd>
7743:
7744: <dt>A DOCTYPE token</dt>
7745: <dd>
7746: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7747: </dd>
7748:
7749: <dt>A start tag whose tag name is "html"</dt>
7750: <dd>
7751: <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
7752: mode</a>.</p>
7753: </dd>
7754:
7755: <dt>An end tag whose tag name is "html"</dt>
7756: <dd>
7757: <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
7758: frameset</a>".</p>
7759: </dd>
7760:
7761: <dt>A start tag whose tag name is "noframes"</dt>
7762: <dd>
7763: <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
7764: mode</a>.</p>
7765: </dd>
7766:
7767: <dt>An end-of-file token</dt>
7768: <dd>
7769: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7770: </dd>
7771:
7772: <dt>Anything else</dt>
7773: <dd>
7774: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7775: </dd>
7776:
1.614 mike 7777: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7778:
7779: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
7780: mode: after after body">after after body</a>", tokens must be handled as follows:</p>
7781:
7782: <dl class="switch"><dt>A comment token</dt>
7783: <dd>
7784: <p>Append a <code>Comment</code> node to the <code>Document</code>
7785: object with the <code title="">data</code> attribute set to the
7786: data given in the comment token.</p>
7787: </dd>
7788:
7789: <dt>A DOCTYPE token</dt>
7790: <dt>A character token that is one of U+0009 CHARACTER
7791: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7792: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7793: <dt>A start tag whose tag name is "html"</dt>
7794: <dd>
7795: <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
7796: mode</a>.</p>
7797: </dd>
7798:
7799: <dt>An end-of-file token</dt>
7800: <dd>
7801: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7802: </dd>
7803:
7804: <dt>Anything else</dt>
7805: <dd>
7806: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
7807: to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
7808: reprocess the token.</p>
7809: </dd>
7810:
1.614 mike 7811: </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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7812:
7813: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
7814: mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
7815:
7816: <dl class="switch"><dt>A comment token</dt>
7817: <dd>
7818: <p>Append a <code>Comment</code> node to the <code>Document</code>
7819: object with the <code title="">data</code> attribute set to the
7820: data given in the comment token.</p>
7821: </dd>
7822:
7823: <dt>A DOCTYPE token</dt>
7824: <dt>A character token that is one of U+0009 CHARACTER
7825: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7826: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7827: <dt>A start tag whose tag name is "html"</dt>
7828: <dd>
7829: <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
7830: mode</a>.</p>
7831: </dd>
7832:
7833: <dt>An end-of-file token</dt>
7834: <dd>
7835: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7836: </dd>
7837:
7838: <dt>A start tag whose tag name is "noframes"</dt>
7839: <dd>
7840: <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
7841: mode</a>.</p>
7842: </dd>
7843:
7844: <dt>Anything else</dt>
7845: <dd>
7846: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7847: </dd>
7848:
1.266 mike 7849: </dl></div><div class="impl">
7850:
1.614 mike 7851: <h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7852:
7853: <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
1.484 mike 7854: the document, the user agent must run the following steps:</p>
1.1 mike 7855:
1.484 mike 7856: <ol><!-- this happens as part of one of the tasks that runs the parser --><li><p>Set the <a href="dom.html#current-document-readiness">current document readiness</a> to
7857: "interactive" <!-- this also synchronously fires an event --> and
7858: the <a href="#insertion-point">insertion point</a> to undefined.</p></li>
7859:
7860: <li><p>If the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the
7861: document has finished parsing</a> is not empty, run these
7862: substeps:</p>
7863:
7864: <ol><li><p><a href="browsers.html#spin-the-event-loop">Spin the event loop</a> until the first
7865: <code><a href="semantics.html#script">script</a></code> in the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will
7866: execute when the document has finished parsing</a> has its
7867: <a href="semantics.html#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag set <em>and</em> there
7868: is no <a href="semantics.html#a-style-sheet-blocking-scripts" title="a style sheet blocking scripts">style sheet
7869: blocking scripts</a>.</p></li>
7870:
7871: <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute</a> the
7872: first <code><a href="semantics.html#script">script</a></code> in the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will
7873: execute when the document has finished parsing</a>.</p></li>
7874:
7875: <li><p>Remove the first <code><a href="semantics.html#script">script</a></code> element from the
7876: <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the document has
7877: finished parsing</a> (i.e. shift out the first entry in the
7878: list).</p></li>
7879:
7880: <li><p>If the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the
7881: document has finished parsing</a> is still not empty, repeat
7882: these substeps again from substep 1.</p>
7883:
7884: </li></ol></li>
7885:
1.671 mike 7886: <li><p><a href="browsers.html#spin-the-event-loop">Spin the event loop</a> until the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of
1.484 mike 7887: scripts that will execute as soon as possible</a> is
7888: empty.</p></li>
7889:
7890: <li><p><a href="browsers.html#queue-a-task">Queue a task</a> to <a href="browsers.html#fire-a-simple-event">fire a simple
7891: event</a> named <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
7892: <code>Document</code>.</p></li>
7893:
7894: <li><p><a href="browsers.html#spin-the-event-loop">Spin the event loop</a> until there is nothing that
7895: <dfn id="delay-the-load-event" title="delay the load event">delays the load event</dfn> in
7896: the <code>Document</code>.</p></li>
7897:
7898: <li><p><a href="browsers.html#queue-a-task">Queue a task</a> to set the <a href="dom.html#current-document-readiness">current document
7899: readiness</a> to "complete". <!-- this also fires an event
7900: synchronously during the task --></p></li>
1.1 mike 7901:
1.484 mike 7902: <li><p>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
1.1 mike 7903: context</a>, then <a href="browsers.html#queue-a-task">queue a task</a> to <a href="browsers.html#fire-a-simple-event">fire a
1.460 mike 7904: simple event</a> named <code title="event-load">load</code> at
1.1 mike 7905: the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
7906: its <code title="dom-event-target">target</code> set to the
7907: <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
1.484 mike 7908: <code><a href="browsers.html#window">Window</a></code> object).</p></li>
1.1 mike 7909:
1.569 mike 7910: <li><p>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
7911: 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
7912: simple event</a> named <code title="event-pageshow">pageshow</code> at the
7913: <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object.</p></li>
7914:
1.484 mike 7915: <li><p>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
1.651 mike 7916: 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 at the
1.1 mike 7917: <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
7918: <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
7919: current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
1.484 mike 7920: must bubble but not be cancelable and has no default
7921: action.</p></li>
1.1 mike 7922:
1.484 mike 7923: </ol><p>The <a href="browsers.html#task-source">task source</a> for the <a href="browsers.html#concept-task" title="concept-task">tasks</a> mentioned in this section is the
7924: <a href="browsers.html#dom-manipulation-task-source">DOM manipulation task source</a>.</p>
1.1 mike 7925:
1.266 mike 7926: </div><div class="impl">
1.1 mike 7927:
1.614 mike 7928: <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7929:
7930: <p>When an application uses an <a href="#html-parser">HTML parser</a> in
7931: conjunction with an XML pipeline, it is possible that the
7932: constructed DOM is not compatible with the XML tool chain in certain
7933: subtle ways. For example, an XML toolchain might not be able to
7934: represent attributes with the name <code title="">xmlns</code>,
7935: since they conflict with the Namespaces in XML syntax. There is also
7936: some data that the <a href="#html-parser">HTML parser</a> generates that isn't
7937: included in the DOM itself. This section specifies some rules for
7938: handling these issues.</p>
7939:
7940: <p>If the XML API being used doesn't support DOCTYPEs, the tool may
7941: drop DOCTYPEs altogether.</p>
7942:
7943: <p>If the XML API doesn't support attributes in no namespace that
7944: are named "<code title="">xmlns</code>", attributes whose names
7945: start with "<code title="">xmlns:</code>", or attributes in the
7946: <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
7947: attributes.</p>
7948:
7949: <p>The tool may annotate the output with any namespace declarations
7950: required for proper operation.</p>
7951:
7952: <p>If the XML API being used restricts the allowable characters in
7953: the local names of elements and attributes, then the tool may map
7954: all element and attribute local names that the API wouldn't support
7955: to a set of names that <em>are</em> allowed, by replacing any
7956: character that isn't supported with the uppercase letter U and the
7957: six digits of the character's Unicode code point when expressed in
7958: hexadecimal, using digits 0-9 and capital letters A-F as the
7959: symbols, in increasing numeric order.</p>
7960:
7961: <p class="example">For example, the element name <code title="">foo<bar</code>, which can be output by the <a href="#html-parser">HTML
7962: parser</a>, though it is neither a legal HTML element name nor a
7963: well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
7964: element name (though it's still not legal in HTML by any means).</p>
7965:
7966: <p class="example">As another example, consider the attribute
7967: <code>xlink:href</code>. Used on a MathML element, it becomes, after
7968: being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
7969: attribute with a prefix "<code title="">xlink</code>" and a local
7970: name "<code title="">href</code>". However, used on an HTML element,
7971: it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
7972: might not be accepted by an XML API. It could thus get converted,
7973: becoming "<code title="">xlinkU00003Ahref</code>".</p>
7974:
7975: <p class="note">The resulting names from this conversion
7976: conveniently can't clash with any attribute generated by the
7977: <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
7978: those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
7979: algorithm's table.</p>
7980:
7981: <p>If the XML API restricts comments from having two consecutive
7982: U+002D HYPHEN-MINUS characters (--), the tool may insert a single
7983: U+0020 SPACE character between any such offending characters.</p>
7984:
7985: <p>If the XML API restricts comments from ending in a
7986: U+002D HYPHEN-MINUS character (-), the tool may insert a single
7987: U+0020 SPACE character at the end of such comments.</p>
7988:
7989: <p>If the XML API restricts allowed characters in character data,
1.439 mike 7990: attribute values, or comments, the tool may replace any U+000C FORM
7991: FEED (FF) character with a U+0020 SPACE character, and any other
7992: literal non-XML character with a U+FFFD REPLACEMENT CHARACTER.</p>
1.1 mike 7993:
7994: <p>If the tool has no way to convey out-of-band information, then
7995: the tool may drop the following information:</p>
7996:
7997: <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
7998: <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>
7999:
8000: <li>The association between form controls and forms that aren't
8001: their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
8002: <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
8003:
8004: </ul><p class="note">The mutations allowed by this section apply
8005: <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
8006: applied. For example, a <code title=""><a::></code> start tag
8007: will be closed by a <code title=""></a::></code> end tag, and
8008: never by a <code title=""></aU00003AU00003A></code> end tag, even
8009: if the user agent is using the rules above to then generate an
8010: actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
8011:
1.266 mike 8012: </div><div class="impl">
1.1 mike 8013:
1.614 mike 8014: <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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 8015:
8016: <p><i>This section is non-normative.</i></p>
8017:
8018: <p>This section examines some erroneous markup and discusses how
8019: the <a href="#html-parser">HTML parser</a> handles these cases.</p>
8020:
8021:
8022: <h5 id="misnested-tags:-b-i-b-i"><span class="secno">9.2.8.1 </span>Misnested tags: <b><i></b></i></h5>
8023:
8024: <p><i>This section is non-normative.</i></p>
8025:
8026: <p>The most-often discussed example of erroneous markup is as
8027: follows:</p>
8028:
8029: <pre><p>1<b>2<i>3</b>4</i>5</p></pre>
8030:
8031: <p>The parsing of this markup is straightforward up to the "3". At
8032: this point, the DOM looks like this:</p>
8033:
1.159 mike 8034: <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
8035: 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 8036: <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
8037: formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
8038: <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>
8039:
8040: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
8041: invoked. This is a simple case, in that the <var title="">formatting
8042: element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
8043: <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
1.159 mike 8044: elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element-0">html</a></code>,
8045: <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 8046: active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
8047: DOM tree is unmodified at this point.</p>
8048:
8049: <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
8050: the active formatting elements</a>, in this case just the
8051: <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
8052: for the "4" text node. After the end tag token for the "i" is also
8053: received, and the "5" text node is inserted, the DOM looks as
8054: follows:</p>
8055:
1.159 mike 8056: <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 8057:
8058: <p><i>This section is non-normative.</i></p>
8059:
8060: <p>A case similar to the previous one is the following:</p>
8061:
8062: <pre><b>1<p>2</b>3</p></pre>
8063:
8064: <p>Up to the "2" the parsing here is straightforward:</p>
8065:
1.159 mike 8066: <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 8067: "b" is parsed.</p>
8068:
8069: <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
1.159 mike 8070: elements</a> has four elements on it: <code><a href="semantics.html#the-html-element-0">html</a></code>,
8071: <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 8072: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
8073: <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>
8074:
8075: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
8076: in the previous example. However, in this case, there <em>is</em> a
8077: <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
8078: this time the adoption agency algorithm isn't skipped over.</p>
8079:
1.159 mike 8080: <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 8081: element. A conceptual "bookmark" marks the position of the
8082: <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
8083: elements</a>, but since that list has only one element in it,
8084: it won't have much effect.</p>
8085:
8086: <p>As the algorithm progresses, <var title="">node</var> ends up set
8087: to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
8088: node</var> ends up set to the <var title="">furthest block</var>
8089: (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
8090:
8091: <p>The <var title="">last node</var> gets appended (moved) to the
8092: <var title="">common ancestor</var>, so that the DOM looks like:</p>
8093:
1.159 mike 8094: <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 8095: <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
8096:
1.159 mike 8097: <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 8098: <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
8099:
1.159 mike 8100: <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 8101: active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
8102: elements</a>, so that when the "3" is parsed, it is appended to
8103: the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
8104:
1.614 mike 8105: <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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 8106:
8107: <p><i>This section is non-normative.</i></p>
8108:
8109: <p>Error handling in tables is, for historical reasons, especially
8110: strange. For example, consider the following markup:</p>
8111:
8112: <pre><table><strong><b></strong><tr><td>aaa</td></tr><strong>bbb</strong></table>ccc</pre>
8113:
8114: <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
8115: directly inside a table like that, and the parser handles this case
8116: 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
8117: examining the DOM tree as it stands just after the
8118: <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
8119:
1.159 mike 8120: <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 8121: tag has been seen:</p>
8122:
1.159 mike 8123: <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
8124: 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 8125: <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
8126: resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
8127: elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
8128: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
8129: table">in table</a>".</p>
8130:
8131: <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
8132: to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
8133: 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
8134: then handled in a rather straight-forward manner, taking the parser
8135: through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
8136: body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
8137: row</a>" insertion modes, after which the DOM looks as
8138: follows:</p>
8139:
1.159 mike 8140: <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
8141: 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 8142: <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
8143: formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
8144: it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
8145: mode: in row">in row</a>".</p>
8146:
8147: <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
8148: <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
8149: 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
8150: mode</a>).</p>
8151:
1.159 mike 8152: <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 8153: no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
8154: node:</p>
8155:
1.159 mike 8156: <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 8157: handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
1.159 mike 8158: 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 8159: 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
8160: elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
8161: marker having been removed by the "td" end tag token); and the
8162: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
8163: table body">in table body</a>".</p>
8164:
8165: <p>Thus it is that the "bbb" character tokens are found. These
8166: trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
8167: text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
8168: insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
8169: body">in table body</a>"). The character tokens are collected,
8170: and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
8171: seen, they are processed as a group. Since they are not all spaces,
8172: 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,
8173: which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
8174: body</a>" insertion mode but with <a href="#foster-parent" title="foster
8175: parent">foster parenting</a>.</p>
8176:
8177: <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
8178: active formatting elements are reconstructed</a>, a
8179: <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
8180: parent">foster parented</a>, and then the "bbb" text node is
8181: appended to it:</p>
8182:
1.159 mike 8183: <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
8184: <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 8185: <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
8186: this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
8187: formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
8188: and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
8189: mode: in table body">in table body</a>".</p>
8190:
8191: <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
8192: character">space characters</a> instead of "bbb", then those
8193: <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
8194: appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
8195:
8196: <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
8197: tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
8198: elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
8199: but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
8200: elements</a>, so the "ccc" character tokens after the table
8201: result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
8202: time after the table:</p>
8203:
1.614 mike 8204: <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><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 8205:
8206: <p><i>This section is non-normative.</i></p>
8207:
8208: <p>Consider the following markup, which for this example we will
8209: 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 8210: content of an <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code> in another document with the
1.1 mike 8211: <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
8212:
8213: <pre><div id=a>
8214: <script>
8215: var div = document.getElementById('a');
8216: parent.document.body.appendChild(div);
8217: </script>
8218: <script>
8219: alert(document.URL);
8220: </script>
8221: </div>
8222: <script>
8223: alert(document.URL);
8224: </script></pre>
8225:
8226: <p>Up to the first "script" end tag, before the script is parsed,
8227: the result is relatively straightforward:</p>
8228:
1.306 mike 8229: <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="">
8230: </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 8231: and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
8232:
1.159 mike 8233: <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 8234: aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
8235: <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
1.306 mike 8236: <code><a href="semantics.html#the-div-element">div</a></code> element</em>.</p>
1.1 mike 8237:
8238: <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
8239: is inserted <em>into the outer <code>Document</code>
8240: object</em>.</p>
8241:
8242: <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
8243: the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
8244: object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
1.159 mike 8245: <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>.</p>
1.1 mike 8246:
8247: <p class="note">This isn't a security problem since the script that
1.306 mike 8248: moves the <code><a href="semantics.html#the-div-element">div</a></code> into the outer <code>Document</code> can
1.1 mike 8249: only do so because they have the two <code>Document</code> object
1.159 mike 8250: have the same <a href="browsers.html#origin">origin</a>.</p>
1.1 mike 8251:
8252: <p>Thus, the first alert says "http://example.com/outer".</p>
8253:
1.306 mike 8254: <p>Once the <code><a href="semantics.html#the-div-element">div</a></code> element's end tag is parsed, the
8255: <code><a href="semantics.html#the-div-element">div</a></code> element is popped off the stack, and so the next
1.1 mike 8256: <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
8257:
1.159 mike 8258: <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 8259:
8260:
8261:
1.614 mike 8262: <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 8263:
8264: <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
8265:
8266: <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
8267:
8268: <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
8269:
8270: <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
8271:
8272: <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
8273:
8274: <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
8275:
8276: <hr><p>Data mining tools and other user agents that perform operations
1.605 mike 8277: on <code><a href="iana.html#text-html">text/html</a></code> content without running scripts,
1.1 mike 8278: evaluating CSS or XPath expressions, or otherwise exposing the
8279: resulting DOM to arbitrary content, may "support namespaces" by just
8280: asserting that their DOM node analogues are in certain namespaces,
8281: without actually exposing the above strings.</p>
8282:
8283:
8284:
8285:
1.614 mike 8286: <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 8287:
8288: <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
8289: algorithm</dfn>. The algorithm takes as input a DOM
8290: <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
8291: exception.</p>
8292:
8293: <p class="note">This algorithm serializes the <em>children</em> of
8294: the node being serialized, not the node itself.</p>
8295:
8296: <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
8297: the empty string.</p></li>
8298:
8299: <li>
8300:
8301: <p>For each child node of <var title="">the node</var>, in
8302: <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
8303:
8304: </p><ol><li><p>Let <var title="">current node</var> be the child node
8305: being processed.</p></li>
8306:
8307: <li>
8308:
8309: <p>Append the appropriate string from the following list to
8310: <var title="">s</var>:</p>
8311:
8312: <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
8313:
8314: <dd>
8315:
1.588 mike 8316: <p>Append a U+003C LESS-THAN SIGN character character (<),
8317: followed by the element's tag name. (For nodes created by the
8318: <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
1.1 mike 8319: lowercase.)</p>
8320:
8321: <p>For each attribute that the element has, append a U+0020
8322: SPACE character, the attribute's name (which, for attributes
8323: 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
1.588 mike 8324: U+003D EQUALS SIGN character (=), a U+0022 QUOTATION MARK
8325: character ("), the attribute's value, <a href="#escapingString" title="escaping a string">escaped as described below</a> in
8326: <i>attribute mode</i>, and a second U+0022 QUOTATION MARK
8327: character (").</p>
1.1 mike 8328:
8329: <p>While the exact order of attributes is UA-defined, and may
8330: depend on factors such as the order that the attributes were
8331: given in the original markup, the sort order must be stable,
8332: such that consecutive invocations of this algorithm serialize an
8333: element's attributes in the same order.</p>
8334:
1.588 mike 8335: <p>Append a U+003E GREATER-THAN SIGN character (>).</p>
1.1 mike 8336:
8337: <p>If <var title="">current node</var> is an
1.5 mike 8338: <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 8339: <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 8340: <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>,
8341: <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>,
1.589 mike 8342: <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>, or
8343: <code>wbr</code> element, then continue on to the next child
8344: node at this point.</p> <!-- also, i guess: image and isindex,
8345: but we don't list those because we don't consider those
8346: "elements", more "macros", and thus we should never serialize
8347: them -->
1.1 mike 8348:
8349: <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42 mike 8350: <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 8351: a U+000A LINE FEED (LF) character.</p>
8352:
8353: <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
8354: serialization algorithm</a> on the <var title="">current
8355: node</var> element (thus recursing into this algorithm for
1.588 mike 8356: that element), followed by a U+003C LESS-THAN SIGN character
8357: (<), a U+002F SOLIDUS character (/), the element's tag name
8358: again, and finally a U+003E GREATER-THAN SIGN character
8359: (>).</p>
1.1 mike 8360:
8361: </dd>
8362:
8363:
8364: <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
8365: node</dt>
8366:
8367: <dd>
8368:
1.19 mike 8369: <p>If the parent of <var title="">current node</var> is a
1.42 mike 8370: <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 8371: <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 8372: <code><a href="obsolete.html#noframes">noframes</a></code>, or <code><a href="obsolete.html#plaintext">plaintext</a></code> element, or
8373: if the parent of <var title="">current node</var> is
8374: <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
8375: node, then append the value of <var title="">current
8376: node</var>'s <code title="">data</code> IDL attribute
8377: literally.</p>
1.1 mike 8378:
8379: <p>Otherwise, append the value of <var title="">current
1.192 mike 8380: node</var>'s <code title="">data</code> IDL attribute, <a href="#escapingString" title="escaping a string">escaped as described
1.1 mike 8381: below</a>.</p>
8382:
8383: </dd>
8384:
8385:
8386: <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
8387:
8388: <dd>
8389:
8390: <p>Append the literal string <code><!--</code> (U+003C
8391: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
1.192 mike 8392: U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1 mike 8393: attribute, followed by the literal string <code>--></code>
8394: (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
8395: SIGN).</p>
8396:
8397: </dd>
8398:
8399:
8400: <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
8401:
8402: <dd>
8403:
8404: <p>Append the literal string <code><?</code> (U+003C
8405: LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
1.192 mike 8406: of <var title="">current node</var>'s <code title="">target</code> IDL attribute, followed by a single
8407: U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1 mike 8408: attribute, followed by a single U+003E GREATER-THAN SIGN
1.464 mike 8409: character (>).</p>
1.1 mike 8410:
8411: </dd>
8412:
8413:
8414: <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
8415:
8416: <dd>
8417:
8418: <p>Append the literal string <code><!DOCTYPE</code> (U+003C
8419: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
8420: LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
8421: LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
8422: LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
8423: LETTER E), followed by a space (U+0020 SPACE), followed by the
1.192 mike 8424: value of <var title="">current node</var>'s <code title="">name</code> IDL attribute, followed by the literal
1.1 mike 8425: string <code>></code> (U+003E GREATER-THAN SIGN).</p>
8426:
8427: </dd>
8428:
8429:
8430: </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
8431: occur as children of elements. If, despite this, they somehow do
8432: occur, this algorithm must raise an
8433: <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
8434:
8435: </li>
8436:
8437: </ol></li>
8438:
8439: <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
8440:
8441: </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
8442: purposes of the algorithm above) consists of replacing any
8443: occurrences of the "<code title="">&</code>" character by the
8444: string "<code title="">&amp;</code>", any occurrences of the
8445: U+00A0 NO-BREAK SPACE character by the string "<code title="">&nbsp;</code>", and, if the algorithm was invoked in
8446: 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
8447: 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>
8448:
8449: <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
8450: agent, and are therefore not covered in the algorithm above.</p>
8451:
8452: <p class="note">It is possible that the output of this algorithm, if
8453: parsed with an <a href="#html-parser">HTML parser</a>, will not return the
8454: original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
8455: element to which a <code title="">Comment</code> node has been
8456: appended is serialized and the output is then reparsed, the comment
8457: will end up being displayed in the text field. Similarly, if, as a
8458: result of DOM manipulation, an element contains a comment that
8459: contains the literal string "<code title="">--></code>", then
8460: when the result of serializing the element is parsed, the comment
8461: will be truncated at that point and the rest of the comment will be
8462: interpreted as markup. More examples would be making a
8463: <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
8464: "<code></script></code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
8465: 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
8466: <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
8467: tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
8468:
8469:
1.614 mike 8470: <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 8471:
8472: <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
8473: algorithm</dfn>. The algorithm optionally takes as input an
8474: <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
8475: parser, as well as <var title="">input</var>, a string to parse, and
8476: returns a list of zero or more nodes.</p>
8477:
8478: <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
8479: in the parser section are parts that only occur if the parser was
8480: created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
8481: with such markings for informational purposes only; such markings
8482: have no normative weight. If it is possible for a condition
8483: described as a <a href="#fragment-case">fragment case</a> to occur even when the
8484: parser wasn't created for the purposes of handling this algorithm,
8485: then that is an error in the specification.</p>
8486:
8487: <ol><li>
8488:
8489: <p>Create a new <code>Document</code> node, and mark it as being
8490: an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
8491:
8492: </li>
8493:
8494: <li>
8495:
8496: <p>If there is a <var title="">context</var> element, and the
8497: <code>Document</code> of the <var title="">context</var> element
8498: is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
8499: 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
8500: the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
8501: mode</a>, then let the <code>Document</code> be in
8502: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
8503: <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
8504:
8505: </li>
8506:
8507: <li>
8508:
8509: <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
8510: the just created <code>Document</code> node.</p>
8511:
8512: </li>
8513:
8514: <li>
8515:
8516: <p>If there is a <var title="">context</var> element, run these
8517: substeps:</p>
8518:
8519: <ol><li>
8520:
1.541 mike 8521: <p>Set the state of the <a href="#html-parser">HTML parser</a>'s
8522: <a href="#tokenization">tokenization</a> stage as follows:</p>
1.1 mike 8523:
1.159 mike 8524: <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 8525: element</dt>
8526:
1.541 mike 8527: <dd>Switch the tokenizer to the <a href="#rcdata-state">RCDATA state</a>.</dd>
1.1 mike 8528:
8529:
1.672 mike 8530: <dt>If it is a <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="obsolete.html#xmp">xmp</a></code>,
8531: <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 8532: <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1 mike 8533:
1.541 mike 8534: <dd>Switch the tokenizer to the <a href="#rawtext-state">RAWTEXT state</a>.</dd>
1.1 mike 8535:
8536:
1.672 mike 8537: <dt>If it is a <code><a href="semantics.html#script">script</a></code> element</dt>
8538:
8539: <dd>Switch the tokenizer to the <a href="#script-data-state">script data state</a>.</dd>
8540:
8541:
1.1 mike 8542: <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
8543:
1.541 mike 8544: <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, switch the
8545: tokenizer to the <a href="#rawtext-state">RAWTEXT state</a>. Otherwise,
8546: leave the tokenizer in the <a href="#data-state">data state</a>.</dd>
1.1 mike 8547:
8548:
1.42 mike 8549: <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1 mike 8550:
1.541 mike 8551: <dd>Switch the tokenizer to the <a href="#plaintext-state">PLAINTEXT
8552: state</a>.</dd>
1.1 mike 8553:
8554:
8555: <dt>Otherwise</dt>
8556:
1.541 mike 8557: <dd>Leave the tokenizer in the <a href="#data-state">data state</a>.</dd>
1.1 mike 8558:
1.672 mike 8559: </dl><p class="note">For performance reasons, an implementation that
8560: uses the actual state machine described in this specification
8561: directly could use the PLAINTEXT state instead of the RAWTEXT
8562: and script data states where those are mentioned in the list
8563: above. They are equivalent, since there is no <a href="#appropriate-end-tag-token">appropriate
8564: end tag token</a> in the fragment case, but involve far fewer
8565: state transitions.</p>
8566:
8567: </li>
1.1 mike 8568:
8569: <li>
8570:
1.159 mike 8571: <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 8572: with no attributes.</p>
8573:
8574: </li>
8575:
8576: <li>
8577:
8578: <p>Append the element <var title="">root</var> to the
8579: <code>Document</code> node created above.</p>
8580:
8581: </li>
8582:
8583: <li>
8584:
8585: <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
8586: it contains just the single element <var title="">root</var>.</p>
8587:
8588: </li>
8589:
8590: <li>
8591:
8592: <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
8593: parser's insertion mode appropriately</a>.</p>
8594:
8595: <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
8596:
8597: </li>
8598:
8599: <li>
8600:
8601: <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
8602: to the nearest node to the <var title="">context</var> element
8603: that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
8604: ancestor chain, and including the element itself, if it is a
8605: <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
8606: <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
8607:
8608: </li>
8609:
8610: </ol></li>
8611:
8612: <li>
8613:
8614: <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
8615: parser</a> just created the <var title="">input</var>. The
8616: encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
8617: <i>irrelevant</i>.</p>
8618:
8619: </li>
8620:
8621: <li>
8622:
8623: <p>Start the parser and let it run until it has consumed all the
8624: characters just inserted into the input stream.</p>
8625:
8626: </li>
8627:
8628: <li>
8629:
8630: <p>If there is a <var title="">context</var> element, return the
8631: child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
8632: order</a>.</p>
8633:
8634: <p>Otherwise, return the children of the <code>Document</code>
8635: object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
8636:
8637: </li>
8638:
1.123 mike 8639: </ol></div></body></html>
Webmaster