Annotation of html5/spec/syntax.html, revision 1.828
1.2 mike 1: <!DOCTYPE HTML>
1.755 mike 2: <!-- when publishing, change bits marked ZZZ --><html lang="en-US-x-Hixie"><head><title>8 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.736 mike 169: body.dfnEnabled dfn { cursor: pointer; }
170: .dfnPanel {
171: display: inline;
172: position: absolute;
173: z-index: 10;
174: height: auto;
175: width: auto;
176: padding: 0.5em 0.75em;
177: font: small sans-serif, Droid Sans Fallback;
178: background: #DDDDDD;
179: color: black;
180: border: outset 0.2em;
181: }
182: .dfnPanel * { margin: 0; padding: 0; font: inherit; text-indent: 0; }
183: .dfnPanel :link, .dfnPanel :visited { color: black; }
184: .dfnPanel p { font-weight: bolder; }
185: .dfnPanel * + p { margin-top: 0.25em; }
186: .dfnPanel li { list-style-position: inside; }
187:
1.671 mike 188: #configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
189: #configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
190: #configUI p label { display: block; }
191: #configUI #updateUI, #configUI .loginUI { text-align: center; }
192: #configUI input[type=button] { display: block; margin: auto; }
1.267 mike 193: </style><style type="text/css">
194:
1.292 mike 195: .applies thead th > * { display: block; }
196: .applies thead code { display: block; }
197: .applies tbody th { whitespace: nowrap; }
198: .applies td { text-align: center; }
199: .applies .yes { background: yellow; }
200:
1.267 mike 201: .matrix, .matrix td { border: none; text-align: right; }
202: .matrix { margin-left: 2em; }
203:
204: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
205: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
206: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
207:
208: #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
209: #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
210: #table-example-1 caption { padding-bottom: 0.5em; }
211: #table-example-1 thead, #table-example-1 tbody { border: none; }
212: #table-example-1 th, #table-example-1 td { border: solid thin; }
213: #table-example-1 th { font-weight: normal; }
214: #table-example-1 td { border-style: none solid; vertical-align: top; }
215: #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
216: #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
217: #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
218: #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
219: #table-example-1 tbody td:first-child::after { content: leader(". "); }
220: #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
221: #table-example-1 tbody td:first-child + td { width: 10em; }
222: #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
223: #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
224:
225: .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
226: .apple-table-examples * { font-family: "Times", serif; }
227: .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
228: .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
229: .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
230: .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
231: .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
232: .apple-table-examples td { text-align: right; vertical-align: top; }
233: .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
234: .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
235: .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
236: .apple-table-examples sup { line-height: 0; }
237:
1.724 mike 238: .details-example img { vertical-align: top; }
239:
240: </style><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 type="text/javascript">
1.671 mike 241: function getCookie(name) {
242: var params = location.search.substr(1).split("&");
243: for (var index = 0; index < params.length; index++) {
244: if (params[index] == name)
245: return "1";
246: var data = params[index].split("=");
247: if (data[0] == name)
248: return unescape(data[1]);
249: }
250: var cookies = document.cookie.split("; ");
251: for (var index = 0; index < cookies.length; index++) {
252: var data = cookies[index].split("=");
253: if (data[0] == name)
254: return unescape(data[1]);
255: }
256: return null;
257: }
258: function load(script) {
259: var e = document.createElement('script');
260: e.setAttribute('src', 'http://www.whatwg.org/specs/web-apps/current-work/' + script + '?' + encodeURIComponent(location) + '&' + encodeURIComponent(document.referrer));
261: document.body.appendChild(e);
262: }
263: function init() {
264: if (location.search == '?slow-browser')
265: return;
266: var configUI = document.createElement('div');
267: configUI.id = 'configUI';
268: document.body.appendChild(configUI);
269: // load('reviewer.js'); // would need cross-site XHR
270: if (document.getElementById('head'))
271: load('toc.js');
272: load('styler.js');
273: // load('updater.js'); // would need cross-site XHR
1.724 mike 274: load('dfn.js'); // doesn't support split-out specs, but, oh well.
1.671 mike 275: // load('status.js'); // would need cross-site XHR
276: if (getCookie('profile') == '1')
277: document.getElementsByTagName('h2')[0].textContent += '; load: ' + (new Date() - loadTimer) + 'ms';
278: fixBrokenLink();
279: }
1.808 mike 280: </script><link href="http://www.w3.org/StyleSheets/TR/W3C-WD" rel="stylesheet" type="text/css">
1.2 mike 281: <script src="link-fixup.js"></script>
1.755 mike 282: <link href="editing.html" title="7 User interaction" rel="prev">
1.2 mike 283: <link href="spec.html#contents" title="Table of contents" rel="index">
1.755 mike 284: <link href="named-character-references.html" title="8.5 Named character references" rel="next">
1.671 mike 285: </head><body onload="fixBrokenLink(); init()"><div class="head" id="head">
1.1 mike 286: <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 287: <h1>HTML5</h1>
1.1 mike 288: <h2 class="no-num no-toc" id="a-vocabulary-and-associated-apis-for-html-and-xhtml">A vocabulary and associated APIs for HTML and XHTML</h2>
1.123 mike 289: </div><nav>
1.755 mike 290: <a href="editing.html">← 7 User interaction</a> –
1.2 mike 291: <a href="spec.html#contents">Table of contents</a> –
1.755 mike 292: <a href="named-character-references.html">8.5 Named character references →</a>
1.828 ! mike 293: </nav><p>This is revision 1.3820.</p>
1.659 mike 294:
1.1 mike 295:
1.755 mike 296: <h2 id="syntax"><span class="secno">8 </span><dfn>The HTML syntax</dfn></h2><p class="note">This section only describes the rules for resources
1.725 mike 297: labeled with an <a href="infrastructure.html#html-mime-type">HTML MIME type</a>. Rules for XML resources
298: are discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.755 mike 299: syntax</a>".</p><h3 id="writing"><span class="secno">8.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 300:
301: <p><i>This section only applies to documents, authoring tools, and
302: markup generators. In particular, it does not apply to conformance
303: checkers; conformance checkers must use the requirements given in
304: the next section ("parsing HTML documents").</i></p>
305:
1.123 mike 306: </div><p>Documents must consist of the following parts, in the given
307: order:</p><ol><li>Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.</li>
1.1 mike 308:
309: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
310: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
311:
312: <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
313:
314: </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
315: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
316:
1.159 mike 317: <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 318:
319: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
320: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
321:
322: </ol><p>The various types of content mentioned above are described in the
1.123 mike 323: 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 324: declarations</a> are to be serialized, as discussed in the
1.123 mike 325: section on that topic.</p><div class="note">
1.1 mike 326:
1.159 mike 327: <p>Space characters before the root <code><a href="semantics.html#the-html-element-0">html</a></code> element, and
328: space characters at the start of the <code><a href="semantics.html#the-html-element-0">html</a></code> element and
329: before the <code><a href="semantics.html#the-head-element-0">head</a></code> element, will be dropped when the
1.1 mike 330: document is parsed; space characters <em>after</em> the root
1.159 mike 331: <code><a href="semantics.html#the-html-element-0">html</a></code> element will be parsed as if they were at the end
332: of the <code><a href="semantics.html#the-body-element-0">body</a></code> element. Thus, space characters around the
1.1 mike 333: root element do not round-trip.</p>
334:
335: <p>It is suggested that newlines be inserted after the DOCTYPE,
336: after any comments that are before the root element, after the
1.159 mike 337: <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
338: that are inside the <code><a href="semantics.html#the-html-element-0">html</a></code> element but before the
339: <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 340:
1.123 mike 341: </div><p>Many strings in the HTML syntax (e.g. the names of elements and
1.1 mike 342: their attributes) are case-insensitive, but only for characters in
1.547 mike 343: the ranges U+0041 to U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
344: LETTER Z) and U+0061 to U+007A (LATIN SMALL LETTER A to LATIN SMALL
1.1 mike 345: LETTER Z). For convenience, in this section this is just referred to
1.813 mike 346: as "case-insensitive".</p><h4 id="the-doctype"><span class="secno">8.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) and <a href="http://www.w3.org/html/wg/tracker/issues/84">ISSUE-84</a> (legacy-doctypes) block progress to Last Call</span></p><p>A <dfn id="syntax-doctype" title="syntax-doctype">DOCTYPE</dfn> is a mostly useless,
1.123 mike 347: but required, header.</p><p class="note">DOCTYPEs are required for legacy reasons. When
1.1 mike 348: omitted, browsers tend to use a different rendering mode that is
349: incompatible with some specifications. Including the DOCTYPE in a
350: document ensures that the browser makes a best-effort attempt at
1.123 mike 351: following the relevant specifications.</p><p>A DOCTYPE must consist of the following characters, in this
1.588 mike 352: order:</p><ol class="brief"><li>A U+003C LESS-THAN SIGN character (<).</li>
353: <li>A U+0021 EXCLAMATION MARK character (!).</li>
1.1 mike 354: <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>
355: <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
356: <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>
357: <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> (defined below).</li>
358: <li>Zero or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.588 mike 359: <li>A U+003E GREATER-THAN SIGN character (>).</li>
1.1 mike 360: </ol><p class="note">In other words, <code><!DOCTYPE HTML></code>,
1.123 mike 361: case-insensitively.</p><p>For the purposes of HTML generators that cannot output HTML
1.1 mike 362: markup with the short DOCTYPE "<code title=""><!DOCTYPE
363: HTML></code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
364: into the DOCTYPE (in the position defined above). This string must
1.123 mike 365: 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 366: <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 367: <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.1 mike 368: <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
1.465 mike 369: <li>The literal string "<code><a href="infrastructure.html#about:legacy-compat">about:legacy-compat</a></code>".</li>
1.1 mike 370: <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>
371: </ol><p class="note">In other words, <code><!DOCTYPE HTML SYSTEM
372: "about:legacy-compat"></code> or <code><!DOCTYPE HTML SYSTEM
373: 'about:legacy-compat'></code>, case-insensitively except for the bit
1.724 mike 374: in single or double quotes.</p><p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1 mike 375: the document is generated from a system that cannot output the
1.755 mike 376: shorter string.</p><h4 id="elements-0"><span class="secno">8.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 377: <a href="#raw-text-elements">raw text elements</a>, <a href="#rcdata-elements">RCDATA elements</a>,
378: <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 379:
380: <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 381: <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>,
382: <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 383: <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 384: <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 385:
1.373 mike 386: <dt><dfn id="raw-text-elements">Raw text elements</dfn></dt>
1.1 mike 387:
388: <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 389: noscript don't count as raw text for syntax purposes -->
1.1 mike 390:
1.373 mike 391: <dt><dfn id="rcdata-elements">RCDATA elements</dfn></dt>
1.1 mike 392:
1.159 mike 393: <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 394:
1.373 mike 395: <dt><dfn id="foreign-elements">Foreign elements</dfn></dt>
1.1 mike 396:
1.724 mike 397: <dd>Elements from the <a href="infrastructure.html#mathml-namespace">MathML namespace</a>
398: and the <a href="infrastructure.html#svg-namespace">SVG namespace</a>.</dd>
1.1 mike 399:
1.373 mike 400: <dt><dfn id="normal-elements">Normal elements</dfn></dt>
1.1 mike 401:
402: <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
403: elements.</dd>
404:
405: </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.373 mike 406: and end of elements in the markup. <a href="#raw-text-elements" title="raw text
407: elements">Raw text</a>, <a href="#rcdata-elements" title="RCDATA
408: elements">RCDATA</a>, and <a href="#normal-elements" title="normal
409: elements">normal</a> elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to indicate where they
410: begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> to
411: indicate where they end. The start and end tags of certain
412: <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 413: later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
414: elements</a> only have a start tag; end tags must not be
1.373 mike 415: specified for <a href="#void-elements">void elements</a>. <a href="#foreign-elements">Foreign
416: elements</a> must either have a start tag and an end tag, or a
417: start tag that is marked as self-closing, in which case they must
418: not have an end tag.</p><p>The contents of the element must be placed between just after the
1.1 mike 419: start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
420: in certain cases</a>) and just before the end tag (which again,
421: <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
422: cases</a>). The exact allowed contents of each individual element
423: depends on the content model of that element, as described earlier
424: in this specification. Elements must not contain content that their
425: content model disallows. In addition to the restrictions placed on
426: the contents by those content models, however, the five types of
1.123 mike 427: 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 428: no end tag, no content can be put between the start tag and the end
1.373 mike 429: 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
430: 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
431: must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
1.1 mike 432: There are also <a href="#cdata-rcdata-restrictions">further
1.373 mike 433: restrictions</a> described below.</p><p><a href="#foreign-elements">Foreign elements</a> whose start tag is marked as
434: self-closing can't have any contents (since, again, as there's no
435: end tag, no content can be put between the start tag and the end
436: tag). <a href="#foreign-elements">Foreign elements</a> whose start tag is <em>not</em>
437: 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 438: 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 439:
440: <p>The HTML syntax does not support namespace
441: declarations, even in <a href="#foreign-elements">foreign elements</a>.</p>
442:
443: <p>For instance, consider the following HTML fragment:</p>
444:
445: <pre><p>
446: <svg>
447: <metadata>
448: <!-- this is invalid -->
449: <cdr:license xmlns:cdr="http://www.example.com/cdr/metadata" name="MIT"/>
450: </metadata>
451: </svg>
452: </p></pre>
453:
454: <p>The innermost element, <code title="">cdr:license</code>, is
455: actually in the SVG namespace, as the "<code title="">xmlns:cdr</code>" attribute has no effect (unlike in
456: XML). In fact, as the comment in the fragment above says, the
457: fragment is actually non-conforming. This is because the SVG
458: specification does not define any elements called "<code title="">cdr:license</code>" in the SVG namespace.</p>
459:
460: </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 461: contain the character U+003C LESS-THAN SIGN (<) or an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>. Some
462: <a href="#normal-elements">normal elements</a> also have <a href="#element-restrictions">yet more restrictions</a> on what
1.1 mike 463: content they are allowed to hold, beyond the restrictions imposed by
464: the content model and those described in this paragraph. Those
1.123 mike 465: restrictions are described below.</p><p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1 mike 466: giving the element's name. HTML elements all have names that only
1.464 mike 467: use characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT
468: NINE (9), U+0061 LATIN SMALL LETTER A to U+007A LATIN SMALL LETTER
469: Z, and U+0041 LATIN CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER
470: Z. In the HTML syntax, tag names, even those for <a href="#foreign-elements">foreign
1.462 mike 471: elements</a>, may be written with any mix of lower- and uppercase
472: letters that, when converted to all-lowercase, matches the element's
1.755 mike 473: tag name; tag names are case-insensitive.</p><h5 id="start-tags"><span class="secno">8.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 474: following format:</p><ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.588 mike 475: SIGN character (<).</li>
1.1 mike 476:
477: <li>The next few characters of a start tag must be the element's
478: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
479:
480: <li>If there are to be any attributes in the next step, there must
481: first be one or more <a href="infrastructure.html#space-character" title="space character">space
482: characters</a>.</li>
483:
484: <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
485: below. Attributes may be separated from each other by one or more
486: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
487:
1.766 mike 488: <li>After the attributes, or after the <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a> if there are no attributes,
489: there may be one or more <a href="infrastructure.html#space-character" title="space character">space
490: characters</a>. (Some attributes are required to be followed by
491: a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes
492: section</a> below.)</li>
1.1 mike 493:
494: <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
1.373 mike 495: or if the element is a <a href="#foreign-elements" title="foreign elements">foreign
1.588 mike 496: element</a>, then there may be a single U+002F SOLIDUS character
497: (/). This character has no effect on <a href="#void-elements">void elements</a>,
498: but on <a href="#foreign-elements">foreign elements</a> it marks the start tag as
499: self-closing.</li>
1.1 mike 500:
501: <li>Finally, start tags must be closed by a U+003E GREATER-THAN
1.588 mike 502: SIGN character (>).</li>
1.1 mike 503:
1.755 mike 504: </ol><h5 id="end-tags"><span class="secno">8.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 505: following format:</p><ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.588 mike 506: SIGN character (<).</li>
1.1 mike 507:
508: <li>The second character of an end tag must be a U+002F SOLIDUS
1.588 mike 509: character (/).</li>
1.1 mike 510:
511: <li>The next few characters of an end tag must be the element's
512: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
513:
514: <li>After the tag name, there may be one or more <a href="infrastructure.html#space-character" title="space
515: character">space characters</a>.</li>
516:
1.588 mike 517: <li>Finally, end tags must be closed by a U+003E GREATER-THAN SIGN
518: character (>).</li>
1.1 mike 519:
1.755 mike 520: </ol><h5 id="attributes"><span class="secno">8.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 521: 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 522: one or more characters other than the <a href="infrastructure.html#space-character" title="space
523: character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
524: MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
525: (>), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters,
526: the control characters, and any characters that are not defined by
1.462 mike 527: Unicode. In the HTML syntax, attribute names, even those for
528: <a href="#foreign-elements">foreign elements</a>, may be written with any mix of lower-
529: and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.123 mike 530: 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 531: 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 532: 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 533:
534: <dd>
535:
536: <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
537: name</a>.</p>
538:
539: <div class="example">
540:
541: <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
542: the empty attribute syntax:</p>
543:
544: <pre><input <em>disabled</em>></pre>
545:
546: </div>
547:
548: <p>If an attribute using the empty attribute syntax is to be
549: followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
550: character</a> separating the two.</p>
551:
552: </dd>
553:
1.2 mike 554: <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1 mike 555:
556: <dd>
557:
558: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
559: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
560: characters</a>, followed by a single U+003D EQUALS SIGN
561: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
562: character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
563: addition to the requirements given above for attribute values,
564: must not contain any literal <a href="infrastructure.html#space-character" title="space character">space
1.588 mike 565: characters</a>, any U+0022 QUOTATION MARK characters ("),
566: U+0027 APOSTROPHE characters ('), U+003D EQUALS SIGN
567: characters (=), U+003C LESS-THAN SIGN characters (<), U+003E
568: GREATER-THAN SIGN characters (>), or U+0060 GRAVE ACCENT
569: characters (`), and must not be the empty string.</p>
1.463 mike 570:
571: <!-- The ` character is in this list on a temporary basis, waiting
572: for IE to fix it's parsing bug whereby it treats ` as an
573: attribute value delimiter. Otherwise, escaping software that
574: tries to be clever and not use quotes when it doesn't need to
575: could be tricked by an attacker.
576:
577: Posit a site that allows the user to input text that is used
578: verbatim in two attributes, such that the user can set the
579: first attribute's value to:
580:
581: `
582:
583: ...and the second to:
584:
585: ` onload='...payload...' end=x
586:
587: ...with the assumption that the site is going to not quote
588: the first one, and quote the second one with double quotes:
589:
590: <body title=` class="` onload='...payload...' end=x">
591:
592: In IE, this is treated as:
593:
594: <body title=' class="'
595: onload='...payload...'
596: end='x"'>
597:
598: -->
599:
1.1 mike 600:
601: <div class="example">
602:
603: <p>In the following example, the <code title="attr-input-value"><a href="forms.html#attr-input-value">value</a></code> attribute is given
604: with the unquoted attribute value syntax:</p>
605:
606: <pre><input <em>value=yes</em>></pre>
607:
608: </div>
609:
610: <p>If an attribute using the unquoted attribute syntax is to be
1.101 mike 611: followed by another attribute or by the optional U+002F SOLIDUS
1.464 mike 612: 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 613: must be a <a href="infrastructure.html#space-character">space character</a> separating the two.</p>
614:
615: </dd>
616:
617: <dt>Single-quoted attribute value syntax</dt>
618:
619: <dd>
620:
621: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
622: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
623: characters</a>, followed by a single U+003D EQUALS SIGN
624: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
625: character">space characters</a>, followed by a single U+0027
1.588 mike 626: APOSTROPHE character ('), followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
1.1 mike 627: addition to the requirements given above for attribute values,
1.588 mike 628: must not contain any literal U+0027 APOSTROPHE characters ('), and
629: finally followed by a second single U+0027 APOSTROPHE character
630: (').</p>
1.1 mike 631:
632: <div class="example">
633:
634: <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
635: single-quoted attribute value syntax:</p>
636:
637: <pre><input <em>type='checkbox'</em>></pre>
638:
639: </div>
640:
641: <p>If an attribute using the single-quoted attribute syntax is to
642: be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
643: character</a> separating the two.</p>
644:
645: </dd>
646:
647: <dt>Double-quoted attribute value syntax</dt>
648:
649: <dd>
650:
651: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
652: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
653: characters</a>, followed by a single U+003D EQUALS SIGN
654: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
655: character">space characters</a>, followed by a single U+0022
1.588 mike 656: QUOTATION MARK character ("), followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
1.1 mike 657: addition to the requirements given above for attribute values,
1.588 mike 658: must not contain any literal U+0022 QUOTATION MARK characters ("),
659: and finally followed by a second single U+0022 QUOTATION MARK
660: character (").</p>
1.1 mike 661:
662: <div class="example">
663:
664: <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
665: double-quoted attribute value syntax:</p>
666:
667: <pre><input <em>name="be evil"</em>></pre>
668:
669: </div>
670:
671: <p>If an attribute using the double-quoted attribute syntax is to
672: be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
673: character</a> separating the two.</p>
674:
675: </dd>
676:
677: </dl><p>There must never be two or more attributes on the same start tag
678: whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.462 mike 679: each other.</p><hr><p>When a <a href="#foreign-elements" title="foreign elements">foreign element</a> has
680: one of the namespaced attributes given by the local name and
681: namespace of the first and second cells of a row from the following
682: table, it must be written using the name given by the third cell
683: from the same row.</p><table><thead><tr><th> Local name </th><th> Namespace </th><th> Attribute name
1.724 mike 684: </th></tr></thead><tbody><tr><td> <code title="">actuate</code> </td><td> <a href="infrastructure.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:actuate</code>
685: </td></tr><tr><td> <code title="">arcrole</code> </td><td> <a href="infrastructure.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:arcrole</code>
686: </td></tr><tr><td> <code title="">href</code> </td><td> <a href="infrastructure.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:href</code>
687: </td></tr><tr><td> <code title="">role</code> </td><td> <a href="infrastructure.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:role</code>
688: </td></tr><tr><td> <code title="">show</code> </td><td> <a href="infrastructure.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:show</code>
689: </td></tr><tr><td> <code title="">title</code> </td><td> <a href="infrastructure.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:title</code>
690: </td></tr><tr><td> <code title="">type</code> </td><td> <a href="infrastructure.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:type</code>
691: </td></tr><tr><td> <code title="">base</code> </td><td> <a href="infrastructure.html#xml-namespace">XML namespace</a> <!-- attr-xml-base --> </td><td> <code title="">xml:base</code>
692: </td></tr><tr><td> <code title="">lang</code> </td><td> <a href="infrastructure.html#xml-namespace">XML namespace</a> </td><td> <code title="">xml:lang</code>
693: </td></tr><tr><td> <code title="">space</code> </td><td> <a href="infrastructure.html#xml-namespace">XML namespace</a> </td><td> <code title="">xml:space</code>
694: </td></tr><tr><td> <code title="">xmlns</code> </td><td> <a href="infrastructure.html#xmlns-namespace">XMLNS namespace</a> </td><td> <code title="">xmlns</code>
695: </td></tr><tr><td> <code title="">xlink</code> </td><td> <a href="infrastructure.html#xmlns-namespace">XMLNS namespace</a> </td><td> <code title="">xmlns:xlink</code>
1.671 mike 696: </td></tr></tbody></table><p>No other namespaced attribute can be expressed in <a href="#syntax">the
1.755 mike 697: HTML syntax</a>.</p><h5 id="optional-tags"><span class="secno">8.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 698: is not present; it is implied, but it is still there. An HTML
1.159 mike 699: document always has a root <code><a href="semantics.html#the-html-element-0">html</a></code> element, even if the
1.1 mike 700: string <code title=""><html></code> doesn't appear anywhere in
1.159 mike 701: 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
702: 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
703: tag</a> may be omitted if the <code><a href="semantics.html#the-html-element-0">html</a></code> element is not
1.821 mike 704: 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
705: element is empty, or if the first thing inside the
1.159 mike 706: <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
707: tag</a> may be omitted if the <code><a href="semantics.html#the-head-element-0">head</a></code> element is not
708: 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
709: 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 710: 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 711: 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 712: <code><a href="semantics.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
1.724 mike 713: tag is present, the parser makes <style> and <script type="text/javascript"> elements
1.1 mike 714: between </head> and <body> end up in the <head> instead of implying
1.159 mike 715: 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
716: 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 717: 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 718: tag</a> may be omitted if the <code><a href="semantics.html#the-li-element">li</a></code> element is
719: immediately followed by another <code><a href="semantics.html#the-li-element">li</a></code> element or if there
1.422 mike 720: 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 721: tag</a> may be omitted if the <code><a href="semantics.html#the-dt-element">dt</a></code> element is
722: immediately followed by another <code><a href="semantics.html#the-dt-element">dt</a></code> element or a
1.123 mike 723: <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 724: tag</a> may be omitted if the <code><a href="semantics.html#the-dd-element">dd</a></code> element is
725: immediately followed by another <code><a href="semantics.html#the-dd-element">dd</a></code> element or a
726: <code><a href="semantics.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.123 mike 727: 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 728: tag</a> may be omitted if the <code><a href="semantics.html#the-p-element">p</a></code> element is
729: immediately followed by an <code><a href="semantics.html#the-address-element">address</a></code>,
730: <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 731: <!--v2DATAGRID <code>datagrid</code>,--> <code><a href="obsolete.html#dir">dir</a></code>,
1.306 mike 732: <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 733: <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>,
734: <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>,
735: <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>,
736: <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>,
737: <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 738: <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>,
739: element, or if there is no more content in the parent element and
1.123 mike 740: 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 741: tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element is
742: 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 743: 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 744: tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element is
745: 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 746: 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 747: <select>; commented out text below can handle the non-<select> case
1.123 mike 748: 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 749: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
750: <code>select</code> element and--> is immediately followed by
751: another <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
752: that are ancestors of the <code>optgroup</code> element, up to and
753: including the first ancestor element that is not an
754: <code>optgroup</code> element, have no more content--> there is no
1.123 mike 755: more content in the parent element.</p><!-- so e.g. the max number of </optgroup>s are omitted here:
1.1 mike 756: <select><optgroup></select>
757: <p id=x><optgroup></optgroup>x</p>
758: <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
759: <p><optgroup id=x><optgroup></optgroup>x</p>
760: <p><optgroup><optgroup id=x>x</p>
1.123 mike 761: --><!-- </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 762: tag</a> may be omitted if the <code><a href="forms.html#the-option-element">option</a></code> element is
763: immediately followed by another <code><a href="forms.html#the-option-element">option</a></code> element, or if
764: it is immediately followed by an <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or
1.123 mike 765: 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 766: first thing inside the <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is a
767: <code><a href="tabular-data.html#the-col-element">col</a></code> element, and if the element is not immediately
768: 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 769: 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 770: <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.123 mike 771: <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 772: tag</a> may be omitted if the <code><a href="tabular-data.html#the-thead-element">thead</a></code> element is
773: 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 774: 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 775: first thing inside the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is a
776: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, and if the element is not immediately
777: 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
778: <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
779: tag</a> has been omitted. (It can't be omitted if the element is
1.123 mike 780: 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 781: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is
782: 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 783: 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 784: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element is
785: immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, or if there is
1.123 mike 786: 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 787: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
788: immediately followed by another <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, or if there
1.123 mike 789: 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 790: tag</a> may be omitted if the <code><a href="tabular-data.html#the-td-element">td</a></code> element is
791: 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 792: 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 793: tag</a> may be omitted if the <code><a href="tabular-data.html#the-th-element">th</a></code> element is
794: 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 795: 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.755 mike 796: tag</a> must never be omitted if it has any attributes.</p><h5 id="element-restrictions"><span class="secno">8.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 797: 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 798: elements, even though these elements are technically allowed inside
799: <code><a href="tabular-data.html#the-table-element">table</a></code> elements according to the content models
800: described in this specification. (If a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
801: 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 802: 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
803: placed immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
1.1 mike 804: 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>
805: elements. This does not affect the processing of the element. The
1.304 mike 806: otherwise optional <a href="#syntax-newlines" title="syntax-newlines">newline</a>
1.381 mike 807: <em>must</em> be included if the element's contents themselves start
808: with a <a href="#syntax-newlines" title="syntax-newlines">newline</a> (because
809: otherwise the leading newline in the contents would be treated like
810: the optional newline, and ignored).</p><div class="example">
1.1 mike 811: <p>The following two <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
812: <pre><pre>Hello</pre></pre>
813: <pre><pre><br>Hello</pre></pre>
1.755 mike 814: </div><h5 id="cdata-rcdata-restrictions"><span class="secno">8.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 815: <a href="#rcdata-elements" title="RCDATA elements">RCDATAs</a> element must not
816: contain any occurrences of the string "<code title=""></</code>"
817: (U+003C LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that
1.1 mike 818: case-insensitively match the tag name of the element followed by one
819: of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM
1.304 mike 820: FEED (FF), U+000D CARRIAGE RETURN (CR), U+0020 SPACE, U+003E
1.755 mike 821: GREATER-THAN SIGN (>), or U+002F SOLIDUS (/).</p><h4 id="text"><span class="secno">8.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 822: attributes, and comments. Text must consist of Unicode characters.
823: Text must not contain U+0000 characters. Text must not contain
1.316 mike 824: permanently undefined Unicode characters (noncharacters). Text must
825: not contain control characters other than <a href="infrastructure.html#space-character" title="space
826: character">space characters</a>. Extra constraints are placed on
827: what is and what is not allowed in text based on where the text is
1.755 mike 828: to be put, as described in the other sections.</p><h5 id="newlines"><span class="secno">8.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 829: represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A
830: LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR),
1.755 mike 831: U+000A LINE FEED (LF) characters in that order.</p><h4 id="character-references"><span class="secno">8.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 832: to escape characters that couldn't otherwise legally be included in
1.588 mike 833: <a href="#syntax-text" title="syntax-text">text</a>.</p><p>Character references must start with a U+0026 AMPERSAND character
834: (&). Following this, there are three possible kinds of character
835: references:</p><dl><dt>Named character references</dt>
1.1 mike 836:
837: <dd>The ampersand must be followed by one of the names given in the
838: <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
1.677 mike 839: case. <span class="impl">The name must be one that is terminated by
840: a U+003B SEMICOLON character (;).</span></dd>
1.1 mike 841:
842:
843: <dt>Decimal numeric character reference</dt>
844:
845: <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
1.588 mike 846: character (#), followed by one or more digits in the range U+0030
847: DIGIT ZERO (0) to U+0039 DIGIT NINE (9), representing a base-ten
848: integer that corresponds to a Unicode code point that is allowed
849: according to the definition below. The digits must then be followed
850: by a U+003B SEMICOLON character (;).</dd>
1.1 mike 851:
852:
853: <dt>Hexadecimal numeric character reference</dt>
854:
855: <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
1.588 mike 856: character (#), which must be followed by either a U+0078 LATIN
857: SMALL LETTER X character (x) or a U+0058 LATIN CAPITAL LETTER X
858: character (X), which must then be followed by one or more digits in
859: the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), U+0061
860: LATIN SMALL LETTER A to U+0066 LATIN SMALL LETTER F, and U+0041
861: LATIN CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F,
1.464 mike 862: representing a base-sixteen integer that corresponds to a Unicode
863: code point that is allowed according to the definition below. The
864: digits must then be followed by a U+003B SEMICOLON character
865: (;).</dd>
1.378 mike 866:
867: </dl><p>The numeric character reference forms described above are allowed
868: to reference any Unicode code point other than U+0000, permanently
869: undefined Unicode characters (noncharacters), and control characters
870: other than <a href="infrastructure.html#space-character" title="space character">space
871: characters</a>.</p><p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.464 mike 872: ampersand</dfn> is a U+0026 AMPERSAND character (&) that is
873: followed by some <a href="#syntax-text" title="syntax-text">text</a> other than a
874: <a href="infrastructure.html#space-character">space character</a>, a U+003C LESS-THAN SIGN character
1.755 mike 875: (<), or another U+0026 AMPERSAND character (&).</p><h4 id="cdata-sections"><span class="secno">8.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 876: the character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
877: MARK, U+005B LEFT SQUARE BRACKET, U+0043 LATIN CAPITAL LETTER C,
878: U+0044 LATIN CAPITAL LETTER D, U+0041 LATIN CAPITAL LETTER A, U+0054
879: LATIN CAPITAL LETTER T, U+0041 LATIN CAPITAL LETTER A, U+005B LEFT
880: SQUARE BRACKET (<code title=""><![CDATA[</code>). Following this
881: sequence, the CDATA section may have <a href="#syntax-text" title="syntax-text">text</a>, with the additional restriction
882: that the text must not contain the three character sequence U+005D
883: RIGHT SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E
884: GREATER-THAN SIGN (<code title="">]]></code>). Finally, the CDATA
885: section must be ended by the three character sequence U+005D RIGHT
886: SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E GREATER-THAN
1.724 mike 887: SIGN (<code title="">]]></code>).</p><div class="example">
888:
889: <p>CDATA sections can only be used in foreign content (MathML or
890: SVG). In this example, a CDATA section is used to escape the
891: contents of an <code>ms</code> element:</p>
892:
893: <pre><p>You can add a string to a number, but this stringifies the number:</p>
894: <math>
895: <ms><![CDATA[x<y]]></ms>
896: <mo>+</mo>
897: <mn>3</mn>
898: <mo>=</mo>
899: <ms><![CDATA[x<y3]]></ms>
900: </math></pre>
901:
1.755 mike 902: </div><h4 id="comments"><span class="secno">8.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 903: four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
904: MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title=""><!--</code>). Following this sequence, the comment may
905: have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
906: restriction that the text must not start with a single U+003E
1.588 mike 907: GREATER-THAN SIGN character (>), nor start with a U+002D
908: HYPHEN-MINUS character (-) followed by a U+003E GREATER-THAN SIGN
909: (>) character, nor contain two consecutive U+002D HYPHEN-MINUS
910: characters (<code title="">--</code>), nor end with a U+002D
911: HYPHEN-MINUS character (-). Finally, the comment must be ended by
1.1 mike 912: the three character sequence U+002D HYPHEN-MINUS, U+002D
1.123 mike 913: HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--></code>).</p><div class="impl">
1.1 mike 914:
1.755 mike 915: <h3 id="parsing"><span class="secno">8.2 </span>Parsing HTML documents</h3><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 916:
917: <p><i>This section only applies to user agents, data mining tools,
918: and conformance checkers.</i></p>
919:
920: <p class="note">The rules for parsing XML documents into DOM trees
921: are covered by the next section, entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
922: syntax</a>".</p>
923:
924: <p>For <a href="dom.html#html-documents">HTML documents</a>, user agents must use the parsing
925: rules described in this section to generate the DOM trees. Together,
926: these rules define what is referred to as the <dfn id="html-parser">HTML
927: parser</dfn>.</p>
928:
929: <div class="note">
930:
931: <p>While the HTML syntax described in this specification bears a
932: close resemblance to SGML and XML, it is a separate language with
933: its own parsing rules.</p>
934:
1.183 mike 935: <p>Some earlier versions of HTML (in particular from HTML2 to
936: HTML4) were based on SGML and used SGML parsing rules. However, few
1.1 mike 937: (if any) web browsers ever implemented true SGML parsing for HTML
938: documents; the only user agents to strictly handle HTML as an SGML
939: application have historically been validators. The resulting
940: confusion — with validators claiming documents to have one
941: representation while widely deployed Web browsers interoperably
942: implemented a different representation — has wasted decades
943: of productivity. This version of HTML thus returns to a non-SGML
944: basis.</p>
945:
946: <p>Authors interested in using SGML tools in their authoring
947: pipeline are encouraged to use XML tools and the XML serialization
948: of HTML.</p>
949:
950: </div>
951:
952: <p>This specification defines the parsing rules for HTML documents,
953: whether they are syntactically correct or not. Certain points in the
954: parsing algorithm are said to be <dfn id="parse-error" title="parse error">parse
955: errors</dfn>. The error handling for parse errors is well-defined:
956: user agents must either act as described below when encountering
957: such problems, or must abort processing at the first error that they
958: encounter for which they do not wish to apply the rules described
959: below.</p>
960:
961: <p>Conformance checkers must report at least one parse error
962: condition to the user if one or more parse error conditions exist in
963: the document and must not report parse error conditions if none
964: exist in the document. Conformance checkers may report more than one
1.174 mike 965: parse error condition if more than one parse error condition exists
1.1 mike 966: in the document. Conformance checkers are not required to recover
967: from parse errors.</p>
968:
969: <p class="note">Parse errors are only errors with the
970: <em>syntax</em> of HTML. In addition to checking for parse errors,
971: conformance checkers will also verify that the document obeys all
972: the other conformance requirements described in this
973: specification.</p>
974:
975: <p>For the purposes of conformance checkers, if a resource is
976: determined to be in <a href="#syntax">the HTML syntax</a>, then it is an
977: <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
978:
1.266 mike 979: </div><div class="impl">
1.1 mike 980:
1.755 mike 981: <h4 id="overview-of-the-parsing-model"><span class="secno">8.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 982:
983: <p>The input to the HTML parsing process consists of a stream of
984: Unicode characters, which is passed through a
985: <a href="#tokenization">tokenization</a> stage followed by a <a href="#tree-construction">tree
1.810 mike 986: construction</a> stage. The output is a <code><a href="infrastructure.html#document">Document</a></code>
1.1 mike 987: object.</p>
988:
989: <p class="note">Implementations that <a href="infrastructure.html#non-scripted">do not
990: support scripting</a> do not have to actually create a DOM
1.810 mike 991: <code><a href="infrastructure.html#document">Document</a></code> object, but the DOM tree in such cases is
1.1 mike 992: still used as the model for the rest of the specification.</p>
993:
994: <p>In the common case, the data handled by the tokenization stage
1.159 mike 995: comes from the network, but <a href="embedded-content-0.html#dynamic-markup-insertion" title="dynamic markup
996: 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 997:
1.724 mike 998: <p><img alt="" src="http://dev.w3.org/html5/spec/images/parsing-model-overview.png"></p>
1.1 mike 999:
1000: <p id="nestedParsing">There is only one set of states for the
1001: tokenizer stage and the tree construction stage, but the tree
1002: construction stage is reentrant, meaning that while the tree
1003: construction stage is handling one token, the tokenizer might be
1004: resumed, causing further tokens to be emitted and processed before
1005: the first token's processing is complete.</p>
1006:
1007: <div class="example">
1008:
1009: <p>In the following example, the tree construction stage will be
1010: called upon to handle a "p" start tag token while handling the
1011: "script" start tag token:</p>
1012:
1013: <pre>...
1014: <script>
1015: document.write('<p>');
1016: </script>
1017: ...</pre>
1018:
1019: </div>
1020:
1021: <p>To handle these cases, parsers have a <dfn id="script-nesting-level">script nesting
1022: level</dfn>, which must be initially set to zero, and a <dfn id="parser-pause-flag">parser
1023: pause flag</dfn>, which must be initially set to false.</p>
1024:
1.266 mike 1025: </div><div class="impl">
1.1 mike 1026:
1.755 mike 1027: <h4 id="the-input-stream"><span class="secno">8.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 1028:
1029: <p>The stream of Unicode characters that comprises the input to the
1030: tokenization stage will be initially seen by the user agent as a
1031: stream of bytes (typically coming over the network or from the local
1032: file system). The bytes encode the actual characters according to a
1033: particular <em>character encoding</em>, which the user agent must
1034: use to decode the bytes into characters.</p>
1035:
1036: <p class="note">For XML documents, the algorithm user agents must
1037: use to determine the character encoding is given by the XML
1.104 mike 1038: specification. This section does not apply to XML documents. <a href="references.html#refsXML">[XML]</a></p>
1.1 mike 1039:
1040:
1.755 mike 1041: <h5 id="determining-the-character-encoding"><span class="secno">8.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 1042:
1043: <p>In some cases, it might be impractical to unambiguously determine
1044: the encoding before parsing the document. Because of this, this
1045: specification provides for a two-pass mechanism with an optional
1046: pre-scan. Implementations are allowed, as described below, to apply
1047: a simplified parsing algorithm to whatever bytes they have available
1048: before beginning to parse the document. Then, the real parser is
1049: started, using a tentative encoding derived from this pre-parse and
1050: other out-of-band metadata. If, while the document is being loaded,
1051: the user agent discovers an encoding declaration that conflicts with
1052: this information, then the parser can get reinvoked to perform a
1053: parse of the document with the real encoding.</p>
1054:
1055: <p id="documentEncoding">User agents must use the following
1056: algorithm (the <dfn id="encoding-sniffing-algorithm">encoding sniffing algorithm</dfn>) to determine
1057: the character encoding to use when decoding a document in the first
1058: pass. This algorithm takes as input any out-of-band metadata
1059: available to the user agent (e.g. the <a href="infrastructure.html#content-type" title="Content-Type">Content-Type metadata</a> of the document)
1060: and all the bytes available so far, and returns an encoding and a
1061: <dfn id="concept-encoding-confidence" title="concept-encoding-confidence">confidence</dfn>. The
1062: confidence is either <i>tentative</i>, <i>certain</i>, or
1063: <i>irrelevant</i>. The encoding used, and whether the confidence in
1064: that encoding is <i>tentative</i> or <i>certain</i>, is <a href="#meta-charset-during-parse">used during the parsing</a> to
1065: determine whether to <a href="#change-the-encoding">change the encoding</a>. If no
1066: encoding is necessary, e.g. because the parser is operating on a
1067: stream of Unicode characters and doesn't have to use an encoding at
1068: all, then the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
1069: <i>irrelevant</i>.</p>
1070:
1071: <ol><li><p>If the transport layer specifies an encoding, and it is
1072: supported, return that encoding with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1073: <i>certain</i>, and abort these steps.</p></li>
1074:
1075: <li><p>The user agent may wait for more bytes of the resource to be
1076: available, either in this step or at any later step in this
1077: algorithm. For instance, a user agent might wait 500ms or 512
1078: bytes, whichever came first. In general preparsing the source to
1079: find the encoding improves performance, as it reduces the need to
1080: throw away the data structures used when parsing upon finding the
1081: encoding information. However, if the user agent delays too long to
1082: obtain data to determine the encoding, then the cost of the delay
1083: could outweigh any performance improvements from the
1084: preparse.</p></li>
1085:
1086: <li><p>For each of the rows in the following table, starting with
1087: the first one and going down, if there are as many or more bytes
1088: available than the number of bytes in the first column, and the
1089: first bytes of the file match the bytes given in the first column,
1090: then return the encoding given in the cell in the second column of
1091: that row, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1092: <i>certain</i>, and abort these steps:</p>
1093:
1094: <!-- this table is present in several forms in this file; keep them in sync -->
1095: <table><thead><tr><th>Bytes in Hexadecimal
1096: </th><th>Encoding
1097: </th></tr></thead><tbody><!-- nobody uses this
1098: <tr>
1099: <td>00 00 FE FF
1100: <td>UTF-32BE
1101: <tr>
1102: <td>FF FE 00 00
1103: <td>UTF-32LE
1104: --><tr><td>FE FF
1105: </td><td>UTF-16BE
1106: </td></tr><tr><td>FF FE
1107: </td><td>UTF-16LE
1108: </td></tr><tr><td>EF BB BF
1109: </td><td>UTF-8
1110: <!-- nobody uses this
1111: <tr>
1112: <td>DD 73 66 73
1113: <td>UTF-EBCDIC
1114: -->
1115: </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
1116: (BOMs).</p></li>
1117:
1118: <li><p>Otherwise, the user agent will have to search for explicit
1119: character encoding information in the file itself. This should
1120: proceed as follows:
1121:
1122: </p><p>Let <var title="">position</var> be a pointer to a byte in the
1123: input stream, initially pointing at the first byte. If at any
1124: point during these substeps the user agent either runs out of
1125: bytes or decides that scanning further bytes would not be
1126: efficient, then skip to the next step of the overall character
1127: encoding detection algorithm. User agents may decide that scanning
1128: <em>any</em> bytes is not efficient, in which case these substeps
1129: are entirely skipped.</p>
1130:
1131: <p>Now, repeat the following "two" steps until the algorithm
1132: aborts (either because user agent aborts, as described above, or
1133: because a character encoding is found):</p>
1134:
1135: <ol><li><p>If <var title="">position</var> points to:</p>
1136:
1137: <dl class="switch"><dt>A sequence of bytes starting with: 0x3C 0x21 0x2D 0x2D (ASCII '<!--')</dt>
1138: <dd>
1139:
1140: <p>Advance the <var title="">position</var> pointer so that it
1141: points at the first 0x3E byte which is preceded by two 0x2D
1142: bytes (i.e. at the end of an ASCII '-->' sequence) and comes
1143: after the 0x3C byte that was found. (The two 0x2D bytes can be
1144: the same as the those in the '<!--' sequence.)</p>
1145:
1146: </dd>
1147:
1148: <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>
1149: <dd>
1150:
1151: <ol><li><p>Advance the <var title="">position</var> pointer so
1152: that it points at the next 0x09, 0x0A, 0x0C, 0x0D, 0x20, or
1153: 0x2F byte (the one in sequence of characters matched
1154: above).</p></li>
1155:
1156: <li><p><a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">Get
1157: an attribute</a> and its value. If no attribute was
1158: sniffed, then skip this inner set of steps, and jump to the
1159: second step in the overall "two step" algorithm.</p></li>
1160:
1161: <li><p>If the attribute's name is neither "<code title="">charset</code>" nor "<code title="">content</code>",
1162: then return to step 2 in these inner steps.</p></li>
1163:
1164: <li><p>If the attribute's name is "<code title="">charset</code>", let <var title="">charset</var> be
1165: the attribute's value, interpreted as a character
1166: encoding.</p></li>
1167:
1168: <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
1169: extracting an encoding from a Content-Type</a>, giving the
1170: attribute's value as the string to parse. If an encoding is
1171: returned, let <var title="">charset</var> be that
1172: encoding. Otherwise, return to step 2 in these inner
1173: steps.</p></li>
1174:
1175: <li><p>If <var title="">charset</var> is a UTF-16 encoding,
1176: change the value of <var title="">charset</var> to
1177: UTF-8.</p></li>
1178:
1179: <li><p>If <var title="">charset</var> is a supported
1180: character encoding, then return the given encoding, with
1181: <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1182: <i>tentative</i>, and abort all these steps.</p></li>
1183:
1184: <li><p>Otherwise, return to step 2 in these inner
1185: steps.</p></li>
1186:
1187: </ol></dd>
1188:
1.464 mike 1189: <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 1190: <dd>
1191:
1192: <ol><li><p>Advance the <var title="">position</var> pointer so
1193: that it points at the next 0x09 (ASCII TAB), 0x0A (ASCII LF),
1194: 0x0C (ASCII FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E
1.464 mike 1195: (ASCII >) byte.</p></li>
1.1 mike 1196:
1197: <li><p>Repeatedly <a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
1198: attribute</a> until no further attributes can be found,
1199: then jump to the second step in the overall "two step"
1200: algorithm.</p></li>
1201:
1202: </ol></dd>
1203:
1204: <dt>A sequence of bytes starting with: 0x3C 0x21 (ASCII '<!')</dt>
1205: <dt>A sequence of bytes starting with: 0x3C 0x2F (ASCII '</')</dt>
1206: <dt>A sequence of bytes starting with: 0x3C 0x3F (ASCII '<?')</dt>
1207: <dd>
1208:
1209: <p>Advance the <var title="">position</var> pointer so that it
1.464 mike 1210: points at the first 0x3E byte (ASCII >) that comes after the
1.1 mike 1211: 0x3C byte that was found.</p>
1212:
1213: </dd>
1214:
1215: <dt>Any other byte</dt>
1216: <dd>
1217:
1218: <p>Do nothing with that byte.</p>
1219:
1220: </dd>
1221:
1222: </dl></li>
1223:
1224: <li>Move <var title="">position</var> so it points at the next
1225: byte in the input stream, and return to the first step of this
1226: "two step" algorithm.</li>
1227:
1228: </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
1229: attribute</dfn>, it means doing this:</p>
1230:
1231: <ol><li><p>If the byte at <var title="">position</var> is one of 0x09
1232: (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII FF), 0x0D (ASCII CR),
1.464 mike 1233: 0x20 (ASCII space), or 0x2F (ASCII /) then advance <var title="">position</var> to the next byte and redo this
1.1 mike 1234: substep.</p></li>
1235:
1236: <li><p>If the byte at <var title="">position</var> is 0x3E (ASCII
1.464 mike 1237: >), then abort the "get an attribute" algorithm. There isn't
1.1 mike 1238: one.</p></li>
1239:
1240: <li><p>Otherwise, the byte at <var title="">position</var> is the
1241: start of the attribute name. Let <var title="">attribute
1242: name</var> and <var title="">attribute value</var> be the empty
1243: string.</p></li>
1244:
1245: <li><p><i>Attribute name</i>: Process the byte at <var title="">position</var> as follows:</p>
1246:
1.464 mike 1247: <dl class="switch"><dt>If it is 0x3D (ASCII =), and the <var title="">attribute
1.1 mike 1248: name</var> is longer than the empty string</dt>
1249:
1250: <dd>Advance <var title="">position</var> to the next byte and
1251: jump to the step below labeled <i>value</i>.</dd>
1252:
1253: <dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
1254: FF), 0x0D (ASCII CR), or 0x20 (ASCII space)</dt>
1255:
1256: <dd>Jump to the step below labeled <i>spaces</i>.</dd>
1257:
1.464 mike 1258: <dt>If it is 0x2F (ASCII /) or 0x3E (ASCII >)</dt>
1.1 mike 1259:
1260: <dd>Abort the "get an attribute" algorithm. The attribute's
1261: name is the value of <var title="">attribute name</var>, its
1262: value is the empty string.</dd>
1263:
1.464 mike 1264: <dt>If it is in the range 0x41 (ASCII A) to 0x5A (ASCII
1265: Z)</dt>
1.1 mike 1266:
1267: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1268: name</var> (where <var title="">b</var> is the value of the
1269: byte at <var title="">position</var>).</dd>
1270:
1271: <dt>Anything else</dt>
1272:
1273: <dd>Append the Unicode character with the same code point as the
1274: value of the byte at <var title="">position</var>) to <var title="">attribute name</var>. (It doesn't actually matter how
1275: bytes outside the ASCII range are handled here, since only
1276: ASCII characters can contribute to the detection of a character
1277: encoding.)</dd>
1278:
1279: </dl></li>
1280:
1281: <li><p>Advance <var title="">position</var> to the next byte and
1282: return to the previous step.</p></li>
1283:
1284: <li><p><i>Spaces</i>: If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
1285: LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
1286: advance <var title="">position</var> to the next byte, then,
1287: repeat this step.</p></li>
1288:
1289: <li><p>If the byte at <var title="">position</var> is
1.464 mike 1290: <em>not</em> 0x3D (ASCII =), abort the "get an attribute"
1.1 mike 1291: algorithm. The attribute's name is the value of <var title="">attribute name</var>, its value is the empty
1292: string.</p></li>
1293:
1294: <li><p>Advance <var title="">position</var> past the 0x3D (ASCII
1.464 mike 1295: =) byte.</p></li>
1.1 mike 1296:
1297: <li><p><i>Value:</i> If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
1298: LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
1299: advance <var title="">position</var> to the next byte, then,
1300: repeat this step.</p></li>
1301:
1302: <li><p>Process the byte at <var title="">position</var> as
1303: follows:</p>
1304:
1.464 mike 1305: <dl class="switch"><dt>If it is 0x22 (ASCII ") or 0x27 (ASCII ')</dt>
1.1 mike 1306:
1307: <dd>
1308:
1309: <ol><li>Let <var title="">b</var> be the value of the byte at
1310: <var title="">position</var>.</li>
1311:
1312: <li>Advance <var title="">position</var> to the next
1313: byte.</li>
1314:
1315: <li>If the value of the byte at <var title="">position</var>
1316: is the value of <var title="">b</var>, then advance <var title="">position</var> to the next byte and abort the "get
1317: an attribute" algorithm. The attribute's name is the value of
1318: <var title="">attribute name</var>, and its value is the
1319: value of <var title="">attribute value</var>.</li>
1320:
1.464 mike 1321: <li>Otherwise, if the value of the byte at <var title="">position</var> is in the range 0x41 (ASCII A) to
1322: 0x5A (ASCII Z), then append a Unicode character to <var title="">attribute value</var> whose code point is 0x20 more
1.1 mike 1323: than the value of the byte at <var title="">position</var>.</li>
1324:
1325: <li>Otherwise, append a Unicode character to <var title="">attribute value</var> whose code point is the same as
1326: the value of the byte at <var title="">position</var>.</li>
1327:
1328: <li>Return to the second step in these substeps.</li>
1329:
1330: </ol></dd>
1331:
1.464 mike 1332: <dt>If it is 0x3E (ASCII >)</dt>
1.1 mike 1333:
1334: <dd>Abort the "get an attribute" algorithm. The attribute's
1335: name is the value of <var title="">attribute name</var>, its
1336: value is the empty string.</dd>
1337:
1338:
1.464 mike 1339: <dt>If it is in the range 0x41 (ASCII A) to 0x5A (ASCII
1340: Z)</dt>
1.1 mike 1341:
1342: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1343: value</var> (where <var title="">b</var> is the value of the
1344: byte at <var title="">position</var>). Advance <var title="">position</var> to the next byte.</dd>
1345:
1346: <dt>Anything else</dt>
1347:
1348: <dd>Append the Unicode character with the same code point as the
1349: 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>
1350:
1351: </dl></li>
1352:
1353: <li><p>Process the byte at <var title="">position</var> as
1354: follows:</p>
1355:
1356: <dl class="switch"><dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
1357: FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E (ASCII
1.464 mike 1358: >)</dt>
1.1 mike 1359:
1360: <dd>Abort the "get an attribute" algorithm. The attribute's
1361: name is the value of <var title="">attribute name</var> and its
1362: value is the value of <var title="">attribute value</var>.</dd>
1363:
1.464 mike 1364: <dt>If it is in the range 0x41 (ASCII A) to 0x5A (ASCII
1365: Z)</dt>
1.1 mike 1366:
1367: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1368: value</var> (where <var title="">b</var> is the value of the
1369: byte at <var title="">position</var>).</dd>
1370:
1371: <dt>Anything else</dt>
1372:
1373: <dd>Append the Unicode character with the same code point as the
1374: value of the byte at <var title="">position</var>) to <var title="">attribute value</var>.</dd>
1375:
1376: </dl></li>
1377:
1378: <li><p>Advance <var title="">position</var> to the next byte and
1379: return to the previous step.</p></li>
1380:
1381: </ol><p>For the sake of interoperability, user agents should not use a
1382: pre-scan algorithm that returns different results than the one
1383: described above. (But, if you do, please at least let us know, so
1384: that we can improve this algorithm and benefit everyone...)</p>
1385:
1386: </li>
1387:
1388: <li><p>If the user agent has information on the likely encoding for
1389: this page, e.g. based on the encoding of the page when it was last
1390: visited, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1391: <i>tentative</i>, and abort these steps.</p></li>
1392:
1.322 mike 1393: <li>
1394:
1395: <p>The user agent may attempt to autodetect the character encoding
1396: from applying frequency analysis or other algorithms to the data
1.568 mike 1397: stream. Such algorithms may use information about the resource
1398: other than the resource's contents, including the address of the
1399: resource. If autodetection succeeds in determining a character
1.322 mike 1400: encoding, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1401: <i>tentative</i>, and abort these steps. <a href="references.html#refsUNIVCHARDET">[UNIVCHARDET]</a></p>
1402:
1403: <p class="note">The UTF-8 encoding has a highly detectable bit
1404: pattern. Documents that contain bytes with values greater than
1405: 0x7F which match the UTF-8 pattern are very likely to be UTF-8,
1406: while documents with byte sequences that do not match it are very
1407: likely not. User-agents are therefore encouraged to search for
1.485 mike 1408: this common encoding. <a href="references.html#refsPPUTF8">[PPUTF8]</a> <a href="references.html#refsUTF8DET">[UTF8DET]</a></p>
1.322 mike 1409:
1410: </li>
1.1 mike 1411:
1.501 mike 1412: <li>
1413:
1414: <p>Otherwise, return an implementation-defined or user-specified
1415: default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1416: <i>tentative</i>.</p>
1417:
1418: <p>In controlled environments or in environments where the
1419: encoding of documents can be prescribed (for example, for user
1420: agents intended for dedicated use in new networks), the
1421: comprehensive <code title="">UTF-8</code> encoding is
1422: suggested.</p>
1423:
1424: <p>In other environments, the default encoding is typically
1425: dependent on the user's locale (an approximation of the languages,
1.760 mike 1426: and thus often encodings, of the pages that the user is likely to
1427: frequent). The following table gives suggested defaults based on
1428: the user's locale, for compatibility with legacy content. Locales
1429: are identified by BCP 47 language codes. <a href="references.html#refsBCP47">[BCP47]</a></p>
1.501 mike 1430:
1431: <!-- based on mozilla 1.9.1 localizations:
1432: http://mxr.mozilla.org/l10n-mozilla1.9.1/find?string=global%2Fintl.properties&tree=l10n-mozilla1.9.1&hint= -->
1433:
1.504 mike 1434: <table><thead><tr><th>Locale language
1.501 mike 1435: </th><th>Suggested default encoding
1436: </th></tr></thead><tbody><tr><td>ar
1437: </td><td>UTF-8
1438:
1439: </td></tr><tr><td>be
1440: </td><td>ISO-8859-5
1441:
1442: </td></tr><tr><td>bg
1443: </td><td>windows-1251
1444:
1445: </td></tr><tr><td>cs<!-- -CZ -->
1446: </td><td>ISO-8859-2
1447:
1448: </td></tr><tr><td>cy
1449: </td><td>UTF-8
1450:
1451: </td></tr><tr><td>fa<!-- -IR -->
1452: </td><td>UTF-8
1453:
1454: </td></tr><tr><td>he<!-- -IL -->
1455: </td><td>windows-1255
1456:
1457: </td></tr><tr><td>hr
1458: </td><td>UTF-8
1459:
1460: </td></tr><tr><td>hu<!-- -HU -->
1461: </td><td>ISO-8859-2
1462:
1463: </td></tr><tr><td>ja <!-- and ja-JP-mac -->
1464: </td><td>windows-31J <!-- Shift_JIS -->
1465:
1466: </td></tr><tr><td>kk
1467: </td><td>UTF-8
1468:
1469: </td></tr><tr><td>ko<!-- -KR -->
1470: </td><td>windows-949 <!-- EUC-KR -->
1471:
1472: </td></tr><tr><td>ku
1473: </td><td>windows-1254 <!-- ISO-8859-9 -->
1474:
1475: </td></tr><tr><td>lt
1476: </td><td>windows-1257
1477:
1478: </td></tr><tr><td>lv<!-- -LV -->
1479: </td><td>ISO-8859-13
1480:
1481: </td></tr><tr><td>mk<!-- -MK -->
1482: </td><td>UTF-8
1483:
1484: </td></tr><tr><td>or
1485: </td><td>UTF-8
1486:
1487: </td></tr><tr><td>pl<!-- -PL -->
1488: </td><td>ISO-8859-2
1489:
1490: </td></tr><tr><td>ro
1491: </td><td>UTF-8
1492:
1493: </td></tr><tr><td>ru
1494: </td><td>windows-1251
1495:
1496: </td></tr><tr><td>sk
1497: </td><td>windows-1250
1498:
1499: </td></tr><tr><td>sl
1500: </td><td>ISO-8859-2
1501:
1502: </td></tr><tr><td>sr
1503: </td><td>UTF-8
1504:
1505: </td></tr><tr><td>th
1506: </td><td>windows-874 <!-- TIS-620 -->
1507:
1508: </td></tr><tr><td>tr<!-- -TR -->
1509: </td><td>windows-1254 <!-- ISO-8859-9 -->
1510:
1.503 mike 1511: </td></tr><tr><td>uk
1.501 mike 1512: </td><td>windows-1251
1513:
1514: </td></tr><tr><td>vi
1515: </td><td>UTF-8
1516:
1517: </td></tr><tr><td>zh-CN
1518: </td><td>GB18030
1519:
1520: </td></tr><tr><td>zh-TW
1521: </td><td>Big5
1522:
1523: </td></tr><tr><td>All other locales
1524: </td><td>windows-1252
1525:
1526: </td></tr></tbody></table></li>
1.1 mike 1527:
1528: </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
1529: be set to the value returned from this algorithm, at the same time
1530: as the user agent uses the returned value to select the decoder to
1531: use for the input stream.</p>
1532:
1.582 mike 1533: <p class="note">This algorithm is a <a href="introduction.html#willful-violation">willful violation</a>
1534: of the HTTP specification, which requires that the encoding be
1535: assumed to be ISO-8859-1 in the absence of a <a href="semantics.html#character-encoding-declaration">character
1.647 mike 1536: encoding declaration</a> to the contrary, and of RFC 2046,
1.582 mike 1537: which requires that the encoding be assumed to be US-ASCII in the
1538: absence of a <a href="semantics.html#character-encoding-declaration">character encoding declaration</a> to the
1539: contrary. This specification's third approach is motivated by a
1540: desire to be maximally compatible with legacy content. <a href="references.html#refsHTTP">[HTTP]</a> <a href="references.html#refsRFC2046">[RFC2046]</a></p>
1541:
1.1 mike 1542:
1.755 mike 1543: <h5 id="character-encodings-0"><span class="secno">8.2.2.2 </span>Character encodings</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 1544:
1.237 mike 1545: <p>User agents must at a minimum support the UTF-8 and Windows-1252
1546: encodings, but may support more.</p>
1547:
1548: <p class="note">It is not unusual for Web browsers to support dozens
1549: if not upwards of a hundred distinct character encodings.</p>
1550:
1.365 mike 1551: <p>User agents must support the <a href="infrastructure.html#preferred-mime-name">preferred MIME name</a> of
1552: every character encoding they support, and should support all the
1553: IANA-registered names and aliases of every character encoding they
1554: support. <a href="references.html#refsIANACHARSET">[IANACHARSET]</a></p>
1.237 mike 1555:
1556: <p>When comparing a string specifying a character encoding with the
1557: name or alias of a character encoding to determine if they are
1558: 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
1559: then perform the comparison in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1560: case-insensitive</a> manner.</p>
1561:
1.539 mike 1562: <hr><p>When a user agent would otherwise use an encoding given in the
1.237 mike 1563: first column of the following table to either convert content to
1564: Unicode characters or convert Unicode characters to bytes, it must
1565: instead use the encoding given in the cell in the second column of
1566: the same row. When a byte or sequence of bytes is treated
1567: differently due to this encoding aliasing, it is said to have been
1568: <dfn id="misinterpreted-for-compatibility">misinterpreted for compatibility</dfn>.</p>
1569:
1570: <table><caption>Character encoding overrides</caption>
1571: <thead><tr><th> Input encoding </th><th> Replacement encoding </th><th> References
1572: </th></tr></thead><tbody><!-- how about EUC-JP? --><tr><td> EUC-KR </td><td> windows-949 </td><td>
1573: <a href="references.html#refsEUCKR">[EUCKR]</a>
1574: <a href="references.html#refsWIN949">[WIN949]</a>
1575: </td></tr><tr><td> GB2312 </td><td> GBK </td><td>
1576: <a href="references.html#refsRFC1345">[RFC1345]</a>
1577: <a href="references.html#refsGBK">[GBK]</a>
1578: </td></tr><tr><td> GB_2312-80 </td><td> GBK </td><td>
1579: <a href="references.html#refsRFC1345">[RFC1345]</a>
1580: <a href="references.html#refsGBK">[GBK]</a>
1581: </td></tr><tr><td> ISO-8859-1 </td><td> windows-1252 </td><td>
1582: <a href="references.html#refsRFC1345">[RFC1345]</a>
1583: <a href="references.html#refsWIN1252">[WIN1252]</a>
1584: </td></tr><tr><td> ISO-8859-9 </td><td> windows-1254 </td><td>
1585: <a href="references.html#refsRFC1345">[RFC1345]</a>
1586: <a href="references.html#refsWIN1254">[WIN1254]</a>
1587: </td></tr><tr><td> ISO-8859-11 </td><td> windows-874 </td><td>
1588: <a href="references.html#refsISO885911">[ISO885911]</a>
1589: <a href="references.html#refsWIN874">[WIN874]</a>
1590: </td></tr><tr><td> KS_C_5601-1987 </td><td> windows-949 </td><td>
1591: <a href="references.html#refsRFC1345">[RFC1345]</a>
1592: <a href="references.html#refsWIN949">[WIN949]</a>
1593: </td></tr><tr><td> Shift_JIS </td><td> windows-31J </td><td>
1594: <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
1595: <a href="references.html#refsWIN31J">[WIN31J]</a>
1596: </td></tr><tr><td> TIS-620 </td><td> windows-874 </td><td>
1597: <a href="references.html#refsTIS620">[TIS620]</a>
1598: <a href="references.html#refsWIN874">[WIN874]</a>
1599: </td></tr><tr><td> US-ASCII </td><td> windows-1252 </td><td>
1600: <a href="references.html#refsRFC1345">[RFC1345]</a>
1601: <a href="references.html#refsWIN1252">[WIN1252]</a>
1602: </td></tr></tbody></table><p class="note">The requirement to treat certain encodings as other
1603: encodings according to the table above is a <a href="introduction.html#willful-violation">willful
1604: violation</a> of the W3C Character Model specification, motivated
1605: by a desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
1606:
1607: <p>When a user agent is to use the UTF-16 encoding but no BOM has
1608: been found, user agents must default to UTF-16LE.</p>
1609:
1610: <p class="note">The requirement to default UTF-16 to LE rather than
1611: BE is a <a href="introduction.html#willful-violation">willful violation</a> of RFC 2781, motivated by a
1.581 mike 1612: desire for compatibility with legacy content. <a href="references.html#refsRFC2781">[RFC2781]</a></p>
1.237 mike 1613:
1614: <hr><p>User agents must not support the CESU-8, UTF-7, BOCU-1 and SCSU
1615: 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>
1616:
1617: <p>Support for encodings based on EBCDIC is not recommended. This
1618: encoding is rarely used for publicly-facing Web content.</p>
1619:
1620: <p>Support for UTF-32 is not recommended. This encoding is rarely
1621: used, and frequently implemented incorrectly.</p>
1622:
1623: <p class="note">This specification does not make any attempt to
1624: support EBCDIC-based encodings and UTF-32 in its algorithms; support
1625: and use of these encodings can thus lead to unexpected behavior in
1626: implementations of this specification.</p>
1627:
1628:
1629:
1.755 mike 1630: <h5 id="preprocessing-the-input-stream"><span class="secno">8.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 1631:
1632: <p>Given an encoding, the bytes in the input stream must be
1633: converted to Unicode characters for the tokenizer, as described by
1634: the rules for that encoding, except that the leading U+FEFF BYTE
1635: ORDER MARK character, if any, must not be stripped by the encoding
1636: layer (it is stripped by the rule below).</p> <!-- this is to
1637: prevent two leading BOMs from being both stripped, once by the
1638: decoder, and once by the parser -->
1639:
1640: <p>Bytes or sequences of bytes in the original byte stream that
1.393 mike 1641: could not be converted to Unicode code points must be converted to
1642: U+FFFD REPLACEMENT CHARACTERs.</p>
1.1 mike 1643:
1644: <p class="note">Bytes or sequences of bytes in the original byte
1645: stream that did not conform to the encoding specification
1646: (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
1647: errors that conformance checkers are expected to report.</p>
1648:
1.438 mike 1649: <p>Any byte or sequence of bytes in the original byte stream that is
1650: <a href="#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
1.1 mike 1651: error</a>.</p>
1652:
1653: <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
1654: any are present.</p>
1655:
1.300 mike 1656: <p class="note">The requirement to strip a U+FEFF BYTE ORDER MARK
1657: character regardless of whether that character was used to determine
1658: the byte order is a <a href="introduction.html#willful-violation">willful violation</a> of Unicode,
1659: motivated by a desire to increase the resilience of user agents in
1660: the face of naïve transcoders.</p>
1661:
1.316 mike 1662: <p>All U+0000 NULL characters and code points in the range U+D800 to
1.315 mike 1663: U+DFFF<!-- surrogates not allowed e.g. in UTF-8, and we don't want
1664: them to suddenly turn into codepoints when they go through a UTF-16
1665: pipe --> in the input must be replaced by U+FFFD REPLACEMENT
1.316 mike 1666: CHARACTERs. Any occurrences of such characters and code points are
1667: <a href="#parse-error" title="parse error">parse errors</a>.</p>
1.1 mike 1668:
1669: <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
1670: <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
1671: CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
1.315 mike 1672: <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+FDD0
1673: to U+FDEF, and characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF,
1674: U+2FFFE, U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE,
1675: U+5FFFF, U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF,
1676: U+9FFFE, U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE,
1677: U+CFFFF, U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF,
1678: U+10FFFE, and U+10FFFF are <a href="#parse-error" title="parse error">parse
1.316 mike 1679: errors</a>. These are all control characters or permanently
1680: undefined Unicode characters (noncharacters).</p>
1.1 mike 1681:
1682: <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
1683: characters are treated specially. Any CR characters that are
1684: followed by LF characters must be removed, and any CR characters not
1685: followed by LF characters must be converted to LF characters. Thus,
1686: newlines in HTML DOMs are represented by LF characters, and there
1687: are never any CR characters in the input to the
1688: <a href="#tokenization">tokenization</a> stage.</p>
1689:
1690: <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
1691: input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
1692: the <i><a href="#next-input-character">next input character</a></i> is the first character in the
1693: input. The <dfn id="current-input-character">current input character</dfn> is the last character
1694: to have been <i><a href="#consumed">consumed</a></i>.</p>
1695:
1696: <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
1697: character or just before the end of the input stream) where content
1.159 mike 1698: 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 1699: inserted. The insertion point is relative to the position of the
1700: character immediately after it, it is not an absolute offset into
1701: the input stream. Initially, the insertion point is
1.10 mike 1702: undefined.</p>
1.1 mike 1703:
1704: <p>The "EOF" character in the tables below is a conceptual character
1705: representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
1.159 mike 1706: is a <a href="embedded-content-0.html#script-created-parser">script-created parser</a>, then the end of the
1.1 mike 1707: <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
1.159 mike 1708: 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 1709: consumed. Otherwise, the "EOF" character is not a real character in
1710: the stream, but rather the lack of any further characters.</p>
1711:
1712:
1.755 mike 1713: <h5 id="changing-the-encoding-while-parsing"><span class="secno">8.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 1714:
1715: <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
1716: encoding</dfn>, it must run the following steps. This might happen
1717: if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
1718: failed to find an encoding, or if it found an encoding that was not
1719: the actual encoding of the file.</p>
1720:
1721: <ol><li>If the new encoding is identical or equivalent to the encoding
1722: that is already being used to interpret the input stream, then set
1723: the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1724: <i>certain</i> and abort these steps. This happens when the
1725: encoding information found in the file matches what the
1726: <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
1727: encoding, and in the second pass through the parser if the first
1728: pass found that the encoding sniffing algorithm described in the
1729: earlier section failed to find the right encoding.</li>
1730:
1731: <li>If the encoding that is already being used to interpret the
1732: input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1733: <i>certain</i> and abort these steps. The new encoding is ignored;
1734: if it was anything but the same encoding, then it would be clearly
1735: incorrect.</li>
1736:
1737: <li>If the new encoding is a UTF-16 encoding, change it to
1738: UTF-8.</li>
1739:
1740: <li>If all the bytes up to the last byte converted by the current
1741: decoder have the same Unicode interpretations in both the current
1742: encoding and the new encoding, and if the user agent supports
1743: changing the converter on the fly, then the user agent may change
1744: to the new converter for the encoding on the fly. Set the
1745: <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
1746: convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1747: <i>certain</i>, and abort these steps.</li>
1748:
1749: <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
1750: <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
1751: browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
1752: sniffing algorithm</a> and instead just set the encoding to the
1753: new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1754: <i>certain</i>. Whenever possible, this should be done without
1755: actually contacting the network layer (the bytes should be
1756: re-parsed from memory), even if, e.g., the document is marked as
1757: not being cacheable. If this is not possible and contacting the
1758: network layer would involve repeating a request that uses a method
1759: other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
1760: equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1761: <i>certain</i> and ignore the new encoding. The resource will be
1762: misinterpreted. User agents may notify the user of the situation,
1763: to aid in application development.</li>
1764:
1.266 mike 1765: </ol></div><div class="impl">
1766:
1.755 mike 1767: <h4 id="parse-state"><span class="secno">8.2.3 </span>Parse state</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 1768:
1.755 mike 1769: <h5 id="the-insertion-mode"><span class="secno">8.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 1770:
1771: <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
1772: the primary operation of the tree construction stage.</p>
1773:
1774: <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
1775: "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
1776: "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
1777: "<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 1778: "<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 1779: "<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>",
1780: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
1781: "<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
1782: table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
1783: foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
1784: body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
1785: frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
1786: frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
1787: after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
1788: frameset</a>" during the course of the parsing, as described in
1789: the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
1790: how tokens are processed and whether CDATA sections are
1791: supported.</p>
1792:
1793: <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
1794: head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
1795: body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
1796: table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
1797: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
1798: "<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
1799: that the other modes defer to them at various times. When the
1800: algorithm below says that the user agent is to do something
1801: "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
1802: mode", where <var title="">m</var> is one of these modes, the user
1803: agent must use the rules described under the <var title="">m</var>
1804: <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
1805: <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>
1806: to a new value.</p>
1807:
1808: <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.540 mike 1809: mode: text">text</a>" or "<a href="#parsing-main-intabletext" title="insertion mode: in table
1810: text">in table text</a>", the <dfn id="original-insertion-mode">original insertion mode</dfn>
1811: is also set. This is the insertion mode to which the tree
1812: construction stage will return.</p>
1.1 mike 1813:
1814: <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
1815: mode: in foreign content">in foreign content</a>", the
1816: <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
1817: is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
1818: foreign content">in foreign content</a>" mode to handle HTML
1819: (i.e. not foreign) content.</p>
1820:
1821: <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
1822: mode appropriately</dfn>, it means the UA must follow these
1823: steps:</p>
1824:
1825: <ol><li>Let <var title="">last</var> be false.</li>
1826:
1.604 mike 1827: <li>Let <var title="">foreign</var> be false.</li>
1828:
1.1 mike 1829: <li>Let <var title="">node</var> be the last node in the
1830: <a href="#stack-of-open-elements">stack of open elements</a>.</li>
1831:
1.604 mike 1832: <li><i>Loop</i>: If <var title="">node</var> is the first node in
1833: the stack of open elements, then set <var title="">last</var> to
1834: 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 1835:
1836: <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
1.604 mike 1837: 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
1838: step marked <i title="">end</i>. (<a href="#fragment-case">fragment case</a>)</li>
1.1 mike 1839:
1840: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
1841: <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
1842: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
1.604 mike 1843: mode: in cell">in cell</a>" and jump to the step marked <i title="">end</i>.</li>
1.1 mike 1844:
1845: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
1846: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
1.604 mike 1847: mode: in row">in row</a>" and jump to the step marked <i title="">end</i>.</li>
1.1 mike 1848:
1849: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
1850: <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
1851: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
1.604 mike 1852: table body">in table body</a>" and jump to the step marked <i title="">end</i>.</li>
1.1 mike 1853:
1854: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
1.604 mike 1855: 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
1856: the step marked <i title="">end</i>.</li>
1.1 mike 1857:
1858: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
1859: 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 1860: jump to the step marked <i title="">end</i>. (<a href="#fragment-case">fragment
1861: case</a>)</li>
1.1 mike 1862:
1863: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
1.604 mike 1864: 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
1865: step marked <i title="">end</i>.</li>
1.1 mike 1866:
1.159 mike 1867: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element-0">head</a></code> element,
1.604 mike 1868: 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
1869: the step marked <i title="">end</i>. (<a href="#fragment-case">fragment
1870: case</a>)</li> <!-- This is only here for now in case people
1871: think that the spec accidentally omitted it and try to "fix"
1872: it. Note that noscript-in-head is also handled this way. This is
1873: all intentional. The only thing it doesn't handle is the
1874: scripting-disabled fragment parsing case for a <head> element
1875: containing a <noscript> which itself contains something other than
1876: a <link> or a <style> element; you'd expect that to break out of
1877: the <noscript> but it doesn't. This is an edge case that doesn't
1878: affect the spec, since the algorithm for fragment parsing is only
1879: used for innerHTML/outerHTML/insertAdjacentHTML(), where we know
1880: scripting is enabled. -->
1.1 mike 1881:
1.159 mike 1882: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element-0">body</a></code> element,
1.604 mike 1883: 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
1884: step marked <i title="">end</i>.</li>
1.1 mike 1885:
1.5 mike 1886: <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.604 mike 1887: 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
1888: the step marked <i title="">end</i>. (<a href="#fragment-case">fragment
1889: case</a>)</li>
1.1 mike 1890:
1.159 mike 1891: <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element-0">html</a></code> element,
1.333 mike 1892: then <!--: if the <span><code title="">head</code> element
1893: pointer</span> is null,--> switch the <a href="#insertion-mode">insertion mode</a>
1894: to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before
1895: head</a>"<!--, otherwise, switch the <span>insertion mode</span>
1896: to "<span title="insertion mode: after head">after head</span>".-->
1.604 mike 1897: Then, <!-- in either case, --> jump to the step marked <i title="">end</i>. (<a href="#fragment-case">fragment case</a>)</li> <!-- if the
1898: head element pointer can ever be non-null when we're going through
1899: these steps, we'll need to uncomment out the commented-out bits -->
1900:
1.724 mike 1901: <li>If <var title="">node</var> is an element from the <a href="infrastructure.html#mathml-namespace">MathML
1902: namespace</a> or the <a href="infrastructure.html#svg-namespace">SVG namespace</a>, then set the
1.604 mike 1903: <var title="">foreign</var> flag to true.</li>
1.1 mike 1904:
1905: <li>If <var title="">last</var> is true, then switch the
1906: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
1.604 mike 1907: 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 1908:
1909: <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
1910: elements</a>.</li>
1911:
1.604 mike 1912: <li>Return to the step marked <i>loop</i>.</li>
1913:
1914: <li><i>End</i>: If <var title="">foreign</var> is true, switch the
1915: <a href="#secondary-insertion-mode">secondary insertion mode</a> to whatever the
1916: <a href="#insertion-mode">insertion mode</a> is set to, and switch the
1917: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
1918: foreign content">in foreign content</a>".</li>
1.1 mike 1919:
1.755 mike 1920: </ol><h5 id="the-stack-of-open-elements"><span class="secno">8.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 1921:
1922: <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
1923: stack grows downwards; the topmost node on the stack is the first
1924: one added to the stack, and the bottommost node of the stack is the
1925: most recently added node in the stack (notwithstanding when the
1926: stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
1927:
1928: <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
1929: html</a>" <a href="#insertion-mode">insertion mode</a> creates the
1.159 mike 1930: <code><a href="semantics.html#the-html-element-0">html</a></code> root element node, which is then added to the
1.1 mike 1931: stack.</p>
1932:
1933: <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
1.159 mike 1934: elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1 mike 1935: element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
1936: parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
1937: case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
1938: html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
1939:
1.159 mike 1940: <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 1941: node of the stack. It never gets popped off the stack.</p>
1942:
1943: <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
1944: stack.</p>
1945:
1946: <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
1947: element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
1948: 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
1949: open elements</a> (<a href="#fragment-case">fragment case</a>), then the
1950: <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
1.159 mike 1951: of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code> element).</p>
1.1 mike 1952:
1953: <p>Elements in the stack fall into the following categories:</p>
1954:
1955: <dl><dt><dfn id="special">Special</dfn></dt>
1956:
1957: <dd><p>The following HTML elements have varying levels of special
1958: 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>,
1959: <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.724 mike 1960: <code><a href="obsolete.html#basefont">basefont</a></code>, <code><a href="obsolete.html#bgsound">bgsound</a></code>,
1.159 mike 1961: <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 1962: <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.755 mike 1963: <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID <code>datagrid</code>-->,
1.422 mike 1964: <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>,
1965: <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>,
1.762 mike 1966: <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="semantics.html#the-figure-element">figure</a></code>,
1.422 mike 1967: <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>,
1968: <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>,
1969: <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>,
1970: <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>,
1971: <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>,
1972: (commented out because this isn't an element that can end up on the
1973: stack, so it doesn't matter) --> <code><a href="text-level-semantics.html#the-img-element">img</a></code>,
1974: <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>,
1975: <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>,
1976: <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>,
1977: <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>,
1978: <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>,
1979: <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 1980: <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>,
1981: <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>,
1982: <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>,
1.724 mike 1983: <code><a href="obsolete.html#wbr">wbr</a></code>, and <code><a href="obsolete.html#xmp">xmp</a></code>.</p></dd>
1.1 mike 1984:
1985: <dt><dfn id="scoping">Scoping</dfn></dt>
1986: <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
1987: an element in scope">scopes</a> for various parts of the
1.5 mike 1988: 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 1989: <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>,
1990: <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 1991: <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
1992:
1993: <dt><dfn id="formatting">Formatting</dfn></dt>
1994: <dd><p>The following HTML elements are those that end up in the
1995: <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 1996: <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>,
1997: <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>,
1.724 mike 1998: <code><a href="obsolete.html#nobr">nobr</a></code>, <code><a href="obsolete.html#s">s</a></code>, <code><a href="text-level-semantics.html#the-small-element">small</a></code>,
1.5 mike 1999: <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
2000: <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1 mike 2001:
2002: <dt><dfn id="phrasing">Phrasing</dfn></dt>
2003: <dd><p>All other elements found while parsing an HTML
2004: document.</p></dd>
2005:
1.234 mike 2006: </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
2007: specific scope</dfn> consisting of a list of element types <var title="">list</var> when the following algorithm terminates in a
2008: match state:</p>
1.1 mike 2009:
2010: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
2011: node</a> (the bottommost node of the stack).</p></li>
2012:
2013: <li><p>If <var title="">node</var> is the target node, terminate in
2014: a match state.</p></li>
2015:
1.234 mike 2016: <li><p>Otherwise, if <var title="">node</var> is one of the element
2017: types in <var title="">list</var>, terminate in a failure
2018: state.</p></li>
1.1 mike 2019:
2020: <li><p>Otherwise, set <var title="">node</var> to the previous
2021: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
2022: 2. (This will never fail, since the loop will always terminate in
2023: the previous step if the top of the stack — an
1.159 mike 2024: <code><a href="semantics.html#the-html-element-0">html</a></code> element — is reached.)</p></li>
1.1 mike 2025:
1.234 mike 2026: </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
2027: it <a href="#has-an-element-in-the-specific-scope">has an element in the specific scope</a> consisting
2028: of the following element types:</p>
2029:
2030: <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
2031: <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
2032: <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.) -->
2033: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
2034: <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
2035: <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
2036: <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
2037: <li><code><a href="obsolete.html#the-marquee-element">marquee</a></code> in the HTML namespace</li>
2038: <li><code><a href="text-level-semantics.html#the-object-element">object</a></code> in the HTML namespace</li>
2039: <li><code title="">foreignObject</code> in the SVG namespace</li>
2040: </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
2041: item scope</dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
2042: scope</a> consisting of the following element types:</p>
2043:
2044: <ul class="brief"><li>All the element types listed above for the <i><a href="#has-an-element-in-scope">has an element
2045: in scope</a></i> algorithm.</li>
2046: <li><code><a href="semantics.html#the-ol-element">ol</a></code> in the HTML namespace</li>
2047: <li><code><a href="semantics.html#the-ul-element">ul</a></code> in the HTML namespace</li>
2048: </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
2049: scope</em></dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
2050: scope</a> consisting of the following element types:</p>
2051:
2052: <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.) -->
2053: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
2054: </ul><p>Nothing happens if at any time any of the elements in the
1.1 mike 2055: <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
1.810 mike 2056: or removed from, the <code><a href="infrastructure.html#document">Document</a></code> tree. In particular, the
1.1 mike 2057: stack is not changed in this situation. This can cause, amongst
2058: other strange effects, content to be appended to nodes that are no
2059: longer in the DOM.</p>
2060:
2061: <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
2062: the stack is manipulated in a random-access fashion.</p>
2063:
2064:
1.755 mike 2065: <h5 id="the-list-of-active-formatting-elements"><span class="secno">8.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 2066:
2067: <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
2068: empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
2069:
2070: <p>The list contains elements in the <a href="#formatting">formatting</a>
2071: category, and scope markers. The scope markers are inserted when
1.159 mike 2072: 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 2073: elements, marquees, table cells, and table captions, and are used to
1.5 mike 2074: prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.159 mike 2075: elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code> elements, marquees, and
1.1 mike 2076: tables.</p>
2077:
2078: <p class="note">The scope markers are unrelated to the concept of an
2079: element being <a href="#has-an-element-in-scope" title="has an element in scope">in
2080: scope</a>.</p>
2081:
2082: <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
2083: elements</a> is associated with the token for which it was
2084: created, so that further elements can be created for that token if
2085: necessary.</p>
2086:
2087: <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
2088: active formatting elements</dfn>, the UA must perform the following
2089: steps:</p>
2090:
2091: <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
2092: elements</a>, then there is nothing to reconstruct; stop this
2093: algorithm.</li>
2094:
2095: <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
2096: active formatting elements</a> is a marker, or if it is an
2097: element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
2098: there is nothing to reconstruct; stop this algorithm.</li>
2099:
2100: <li>Let <var title="">entry</var> be the last (most recently added)
2101: element in the <a href="#list-of-active-formatting-elements">list of active formatting
2102: elements</a>.</li>
2103:
2104: <li>If there are no entries before <var title="">entry</var> in the
2105: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
2106: 8.</li>
2107:
2108: <li>Let <var title="">entry</var> be the entry one earlier than
2109: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
2110: elements</a>.</li>
2111:
2112: <li>If <var title="">entry</var> is neither a marker nor an element
2113: that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
2114: 4.</li>
2115:
2116: <li>Let <var title="">entry</var> be the element one later than
2117: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
2118: elements</a>.</li>
2119:
2120: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
2121: element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
2122:
2123: <li>Append <var title="">new element</var> to the <a href="#current-node">current
2124: node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
2125: elements</a> so that it is the new <a href="#current-node">current
2126: node</a>.</li>
2127:
2128: <li>Replace the entry for <var title="">entry</var> in the list
2129: with an entry for <var title="">new element</var>.</li>
2130:
2131: <li>If the entry for <var title="">new element</var> in the
2132: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
2133: entry in the list, return to step 7.</li>
2134:
2135: </ol><p>This has the effect of reopening all the formatting elements that
2136: were opened in the current body, cell, or caption (whichever is
2137: youngest) that haven't been explicitly closed.</p>
2138:
2139: <p class="note">The way this specification is written, the
2140: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
2141: elements in chronological order with the least recently added
2142: element first and the most recently added element last (except for
2143: while steps 8 to 11 of the above algorithm are being executed, of
2144: course).</p>
2145:
2146: <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
2147: active formatting elements up to the last marker</dfn>, the UA must
2148: perform the following steps:</p>
2149:
2150: <ol><li>Let <var title="">entry</var> be the last (most recently added)
2151: entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
2152:
2153: <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
2154: formatting elements</a>.</li>
2155:
2156: <li>If <var title="">entry</var> was a marker, then stop the
2157: algorithm at this point. The list has been cleared up to the last
2158: marker.</li>
2159:
2160: <li>Go to step 1.</li>
2161:
1.755 mike 2162: </ol><h5 id="the-element-pointers"><span class="secno">8.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 2163:
2164: <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
2165: pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
2166: pointer</dfn> are both null.</p>
2167:
1.159 mike 2168: <p>Once a <code><a href="semantics.html#the-head-element-0">head</a></code> element has been parsed (whether
1.1 mike 2169: implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
2170: element pointer</a> gets set to point to this node.</p>
2171:
2172: <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
2173: points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
2174: whose end tag has not yet been seen. It is used to make form
2175: controls associate with forms in the face of dramatically bad
2176: markup, for historical reasons.</p>
2177:
2178:
1.755 mike 2179: <h5 id="other-parsing-state-flags"><span class="secno">8.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 2180:
1.794 mike 2181: <p>The <dfn id="scripting-flag">scripting flag</dfn> is set to "enabled" if <a href="webappapis.html#concept-n-script" title="concept-n-script">scripting was enabled</a> for the
1.810 mike 2182: <code><a href="infrastructure.html#document">Document</a></code> with which the parser is associated when the
1.1 mike 2183: parser was created, and "disabled" otherwise.</p>
2184:
2185: <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
2186: when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
2187: parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
2188: don't execute in that case.</p>
2189:
2190: <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
2191: created. It is set to "not ok" after certain tokens are seen.</p>
2192:
1.266 mike 2193: </div><div class="impl">
1.1 mike 2194:
1.755 mike 2195: <h4 id="tokenization"><span class="secno">8.2.4 </span><dfn>Tokenization</dfn></h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 2196:
2197: <p>Implementations must act as if they used the following state
2198: machine to tokenize HTML. The state machine must start in the
2199: <a href="#data-state">data state</a>. Most states consume a single character,
2200: which may have various side-effects, and either switches the state
2201: machine to a new state to <em>reconsume</em> the same character, or
2202: switches it to a new state (to consume the next character), or
2203: repeats the same state (to consume the next character). Some states
2204: have more complicated behavior and can consume several characters
1.541 mike 2205: before switching to another state. In some cases, the tokenizer
2206: state is also changed by the tree construction stage.</p>
1.1 mike 2207:
1.541 mike 2208: <p>The exact behavior of certain states depends on the
2209: <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
2210: elements</a>. Certain states also use a <dfn id="temporary-buffer"><var>temporary
2211: buffer</var></dfn> to track progress.</p>
1.1 mike 2212:
2213: <p>The output of the tokenization step is a series of zero or more
2214: of the following tokens: DOCTYPE, start tag, end tag, comment,
2215: character, end-of-file. DOCTYPE tokens have a name, a public
2216: identifier, a system identifier, and a <i>force-quirks
2217: flag</i>. When a DOCTYPE token is created, its name, public
2218: identifier, and system identifier must be marked as missing (which
2219: is a distinct state from the empty string), and the <i>force-quirks
2220: flag</i> must be set to <i>off</i> (its other state is
2221: <i>on</i>). Start and end tag tokens have a tag name, a
2222: <i>self-closing flag</i>, and a list of attributes, each of which
2223: has a name and a value. When a start or end tag token is created,
2224: its <i>self-closing flag</i> must be unset (its other state is that
2225: it be set), and its attributes list must be empty. Comment and
2226: character tokens have data.</p>
2227:
2228: <p>When a token is emitted, it must immediately be handled by the
2229: <a href="#tree-construction">tree construction</a> stage. The tree construction stage
1.541 mike 2230: can affect the state of the tokenization stage, and can insert
2231: additional characters into the stream. (For example, the
1.1 mike 2232: <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
1.159 mike 2233: using the <a href="embedded-content-0.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
1.1 mike 2234: characters into the stream being tokenized.)</p>
2235:
2236: <p>When a start tag token is emitted with its <i>self-closing
2237: flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
2238: self-closing flag">acknowledged</dfn> when it is processed by the
2239: tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
2240:
2241: <p>When an end tag token is emitted with attributes, that is a
2242: <a href="#parse-error">parse error</a>.</p>
2243:
2244: <p>When an end tag token is emitted with its <i>self-closing
2245: flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
2246:
1.541 mike 2247: <p>An <dfn id="appropriate-end-tag-token">appropriate end tag token</dfn> is an end tag token whose
2248: tag name matches the tag name of the last start tag to have been
2249: emitted from this tokenizer, if any. If no start tag has been
2250: emitted from this tokenizer, then no end tag token is
2251: appropriate.</p>
2252:
1.1 mike 2253: <p>Before each step of the tokenizer, the user agent must first
2254: check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
2255: tokenizer must abort the processing of any nested invocations of the
1.479 mike 2256: tokenizer, yielding control back to the caller.</p>
1.1 mike 2257:
2258: <p>The tokenizer state machine consists of the states defined in the
2259: following subsections.</p>
2260:
1.541 mike 2261:
1.333 mike 2262: <!-- Order of the lists below is supposed to be non-error then
2263: error, by unicode, then EOF, ending with "anything else" -->
1.1 mike 2264:
1.541 mike 2265:
1.755 mike 2266: <h5 id="data-state"><span class="secno">8.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 2267:
2268: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2269:
2270: <dl class="switch"><dt>U+0026 AMPERSAND (&)</dt>
1.541 mike 2271: <dd>Switch to the <a href="#character-reference-in-data-state">character reference in data
1.56 mike 2272: state</a>.</dd>
1.1 mike 2273:
1.541 mike 2274: <dt>U+003C LESS-THAN SIGN (<)</dt>
2275: <dd>Switch to the <a href="#tag-open-state">tag open state</a>.</dd>
2276:
2277: <dt>EOF</dt>
2278: <dd>Emit an end-of-file token.</dd>
2279:
2280: <dt>Anything else</dt>
2281: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2282: token. Stay in the <a href="#data-state">data state</a>.</dd>
1.1 mike 2283:
1.755 mike 2284: </dl><h5 id="character-reference-in-data-state"><span class="secno">8.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>
1.618 mike 2285:
2286: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
2287: <a href="#additional-allowed-character">additional allowed character</a>.</p>
2288:
2289: <p>If nothing is returned, emit a U+0026 AMPERSAND character
2290: token.</p>
2291:
2292: <p>Otherwise, emit the character token that was returned.</p>
2293:
2294: <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
2295:
2296:
1.755 mike 2297: <h5 id="rcdata-state"><span class="secno">8.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 2298:
1.541 mike 2299: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1.1 mike 2300:
1.541 mike 2301: <dl class="switch"><dt>U+0026 AMPERSAND (&)</dt>
1.618 mike 2302: <dd>Switch to the <a href="#character-reference-in-rcdata-state">character reference in RCDATA
1.541 mike 2303: state</a>.</dd>
1.1 mike 2304:
2305: <dt>U+003C LESS-THAN SIGN (<)</dt>
1.541 mike 2306: <dd>Switch to the <a href="#rcdata-less-than-sign-state">RCDATA less-than sign state</a>.</dd>
2307:
2308: <dt>EOF</dt>
2309: <dd>Emit an end-of-file token.</dd>
1.1 mike 2310:
1.541 mike 2311: <dt>Anything else</dt>
2312: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2313: token. Stay in the <a href="#rcdata-state">RCDATA state</a>.</dd>
1.1 mike 2314:
1.755 mike 2315: </dl><h5 id="character-reference-in-rcdata-state"><span class="secno">8.2.4.4 </span><dfn>Character reference in RCDATA state</dfn></h5>
1.618 mike 2316:
2317: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
2318: <a href="#additional-allowed-character">additional allowed character</a>.</p>
2319:
2320: <p>If nothing is returned, emit a U+0026 AMPERSAND character
2321: token.</p>
2322:
2323: <p>Otherwise, emit the character token that was returned.</p>
2324:
2325: <p>Finally, switch to the <a href="#rcdata-state">RCDATA state</a>.</p>
2326:
2327:
1.755 mike 2328: <h5 id="rawtext-state"><span class="secno">8.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 2329:
1.541 mike 2330: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1.1 mike 2331:
1.541 mike 2332: <dl class="switch"><dt>U+003C LESS-THAN SIGN (<)</dt>
2333: <dd>Switch to the <a href="#rawtext-less-than-sign-state">RAWTEXT less-than sign state</a>.</dd>
1.1 mike 2334:
2335: <dt>EOF</dt>
2336: <dd>Emit an end-of-file token.</dd>
2337:
2338: <dt>Anything else</dt>
1.541 mike 2339: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2340: token. Stay in the <a href="#rawtext-state">RAWTEXT state</a>.</dd>
1.1 mike 2341:
1.755 mike 2342: </dl><h5 id="script-data-state"><span class="secno">8.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 2343:
1.541 mike 2344: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1.1 mike 2345:
1.541 mike 2346: <dl class="switch"><dt>U+003C LESS-THAN SIGN (<)</dt>
2347: <dd>Switch to the <a href="#script-data-less-than-sign-state">script data less-than sign state</a>.</dd>
1.1 mike 2348:
1.541 mike 2349: <dt>EOF</dt>
2350: <dd>Emit an end-of-file token.</dd>
1.1 mike 2351:
1.541 mike 2352: <dt>Anything else</dt>
2353: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2354: token. Stay in the <a href="#script-data-state">script data state</a>.</dd>
1.1 mike 2355:
1.755 mike 2356: </dl><h5 id="plaintext-state"><span class="secno">8.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 2357:
1.541 mike 2358: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1.1 mike 2359:
1.541 mike 2360: <dl class="switch"><dt>EOF</dt>
2361: <dd>Emit an end-of-file token.</dd>
1.1 mike 2362:
1.541 mike 2363: <dt>Anything else</dt>
2364: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2365: token. Stay in the <a href="#plaintext-state">PLAINTEXT state</a>.</dd>
1.1 mike 2366:
1.755 mike 2367: </dl><h5 id="tag-open-state"><span class="secno">8.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 2368:
1.541 mike 2369: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1.1 mike 2370:
1.541 mike 2371: <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
2372: <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
1.1 mike 2373:
1.541 mike 2374: <dt>U+002F SOLIDUS (/)</dt>
1.755 mike 2375: <dd>Switch to the <a href="#end-tag-open-state">end tag open state</a>.</dd>
1.1 mike 2376:
1.541 mike 2377: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2378: <dd>Create a new start tag token, set its tag name to the
2379: lowercase version of the <a href="#current-input-character">current input character</a> (add 0x0020 to the
2380: character's code point), then switch to the <a href="#tag-name-state">tag name
2381: state</a>. (Don't emit the token yet; further details will
2382: be filled in before it is emitted.)</dd>
1.1 mike 2383:
1.541 mike 2384: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2385: <dd>Create a new start tag token, set its tag name to the
2386: <a href="#current-input-character">current input character</a>, then switch to the <a href="#tag-name-state">tag
2387: name state</a>. (Don't emit the token yet; further details will
2388: be filled in before it is emitted.)</dd>
1.1 mike 2389:
1.541 mike 2390: <dt>U+003F QUESTION MARK (?)</dt>
2391: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2392: comment state</a>.</dd>
1.1 mike 2393:
1.541 mike 2394: <dt>Anything else</dt>
2395: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2396: character token and reconsume the <a href="#current-input-character">current input
2397: character</a> in the <a href="#data-state">data state</a>.</dd>
1.1 mike 2398:
1.755 mike 2399: </dl><h5 id="end-tag-open-state"><span class="secno">8.2.4.9 </span><dfn>End tag open state</dfn></h5>
1.1 mike 2400:
1.541 mike 2401: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1.1 mike 2402:
2403: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2404: <dd>Create a new end tag token, set its tag name to the lowercase
1.541 mike 2405: version of the <a href="#current-input-character">current input character</a> (add 0x0020 to
2406: the character's code point), then switch to the <a href="#tag-name-state">tag name
1.1 mike 2407: state</a>. (Don't emit the token yet; further details will be
2408: filled in before it is emitted.)</dd>
2409:
2410: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
1.541 mike 2411: <dd>Create a new end tag token, set its tag name to the
2412: <a href="#current-input-character">current input character</a>, then switch to the <a href="#tag-name-state">tag
2413: name state</a>. (Don't emit the token yet; further details will
2414: be filled in before it is emitted.)</dd>
1.1 mike 2415:
2416: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2417: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
2418: state</a>.</dd>
2419:
2420: <dt>EOF</dt>
2421: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2422: character token and a U+002F SOLIDUS character token. Reconsume
2423: the EOF character in the <a href="#data-state">data state</a>.</dd>
2424:
2425: <dt>Anything else</dt>
2426: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2427: comment state</a>.</dd>
2428:
1.755 mike 2429: </dl><h5 id="tag-name-state"><span class="secno">8.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 2430:
2431: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2432:
2433: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2434: <dt>U+000A LINE FEED (LF)</dt>
2435: <dt>U+000C FORM FEED (FF)</dt>
2436: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2437: <dt>U+0020 SPACE</dt>
2438: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2439:
2440: <dt>U+002F SOLIDUS (/)</dt>
2441: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2442:
2443: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2444: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2445: state</a>.</dd>
2446:
2447: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
1.541 mike 2448: <dd>Append the lowercase version of the <a href="#current-input-character">current input
2449: character</a> (add 0x0020 to the character's code point) to the
2450: current tag token's tag name. Stay in the <a href="#tag-name-state">tag name
2451: state</a>.</dd>
2452:
2453: <dt>EOF</dt>
2454: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2455: <a href="#data-state">data state</a>.</dd>
2456:
2457: <dt>Anything else</dt>
2458: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2459: tag token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
2460:
1.755 mike 2461: </dl><h5 id="rcdata-less-than-sign-state"><span class="secno">8.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 2462: <!-- identical to the RAWTEXT less-than sign state, except s/RAWTEXT/RCDATA/g -->
2463:
2464: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2465:
2466: <dl class="switch"><dt>U+002F SOLIDUS (/)</dt>
2467: <dd>Set the <var><a href="#temporary-buffer">temporary buffer</a></var> to the empty string. Switch
2468: to the <a href="#rcdata-end-tag-open-state">RCDATA end tag open state</a>.</dd>
2469:
2470: <dt>Anything else</dt>
2471: <dd>Emit a U+003C LESS-THAN SIGN character token and reconsume the
2472: <a href="#current-input-character">current input character</a> in the <a href="#rcdata-state">RCDATA
2473: state</a>.</dd>
2474:
1.755 mike 2475: </dl><h5 id="rcdata-end-tag-open-state"><span class="secno">8.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 2476: <!-- identical to the RAWTEXT (and Script data) end tag open state, except s/RAWTEXT/RCDATA/g -->
2477:
2478: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2479:
2480: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2481: <dd>Create a new end tag token, and set its tag name to the
2482: lowercase version of the <a href="#current-input-character">current input character</a> (add
2483: 0x0020 to the character's code point). Append the <a href="#current-input-character">current
2484: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2485: switch to the <a href="#rcdata-end-tag-name-state">RCDATA end tag name state</a>. (Don't emit
2486: the token yet; further details will be filled in before it is
2487: emitted.)</dd>
2488:
2489: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2490: <dd>Create a new end tag token, and set its tag name to the
2491: <a href="#current-input-character">current input character</a>. Append the <a href="#current-input-character">current
2492: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2493: switch to the <a href="#rcdata-end-tag-name-state">RCDATA end tag name state</a>. (Don't emit
2494: the token yet; further details will be filled in before it is
2495: emitted.)</dd>
2496:
2497: <dt>Anything else</dt>
2498: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2499: character token, and reconsume the <a href="#current-input-character">current input
2500: character</a> in the <a href="#rcdata-state">RCDATA state</a>.</dd>
2501:
1.755 mike 2502: </dl><h5 id="rcdata-end-tag-name-state"><span class="secno">8.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 2503: <!-- identical to the RAWTEXT (and Script data) end tag name state, except s/RAWTEXT/RCDATA/g -->
2504:
2505: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2506:
2507: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2508: <dt>U+000A LINE FEED (LF)</dt>
2509: <dt>U+000C FORM FEED (FF)</dt>
2510: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2511: <dt>U+0020 SPACE</dt>
2512: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2513: token</a>, then switch to the <a href="#before-attribute-name-state">before attribute name
2514: state</a>. Otherwise, treat it as per the "anything else" entry
2515: below.</dd>
2516:
2517: <dt>U+002F SOLIDUS (/)</dt>
2518: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2519: token</a>, then switch to the <a href="#self-closing-start-tag-state">self-closing start tag
2520: state</a>. Otherwise, treat it as per the "anything else" entry
2521: below.</dd>
2522:
2523: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2524: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2525: token</a>, then emit the current tag token and switch to the
2526: <a href="#data-state">data state</a>. Otherwise, treat it as per the "anything
2527: else" entry below.</dd>
2528:
2529: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2530: <dd>Append the lowercase version of the <a href="#current-input-character">current input
2531: character</a> (add 0x0020 to the character's code point) to the
2532: current tag token's tag name. Append the <a href="#current-input-character">current input
2533: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
2534: <a href="#rcdata-end-tag-name-state">RCDATA end tag name state</a>.</dd>
2535:
2536: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2537: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2538: tag token's tag name. Append the <a href="#current-input-character">current input
2539: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
2540: <a href="#rcdata-end-tag-name-state">RCDATA end tag name state</a>.</dd>
2541:
2542: <dt>Anything else</dt>
2543: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2544: character token, a character token for each of the characters in
2545: the <var><a href="#temporary-buffer">temporary buffer</a></var> (in the order they were added to
2546: the buffer), and reconsume the <a href="#current-input-character">current input character</a>
2547: in the <a href="#rcdata-state">RCDATA state</a>.</dd>
2548:
1.755 mike 2549: </dl><h5 id="rawtext-less-than-sign-state"><span class="secno">8.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 2550: <!-- identical to the RCDATA less-than sign state, except s/RCDATA/RAWTEXT/g -->
2551:
2552: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2553:
2554: <dl class="switch"><dt>U+002F SOLIDUS (/)</dt>
2555: <dd>Set the <var><a href="#temporary-buffer">temporary buffer</a></var> to the empty string. Switch
2556: to the <a href="#rawtext-end-tag-open-state">RAWTEXT end tag open state</a>.</dd>
2557:
2558: <dt>Anything else</dt>
2559: <dd>Emit a U+003C LESS-THAN SIGN character token and reconsume the
2560: <a href="#current-input-character">current input character</a> in the <a href="#rawtext-state">RAWTEXT
2561: state</a>.</dd>
2562:
1.755 mike 2563: </dl><h5 id="rawtext-end-tag-open-state"><span class="secno">8.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 2564: <!-- identical to the RCDATA (and Script data) end tag open state, except s/RCDATA/RAWTEXT/g -->
2565:
2566: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2567:
2568: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2569: <dd>Create a new end tag token, and set its tag name to the
2570: lowercase version of the <a href="#current-input-character">current input character</a> (add
2571: 0x0020 to the character's code point). Append the <a href="#current-input-character">current
2572: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2573: switch to the <a href="#rawtext-end-tag-name-state">RAWTEXT end tag name state</a>. (Don't emit
2574: the token yet; further details will be filled in before it is
2575: emitted.)</dd>
2576:
2577: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2578: <dd>Create a new end tag token, and set its tag name to the
2579: <a href="#current-input-character">current input character</a>. Append the <a href="#current-input-character">current
2580: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2581: switch to the <a href="#rawtext-end-tag-name-state">RAWTEXT end tag name state</a>. (Don't emit
2582: the token yet; further details will be filled in before it is
2583: emitted.)</dd>
2584:
2585: <dt>Anything else</dt>
2586: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2587: character token, and reconsume the <a href="#current-input-character">current input
2588: character</a> in the <a href="#rawtext-state">RAWTEXT state</a>.</dd>
2589:
1.755 mike 2590: </dl><h5 id="rawtext-end-tag-name-state"><span class="secno">8.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 2591: <!-- identical to the RCDATA (and Script data) end tag name state, except s/RCDATA/RAWTEXT/g -->
2592:
2593: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2594:
2595: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2596: <dt>U+000A LINE FEED (LF)</dt>
2597: <dt>U+000C FORM FEED (FF)</dt>
2598: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2599: <dt>U+0020 SPACE</dt>
2600: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2601: token</a>, then switch to the <a href="#before-attribute-name-state">before attribute name
2602: state</a>. Otherwise, treat it as per the "anything else" entry
2603: below.</dd>
2604:
2605: <dt>U+002F SOLIDUS (/)</dt>
2606: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2607: token</a>, then switch to the <a href="#self-closing-start-tag-state">self-closing start tag
2608: state</a>. Otherwise, treat it as per the "anything else" entry
2609: below.</dd>
2610:
2611: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2612: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2613: token</a>, then emit the current tag token and switch to the
2614: <a href="#data-state">data state</a>. Otherwise, treat it as per the "anything
2615: else" entry below.</dd>
2616:
2617: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2618: <dd>Append the lowercase version of the <a href="#current-input-character">current input
2619: character</a> (add 0x0020 to the character's code point) to the
2620: current tag token's tag name. Append the <a href="#current-input-character">current input
2621: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
2622: <a href="#rawtext-end-tag-name-state">RAWTEXT end tag name state</a>.</dd>
2623:
2624: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2625: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2626: tag token's tag name. Append the <a href="#current-input-character">current input
2627: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
2628: <a href="#rawtext-end-tag-name-state">RAWTEXT end tag name state</a>.</dd>
2629:
2630: <dt>Anything else</dt>
2631: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2632: character token, a character token for each of the characters in
2633: the <var><a href="#temporary-buffer">temporary buffer</a></var> (in the order they were added to
2634: the buffer), and reconsume the <a href="#current-input-character">current input character</a>
2635: in the <a href="#rawtext-state">RAWTEXT state</a>.</dd>
2636:
1.755 mike 2637: </dl><h5 id="script-data-less-than-sign-state"><span class="secno">8.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 2638:
2639: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2640:
2641: <dl class="switch"><dt>U+002F SOLIDUS (/)</dt>
2642: <dd>Set the <var><a href="#temporary-buffer">temporary buffer</a></var> to the empty string. Switch
2643: to the <a href="#script-data-end-tag-open-state">script data end tag open state</a>.</dd>
2644:
2645: <dt>U+0021 EXCLAMATION MARK (!)</dt>
2646: <dd>Emit a U+003C LESS-THAN SIGN character token and a U+0021
2647: EXCLAMATION MARK character token. Switch to the <a href="#script-data-escape-start-state">script data
2648: escape start state</a>.</dd>
2649:
2650: <dt>Anything else</dt>
2651: <dd>Emit a U+003C LESS-THAN SIGN character token and reconsume the
2652: <a href="#current-input-character">current input character</a> in the <a href="#script-data-state">script data
2653: state</a>.</dd>
2654:
1.755 mike 2655: </dl><h5 id="script-data-end-tag-open-state"><span class="secno">8.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 2656: <!-- identical to the RCDATA (and RAWTEXT) end tag open state, except s/RCDATA/Script data/g -->
2657:
2658: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2659:
2660: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2661: <dd>Create a new end tag token, and set its tag name to the
2662: lowercase version of the <a href="#current-input-character">current input character</a> (add
2663: 0x0020 to the character's code point). Append the <a href="#current-input-character">current
2664: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2665: switch to the <a href="#script-data-end-tag-name-state">script data end tag name state</a>. (Don't emit
2666: the token yet; further details will be filled in before it is
2667: emitted.)</dd>
2668:
2669: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2670: <dd>Create a new end tag token, and set its tag name to the
2671: <a href="#current-input-character">current input character</a>. Append the <a href="#current-input-character">current
2672: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2673: switch to the <a href="#script-data-end-tag-name-state">script data end tag name state</a>. (Don't emit
2674: the token yet; further details will be filled in before it is
2675: emitted.)</dd>
2676:
2677: <dt>Anything else</dt>
2678: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2679: character token, and reconsume the <a href="#current-input-character">current input
2680: character</a> in the <a href="#script-data-state">script data state</a>.</dd>
2681:
1.755 mike 2682: </dl><h5 id="script-data-end-tag-name-state"><span class="secno">8.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 2683: <!-- identical to the RCDATA (and RAWTEXT) end tag name state, except s/RCDATA/Script data/g -->
2684:
2685: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2686:
2687: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2688: <dt>U+000A LINE FEED (LF)</dt>
2689: <dt>U+000C FORM FEED (FF)</dt>
2690: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2691: <dt>U+0020 SPACE</dt>
2692: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2693: token</a>, then switch to the <a href="#before-attribute-name-state">before attribute name
2694: state</a>. Otherwise, treat it as per the "anything else" entry
2695: below.</dd>
2696:
2697: <dt>U+002F SOLIDUS (/)</dt>
2698: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2699: token</a>, then switch to the <a href="#self-closing-start-tag-state">self-closing start tag
2700: state</a>. Otherwise, treat it as per the "anything else" entry
2701: below.</dd>
2702:
2703: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2704: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2705: token</a>, then emit the current tag token and switch to the
2706: <a href="#data-state">data state</a>. Otherwise, treat it as per the "anything
2707: else" entry below.</dd>
2708:
2709: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2710: <dd>Append the lowercase version of the <a href="#current-input-character">current input
2711: character</a> (add 0x0020 to the character's code point) to the
2712: current tag token's tag name. Append the <a href="#current-input-character">current input
2713: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
1.542 mike 2714: <a href="#script-data-end-tag-name-state">script data end tag name state</a>.</dd>
1.541 mike 2715:
2716: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2717: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2718: tag token's tag name. Append the <a href="#current-input-character">current input
2719: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
1.542 mike 2720: <a href="#script-data-end-tag-name-state">script data end tag name state</a>.</dd>
1.541 mike 2721:
2722: <dt>Anything else</dt>
2723: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2724: character token, a character token for each of the characters in
2725: the <var><a href="#temporary-buffer">temporary buffer</a></var> (in the order they were added to
2726: the buffer), and reconsume the <a href="#current-input-character">current input character</a>
2727: in the <a href="#script-data-state">script data state</a>.</dd>
2728:
1.755 mike 2729: </dl><h5 id="script-data-escape-start-state"><span class="secno">8.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 2730:
2731: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2732:
2733: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2734: <dd>Emit a U+002D HYPHEN-MINUS character token. Switch to the
2735: <a href="#script-data-escape-start-dash-state">script data escape start dash state</a>.</dd>
2736:
2737: <dt>Anything else</dt>
2738: <dd>Reconsume the <a href="#current-input-character">current input character</a> in the
2739: <a href="#script-data-state">script data state</a>.</dd>
2740:
1.755 mike 2741: </dl><h5 id="script-data-escape-start-dash-state"><span class="secno">8.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 2742:
2743: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2744:
2745: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2746: <dd>Emit a U+002D HYPHEN-MINUS character token. Switch to the
2747: <a href="#script-data-escaped-dash-dash-state">script data escaped dash dash state</a>.</dd>
2748:
2749: <dt>Anything else</dt>
2750: <dd>Reconsume the <a href="#current-input-character">current input character</a> in the
2751: <a href="#script-data-state">script data state</a>.</dd>
2752:
1.755 mike 2753: </dl><h5 id="script-data-escaped-state"><span class="secno">8.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 2754:
2755: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2756:
2757: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2758: <dd>Emit a U+002D HYPHEN-MINUS character token. Switch to the
2759: <a href="#script-data-escaped-dash-state">script data escaped dash state</a>.</dd>
2760:
1.542 mike 2761: <dt>U+003C LESS-THAN SIGN (<)</dt>
2762: <dd><p>Switch to the <a href="#script-data-escaped-less-than-sign-state">script data escaped less-than sign
2763: state</a>.</p></dd>
2764:
1.541 mike 2765: <dt>EOF</dt>
2766: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2767: <a href="#data-state">data state</a>.</dd>
2768:
2769: <dt>Anything else</dt>
1.542 mike 2770: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2771: token. Stay in the <a href="#script-data-escaped-state">script data escaped state</a>.</dd>
1.541 mike 2772:
1.755 mike 2773: </dl><h5 id="script-data-escaped-dash-state"><span class="secno">8.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 2774:
2775: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2776:
2777: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2778: <dd>Emit a U+002D HYPHEN-MINUS character token. Switch to the
2779: <a href="#script-data-escaped-dash-dash-state">script data escaped dash dash state</a>.</dd>
2780:
1.542 mike 2781: <dt>U+003C LESS-THAN SIGN (<)</dt>
2782: <dd><p>Switch to the <a href="#script-data-escaped-less-than-sign-state">script data escaped less-than sign
2783: state</a>.</p></dd>
2784:
1.541 mike 2785: <dt>EOF</dt>
2786: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2787: <a href="#data-state">data state</a>.</dd>
2788:
2789: <dt>Anything else</dt>
1.542 mike 2790: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2791: token. Switch to the <a href="#script-data-escaped-state">script data escaped state</a>.</dd>
1.541 mike 2792:
1.755 mike 2793: </dl><h5 id="script-data-escaped-dash-dash-state"><span class="secno">8.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 2794:
2795: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2796:
2797: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2798: <dd>Emit a U+002D HYPHEN-MINUS character token. Stay in the
2799: <a href="#script-data-escaped-dash-dash-state">script data escaped dash dash state</a>.</dd>
2800:
1.542 mike 2801: <dt>U+003C LESS-THAN SIGN (<)</dt>
2802: <dd><p>Switch to the <a href="#script-data-escaped-less-than-sign-state">script data escaped less-than sign
2803: state</a>.</p></dd>
2804:
1.541 mike 2805: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2806: <dd>Emit a U+003E GREATER-THAN SIGN character token. Switch to the
2807: <a href="#script-data-state">script data state</a>.</dd>
1.1 mike 2808:
2809: <dt>EOF</dt>
2810: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2811: <a href="#data-state">data state</a>.</dd>
2812:
2813: <dt>Anything else</dt>
1.542 mike 2814: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2815: token. Switch to the <a href="#script-data-escaped-state">script data escaped state</a>.</dd>
2816:
1.755 mike 2817: </dl><h5 id="script-data-escaped-less-than-sign-state"><span class="secno">8.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 2818:
2819: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2820:
2821: <dl class="switch"><dt>U+002F SOLIDUS (/)</dt>
2822: <dd>Set the <var><a href="#temporary-buffer">temporary buffer</a></var> to the empty string. Switch
2823: to the <a href="#script-data-escaped-end-tag-open-state">script data escaped end tag open state</a>.</dd>
2824:
2825: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2826: <dd>Emit a U+003C LESS-THAN SIGN character token and the
2827: <a href="#current-input-character">current input character</a> as a character token. Set the
2828: <var><a href="#temporary-buffer">temporary buffer</a></var> to the empty string. Append the
2829: lowercase version of the <a href="#current-input-character">current input character</a> (add
2830: 0x0020 to the character's code point) to the <var><a href="#temporary-buffer">temporary
2831: buffer</a></var>. Switch to the <a href="#script-data-double-escape-start-state">script data double escape start
2832: state</a>.</dd>
2833:
2834: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2835: <dd>Emit a U+003C LESS-THAN SIGN character token and the
2836: <a href="#current-input-character">current input character</a> as a character token. Set the
2837: <var><a href="#temporary-buffer">temporary buffer</a></var> to the empty string. Append the
2838: <a href="#current-input-character">current input character</a> to the <var><a href="#temporary-buffer">temporary
2839: buffer</a></var>. Switch to the <a href="#script-data-double-escape-start-state">script data double escape start
2840: state</a>.</dd>
2841:
2842: <dt>Anything else</dt>
2843: <dd>Emit a U+003C LESS-THAN SIGN character token and reconsume the
2844: <a href="#current-input-character">current input character</a> in the <a href="#script-data-escaped-state">script data
2845: escaped state</a>.</dd>
2846:
1.755 mike 2847: </dl><h5 id="script-data-escaped-end-tag-open-state"><span class="secno">8.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 2848:
2849: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2850:
2851: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2852: <dd>Create a new end tag token, and set its tag name to the
2853: lowercase version of the <a href="#current-input-character">current input character</a> (add
2854: 0x0020 to the character's code point). Append the <a href="#current-input-character">current
2855: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2856: switch to the <a href="#script-data-escaped-end-tag-name-state">script data escaped end tag name
2857: state</a>. (Don't emit the token yet; further details will be
2858: filled in before it is emitted.)</dd>
2859:
2860: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2861: <dd>Create a new end tag token, and set its tag name to the
2862: <a href="#current-input-character">current input character</a>. Append the <a href="#current-input-character">current
2863: input character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Finally,
2864: switch to the <a href="#script-data-escaped-end-tag-name-state">script data escaped end tag name
2865: state</a>. (Don't emit the token yet; further details will be
2866: filled in before it is emitted.)</dd>
2867:
2868: <dt>Anything else</dt>
2869: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2870: character token, and reconsume the <a href="#current-input-character">current input
2871: character</a> in the <a href="#script-data-escaped-state">script data escaped state</a>.</dd>
2872:
1.755 mike 2873: </dl><h5 id="script-data-escaped-end-tag-name-state"><span class="secno">8.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 2874:
2875: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2876:
2877: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2878: <dt>U+000A LINE FEED (LF)</dt>
2879: <dt>U+000C FORM FEED (FF)</dt>
2880: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2881: <dt>U+0020 SPACE</dt>
2882: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2883: token</a>, then switch to the <a href="#before-attribute-name-state">before attribute name
2884: state</a>. Otherwise, treat it as per the "anything else" entry
2885: below.</dd>
2886:
2887: <dt>U+002F SOLIDUS (/)</dt>
2888: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2889: token</a>, then switch to the <a href="#self-closing-start-tag-state">self-closing start tag
2890: state</a>. Otherwise, treat it as per the "anything else" entry
2891: below.</dd>
2892:
2893: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2894: <dd>If the current end tag token is an <a href="#appropriate-end-tag-token">appropriate end tag
2895: token</a>, then emit the current tag token and switch to the
2896: <a href="#data-state">data state</a>. Otherwise, treat it as per the "anything
2897: else" entry below.</dd>
2898:
2899: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2900: <dd>Append the lowercase version of the <a href="#current-input-character">current input
2901: character</a> (add 0x0020 to the character's code point) to the
2902: current tag token's tag name. Append the <a href="#current-input-character">current input
2903: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
2904: <a href="#script-data-escaped-end-tag-name-state">script data escaped end tag name state</a>.</dd>
2905:
2906: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2907: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2908: tag token's tag name. Append the <a href="#current-input-character">current input
2909: character</a> to the <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the
2910: <a href="#script-data-escaped-end-tag-name-state">script data escaped end tag name state</a>.</dd>
2911:
2912: <dt>Anything else</dt>
2913: <dd>Emit a U+003C LESS-THAN SIGN character token, a U+002F SOLIDUS
2914: character token, a character token for each of the characters in
2915: the <var><a href="#temporary-buffer">temporary buffer</a></var> (in the order they were added to
2916: the buffer), and reconsume the <a href="#current-input-character">current input character</a>
2917: in the <a href="#script-data-escaped-state">script data escaped state</a>.</dd>
2918:
1.755 mike 2919: </dl><h5 id="script-data-double-escape-start-state"><span class="secno">8.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 2920:
2921: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2922:
2923: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2924: <dt>U+000A LINE FEED (LF)</dt>
2925: <dt>U+000C FORM FEED (FF)</dt>
2926: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2927: <dt>U+0020 SPACE</dt>
2928: <dt>U+002F SOLIDUS (/)</dt>
2929: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2930: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2931: 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
2932: double escaped state</a>. Otherwise, switch to the <a href="#script-data-escaped-state">script
2933: data escaped state</a>.</dd>
2934:
2935: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2936: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2937: token. Append the lowercase version of the <a href="#current-input-character">current input
2938: character</a> (add 0x0020 to the character's code point) to the
2939: <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the <a href="#script-data-double-escape-start-state">script data double
2940: escape start state</a>.</dd>
2941:
2942: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2943: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2944: token. Append the <a href="#current-input-character">current input character</a> to the
2945: <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the <a href="#script-data-double-escape-start-state">script data double
2946: escape start state</a>.</dd>
2947:
2948: <dt>Anything else</dt>
2949: <dd>Reconsume the <a href="#current-input-character">current input character</a> in the
2950: <a href="#script-data-escaped-state">script data escaped state</a>.</dd>
2951:
1.755 mike 2952: </dl><h5 id="script-data-double-escaped-state"><span class="secno">8.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 2953:
2954: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2955:
2956: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2957: <dd>Emit a U+002D HYPHEN-MINUS character token. Switch to the
2958: <a href="#script-data-double-escaped-dash-state">script data double escaped dash state</a>.</dd>
2959:
2960: <dt>U+003C LESS-THAN SIGN (<)</dt>
2961: <dd><p>Emit a U+003C LESS-THAN SIGN character token. Switch to the
2962: <a href="#script-data-double-escaped-less-than-sign-state">script data double escaped less-than sign
2963: state</a>.</p></dd>
2964:
2965: <dt>EOF</dt>
2966: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2967: <a href="#data-state">data state</a>.</dd>
2968:
2969: <dt>Anything else</dt>
2970: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2971: token. Stay in the <a href="#script-data-double-escaped-state">script data double escaped
2972: state</a>.</dd>
2973:
1.755 mike 2974: </dl><h5 id="script-data-double-escaped-dash-state"><span class="secno">8.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 2975:
2976: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2977:
2978: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2979: <dd>Emit a U+002D HYPHEN-MINUS character token. Switch to the
2980: <a href="#script-data-double-escaped-dash-dash-state">script data double escaped dash dash state</a>.</dd>
2981:
2982: <dt>U+003C LESS-THAN SIGN (<)</dt>
2983: <dd><p>Emit a U+003C LESS-THAN SIGN character token. Switch to the
2984: <a href="#script-data-double-escaped-less-than-sign-state">script data double escaped less-than sign
2985: state</a>.</p></dd>
2986:
2987: <dt>EOF</dt>
2988: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2989: <a href="#data-state">data state</a>.</dd>
2990:
2991: <dt>Anything else</dt>
2992: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
2993: token. Switch to the <a href="#script-data-double-escaped-state">script data double escaped
2994: state</a>.</dd>
2995:
1.755 mike 2996: </dl><h5 id="script-data-double-escaped-dash-dash-state"><span class="secno">8.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 2997:
2998: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2999:
3000: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
3001: <dd>Emit a U+002D HYPHEN-MINUS character token. Stay in the
3002: <a href="#script-data-double-escaped-dash-dash-state">script data double escaped dash dash state</a>.</dd>
3003:
3004: <dt>U+003C LESS-THAN SIGN (<)</dt>
3005: <dd><p>Emit a U+003C LESS-THAN SIGN character token. Switch to the
3006: <a href="#script-data-double-escaped-less-than-sign-state">script data double escaped less-than sign
3007: state</a>.</p></dd>
3008:
3009: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3010: <dd>Emit a U+003E GREATER-THAN SIGN character token. Switch to the
3011: <a href="#script-data-state">script data state</a>.</dd>
3012:
3013: <dt>EOF</dt>
3014: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3015: <a href="#data-state">data state</a>.</dd>
3016:
3017: <dt>Anything else</dt>
3018: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
3019: token. Switch to the <a href="#script-data-double-escaped-state">script data double escaped
3020: state</a>.</dd>
3021:
1.755 mike 3022: </dl><h5 id="script-data-double-escaped-less-than-sign-state"><span class="secno">8.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 3023:
3024: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3025:
3026: <dl class="switch"><dt>U+002F SOLIDUS (/)</dt>
3027: <dd>Emit a U+002F SOLIDUS character token. Set the <var><a href="#temporary-buffer">temporary
3028: buffer</a></var> to the empty string. Switch to the <a href="#script-data-double-escape-end-state">script data
3029: double 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>
3034:
1.755 mike 3035: </dl><h5 id="script-data-double-escape-end-state"><span class="secno">8.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 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: <dt>U+002F SOLIDUS (/)</dt>
3045: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3046: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
3047: 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
3048: escaped state</a>. Otherwise, switch to the <a href="#script-data-double-escaped-state">script data
3049: double escaped state</a>.</dd>
3050:
3051: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
3052: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
3053: token. Append the lowercase version of the <a href="#current-input-character">current input
3054: character</a> (add 0x0020 to the character's code point) to the
3055: <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the <a href="#script-data-double-escape-end-state">script data double
3056: escape end state</a>.</dd>
3057:
3058: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
3059: <dd>Emit the <a href="#current-input-character">current input character</a> as a character
3060: token. Append the <a href="#current-input-character">current input character</a> to the
3061: <var><a href="#temporary-buffer">temporary buffer</a></var>. Stay in the <a href="#script-data-double-escape-end-state">script data double
3062: escape end state</a>.</dd>
3063:
3064: <dt>Anything else</dt>
3065: <dd>Reconsume the <a href="#current-input-character">current input character</a> in the
3066: <a href="#script-data-double-escaped-state">script data double escaped state</a>.</dd>
1.1 mike 3067:
1.755 mike 3068: </dl><h5 id="before-attribute-name-state"><span class="secno">8.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 3069:
3070: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3071:
3072: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3073: <dt>U+000A LINE FEED (LF)</dt>
3074: <dt>U+000C FORM FEED (FF)</dt>
3075: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3076: <dt>U+0020 SPACE</dt>
3077: <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
3078:
3079: <dt>U+002F SOLIDUS (/)</dt>
3080: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
3081:
3082: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3083: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
3084: state</a>.</dd>
3085:
3086: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
3087: <dd>Start a new attribute in the current tag token. Set that
3088: attribute's name to the lowercase version of the <a href="#current-input-character">current input
3089: character</a> (add 0x0020 to the character's code point), and its
3090: value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
3091: state</a>.</dd>
3092:
3093: <dt>U+0022 QUOTATION MARK (")</dt>
3094: <dt>U+0027 APOSTROPHE (')</dt>
3095: <dt>U+003C LESS-THAN SIGN (<)</dt>
3096: <dt>U+003D EQUALS SIGN (=)</dt>
3097: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
3098: entry below.</dd>
3099:
3100: <dt>EOF</dt>
3101: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3102: <a href="#data-state">data state</a>.</dd>
3103:
3104: <dt>Anything else</dt>
3105: <dd>Start a new attribute in the current tag token. Set that
3106: attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
3107: the empty string. Switch to the <a href="#attribute-name-state">attribute name
3108: state</a>.</dd>
3109:
1.755 mike 3110: </dl><h5 id="attribute-name-state"><span class="secno">8.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 3111:
3112: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3113:
3114: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3115: <dt>U+000A LINE FEED (LF)</dt>
3116: <dt>U+000C FORM FEED (FF)</dt>
3117: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3118: <dt>U+0020 SPACE</dt>
3119: <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
3120:
3121: <dt>U+002F SOLIDUS (/)</dt>
3122: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
3123:
3124: <dt>U+003D EQUALS SIGN (=)</dt>
3125: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
3126:
3127: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3128: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
3129: state</a>.</dd>
3130:
3131: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
1.541 mike 3132: <dd>Append the lowercase version of the <a href="#current-input-character">current input
3133: character</a> (add 0x0020 to the character's code point) to the
3134: current attribute's name. Stay in the <a href="#attribute-name-state">attribute name
1.1 mike 3135: state</a>.</dd>
3136:
3137: <dt>U+0022 QUOTATION MARK (")</dt>
3138: <dt>U+0027 APOSTROPHE (')</dt>
3139: <dt>U+003C LESS-THAN SIGN (<)</dt>
3140: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
3141: entry below.</dd>
3142:
3143: <dt>EOF</dt>
3144: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3145: <a href="#data-state">data state</a>.</dd>
3146:
3147: <dt>Anything else</dt>
1.541 mike 3148: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3149: attribute's name. Stay in the <a href="#attribute-name-state">attribute name
3150: state</a>.</dd>
1.1 mike 3151:
3152: </dl><p>When the user agent leaves the attribute name state (and before
3153: emitting the tag token, if appropriate), the complete attribute's
3154: name must be compared to the other attributes on the same token;
3155: if there is already an attribute on the token with the exact same
3156: name, then this is a <a href="#parse-error">parse error</a> and the new
3157: attribute must be dropped, along with the value that gets
3158: associated with it (if any).</p>
3159:
3160:
1.755 mike 3161: <h5 id="after-attribute-name-state"><span class="secno">8.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 3162:
3163: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3164:
3165: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3166: <dt>U+000A LINE FEED (LF)</dt>
3167: <dt>U+000C FORM FEED (FF)</dt>
3168: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3169: <dt>U+0020 SPACE</dt>
3170: <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
3171:
3172: <dt>U+002F SOLIDUS (/)</dt>
3173: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
3174:
3175: <dt>U+003D EQUALS SIGN (=)</dt>
3176: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
3177:
3178: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3179: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
3180: state</a>.</dd>
3181:
3182: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
3183: <dd>Start a new attribute in the current tag token. Set that
1.541 mike 3184: attribute's name to the lowercase version of the <a href="#current-input-character">current
3185: input character</a> (add 0x0020 to the character's code point),
3186: and its value to the empty string. Switch to the <a href="#attribute-name-state">attribute
3187: name state</a>.</dd>
1.1 mike 3188:
3189: <dt>U+0022 QUOTATION MARK (")</dt>
3190: <dt>U+0027 APOSTROPHE (')</dt>
3191: <dt>U+003C LESS-THAN SIGN (<)</dt>
3192: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
3193: entry below.</dd>
3194:
3195: <dt>EOF</dt>
3196: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3197: <a href="#data-state">data state</a>.</dd>
3198:
3199: <dt>Anything else</dt>
3200: <dd>Start a new attribute in the current tag token. Set that
1.541 mike 3201: attribute's name to the <a href="#current-input-character">current input character</a>, and
3202: its value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
1.1 mike 3203: state</a>.</dd>
3204:
1.755 mike 3205: </dl><h5 id="before-attribute-value-state"><span class="secno">8.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 3206:
3207: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3208:
3209: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3210: <dt>U+000A LINE FEED (LF)</dt>
3211: <dt>U+000C FORM FEED (FF)</dt>
3212: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3213: <dt>U+0020 SPACE</dt>
3214: <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
3215:
3216: <dt>U+0022 QUOTATION MARK (")</dt>
3217: <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
3218:
3219: <dt>U+0026 AMPERSAND (&)</dt>
3220: <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
1.541 mike 3221: and reconsume this <a href="#current-input-character">current input character</a>.</dd>
1.1 mike 3222:
3223: <dt>U+0027 APOSTROPHE (')</dt>
3224: <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
3225:
3226: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3227: <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
3228: the <a href="#data-state">data state</a>.</dd>
3229:
3230: <dt>U+003C LESS-THAN SIGN (<)</dt>
3231: <dt>U+003D EQUALS SIGN (=)</dt>
1.463 mike 3232: <dt>U+0060 GRAVE ACCENT (`)</dt>
1.1 mike 3233: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
3234: entry below.</dd>
3235:
3236: <dt>EOF</dt>
3237: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3238: <a href="#data-state">data state</a>.</dd>
3239:
3240: <dt>Anything else</dt>
3241: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3242: attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
3243: state</a>.</dd>
3244:
1.755 mike 3245: </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">8.2.4.38 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
1.1 mike 3246:
3247: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3248:
3249: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
3250: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
3251: state</a>.</dd>
3252:
3253: <dt>U+0026 AMPERSAND (&)</dt>
3254: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
3255: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
3256: being U+0022 QUOTATION MARK (").</dd>
3257:
3258: <dt>EOF</dt>
3259: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3260: <a href="#data-state">data state</a>.</dd>
3261:
3262: <dt>Anything else</dt>
1.541 mike 3263: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3264: attribute's value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value
3265: (double-quoted) state</a>.</dd>
1.1 mike 3266:
1.755 mike 3267: </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">8.2.4.39 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
1.1 mike 3268:
3269: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3270:
3271: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
3272: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
3273: state</a>.</dd>
3274:
3275: <dt>U+0026 AMPERSAND (&)</dt>
3276: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
3277: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
3278: being U+0027 APOSTROPHE (').</dd>
3279:
3280: <dt>EOF</dt>
3281: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3282: <a href="#data-state">data state</a>.</dd>
3283:
3284: <dt>Anything else</dt>
1.541 mike 3285: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3286: attribute's value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value
3287: (single-quoted) state</a>.</dd>
1.1 mike 3288:
1.755 mike 3289: </dl><h5 id="attribute-value-unquoted-state"><span class="secno">8.2.4.40 </span><dfn>Attribute value (unquoted) state</dfn></h5>
1.1 mike 3290:
3291: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3292:
3293: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3294: <dt>U+000A LINE FEED (LF)</dt>
3295: <dt>U+000C FORM FEED (FF)</dt>
3296: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3297: <dt>U+0020 SPACE</dt>
3298: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
3299:
3300: <dt>U+0026 AMPERSAND (&)</dt>
3301: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
1.299 mike 3302: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
3303: being U+003E GREATER-THAN SIGN (>).</dd>
1.1 mike 3304:
3305: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3306: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
3307: state</a>.</dd>
3308:
3309: <dt>U+0022 QUOTATION MARK (")</dt>
3310: <dt>U+0027 APOSTROPHE (')</dt>
3311: <dt>U+003C LESS-THAN SIGN (<)</dt>
3312: <dt>U+003D EQUALS SIGN (=)</dt>
1.463 mike 3313: <dt>U+0060 GRAVE ACCENT (`)</dt>
1.1 mike 3314: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
3315: entry below.</dd>
3316:
3317: <dt>EOF</dt>
3318: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3319: <a href="#data-state">data state</a>.</dd>
3320:
3321: <dt>Anything else</dt>
1.541 mike 3322: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3323: attribute's value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
1.1 mike 3324: state</a>.</dd>
3325:
1.755 mike 3326: </dl><h5 id="character-reference-in-attribute-value-state"><span class="secno">8.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 3327:
3328: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
3329:
3330: <p>If nothing is returned, append a U+0026 AMPERSAND character to
3331: the current attribute's value.</p>
3332:
3333: <p>Otherwise, append the returned character token to the current
3334: attribute's value.</p>
3335:
3336: <p>Finally, switch back to the attribute value state that you were
3337: in when were switched into this state.</p>
3338:
3339:
1.755 mike 3340: <h5 id="after-attribute-value-quoted-state"><span class="secno">8.2.4.42 </span><dfn>After attribute value (quoted) state</dfn></h5>
1.1 mike 3341:
3342: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3343:
3344: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3345: <dt>U+000A LINE FEED (LF)</dt>
3346: <dt>U+000C FORM FEED (FF)</dt>
3347: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3348: <dt>U+0020 SPACE</dt>
3349: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
3350:
3351: <dt>U+002F SOLIDUS (/)</dt>
3352: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
3353:
3354: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3355: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
3356: state</a>.</dd>
3357:
3358: <dt>EOF</dt>
3359: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3360: <a href="#data-state">data state</a>.</dd>
3361:
3362: <dt>Anything else</dt>
3363: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
3364: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
3365:
1.755 mike 3366: </dl><h5 id="self-closing-start-tag-state"><span class="secno">8.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 3367:
3368: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3369:
3370: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
3371: <dd>Set the <i>self-closing flag</i> of the current tag
3372: token. Emit the current tag token. Switch to the <a href="#data-state">data
3373: state</a>.</dd>
3374:
3375: <dt>EOF</dt>
3376: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
3377: <a href="#data-state">data state</a>.</dd>
3378:
3379: <dt>Anything else</dt>
3380: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
3381: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
3382:
1.755 mike 3383: </dl><h5 id="bogus-comment-state"><span class="secno">8.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 3384:
3385: <p>Consume every character up to and including the first U+003E
3386: GREATER-THAN SIGN character (>) or the end of the file (EOF),
3387: whichever comes first. Emit a comment token whose data is the
3388: concatenation of all the characters starting from and including
3389: the character that caused the state machine to switch into the
3390: bogus comment state, up to and including the character immediately
3391: before the last consumed character (i.e. up to the character just
3392: before the U+003E or EOF character). (If the comment was started
3393: by the end of the file (EOF), the token is empty.)</p>
3394:
3395: <p>Switch to the <a href="#data-state">data state</a>.</p>
3396:
3397: <p>If the end of the file was reached, reconsume the EOF
3398: character.</p>
3399:
3400:
1.755 mike 3401: <h5 id="markup-declaration-open-state"><span class="secno">8.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 3402:
1.588 mike 3403: <p>If the next two characters are both U+002D HYPHEN-MINUS
3404: characters (-), consume those two characters, create a comment token
1.1 mike 3405: whose data is the empty string, and switch to the <a href="#comment-start-state">comment
3406: start state</a>.</p>
3407:
3408: <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
3409: case-insensitive</a> match for the word "DOCTYPE", then consume
3410: those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
3411:
3412: <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
3413: content</a>" and the <a href="#current-node">current node</a> is not an element
1.724 mike 3414: in the <a href="infrastructure.html#html-namespace-0">HTML namespace</a> and the next seven characters are
1.585 mike 3415: an <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string "[CDATA[" (the
3416: five uppercase letters "CDATA" with a U+005B LEFT SQUARE BRACKET
3417: character before and after), then consume those characters and
3418: switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1 mike 3419:
3420: <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
3421: <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
3422: consumed, if any, is the first character that will be in the
3423: comment.</p>
3424:
3425:
1.755 mike 3426: <h5 id="comment-start-state"><span class="secno">8.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 3427:
3428: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3429:
3430: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
3431: <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
3432:
3433: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3434: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
3435: <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
3436: -->
3437:
3438: <dt>EOF</dt>
3439: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
3440: the EOF character in the <a href="#data-state">data state</a>.</dd>
3441:
3442: <dt>Anything else</dt>
1.541 mike 3443: <dd>Append the <a href="#current-input-character">current input character</a> to the comment
3444: token's data. Switch to the <a href="#comment-state">comment state</a>.</dd>
1.1 mike 3445:
1.755 mike 3446: </dl><h5 id="comment-start-dash-state"><span class="secno">8.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 3447:
3448: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3449:
3450: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
3451: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
3452:
3453: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3454: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
3455: the <a href="#data-state">data 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.755 mike 3467: </dl><h5 id="comment-state"><span class="secno">8.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 3468:
3469: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3470:
3471: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
3472: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
3473:
3474: <dt>EOF</dt>
3475: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
3476: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
3477: in comment end state -->
3478:
3479: <dt>Anything else</dt>
1.541 mike 3480: <dd>Append the <a href="#current-input-character">current input character</a> to the comment
3481: token's data. Stay in the <a href="#comment-state">comment state</a>.</dd>
1.1 mike 3482:
1.755 mike 3483: </dl><h5 id="comment-end-dash-state"><span class="secno">8.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 3484:
3485: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3486:
3487: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
3488: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
3489:
3490: <dt>EOF</dt>
3491: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
3492: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
3493: in comment end state -->
3494:
3495: <dt>Anything else</dt>
1.541 mike 3496: <dd>Append a U+002D HYPHEN-MINUS character (-) and the
3497: <a href="#current-input-character">current input character</a> to the comment token's
3498: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
1.1 mike 3499:
1.755 mike 3500: </dl><h5 id="comment-end-state"><span class="secno">8.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 3501:
3502: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3503:
3504: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
3505: <dd>Emit the comment token. Switch to the <a href="#data-state">data
3506: state</a>.</dd>
3507:
3508: <dt>U+0009 CHARACTER TABULATION</dt>
3509: <dt>U+000A LINE FEED (LF)</dt>
3510: <dt>U+000C FORM FEED (FF)</dt>
3511: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3512: <dt>U+0020 SPACE</dt>
1.588 mike 3513: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS
3514: characters (-) and the <a href="#current-input-character">current input character</a> to the
1.541 mike 3515: comment token's data. Switch to the <a href="#comment-end-space-state">comment end space
3516: state</a>.</dd>
1.1 mike 3517:
3518: <dt>U+0021 EXCLAMATION MARK (!)</dt>
3519: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
3520: state</a>.</dd>
3521:
1.333 mike 3522: <dt>U+002D HYPHEN-MINUS (-)</dt>
3523: <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
1.464 mike 3524: character (-) to the comment token's data. Stay in the
1.333 mike 3525: <a href="#comment-end-state">comment end state</a>.</dd>
3526:
1.1 mike 3527: <dt>EOF</dt>
3528: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
3529: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
1.724 mike 3530: security reasons: otherwise, hostile user could put a <script type="text/javascript"> in
1.1 mike 3531: a comment e.g. in a blog comment and then DOS the server so that
1.724 mike 3532: the end tag isn't read, and then the commented <script type="text/javascript"> tag would
1.1 mike 3533: be treated as live code -->
3534:
3535: <dt>Anything else</dt>
1.588 mike 3536: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS
3537: characters (-) and the <a href="#current-input-character">current input character</a> to the
1.541 mike 3538: comment token's data. Switch to the <a href="#comment-state">comment
3539: state</a>.</dd>
1.1 mike 3540:
1.755 mike 3541: </dl><h5 id="comment-end-bang-state"><span class="secno">8.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 3542:
3543: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3544:
1.333 mike 3545: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
1.588 mike 3546: <dd>Append two U+002D HYPHEN-MINUS characters (-) and a U+0021
1.464 mike 3547: EXCLAMATION MARK character (!) to the comment token's data. Switch
1.1 mike 3548: to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
3549:
1.333 mike 3550: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3551: <dd>Emit the comment token. Switch to the <a href="#data-state">data
3552: state</a>.</dd>
3553:
1.1 mike 3554: <dt>EOF</dt>
3555: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
3556: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
3557: comment in comment end state -->
3558:
3559: <dt>Anything else</dt>
1.588 mike 3560: <dd>Append two U+002D HYPHEN-MINUS characters (-), a U+0021
1.541 mike 3561: EXCLAMATION MARK character (!), and the <a href="#current-input-character">current input
3562: character</a> to the comment token's data. Switch to the
3563: <a href="#comment-state">comment state</a>.</dd>
1.1 mike 3564:
1.755 mike 3565: </dl><h5 id="comment-end-space-state"><span class="secno">8.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 3566:
3567: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3568:
1.333 mike 3569: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
1.1 mike 3570: <dt>U+000A LINE FEED (LF)</dt>
3571: <dt>U+000C FORM FEED (FF)</dt>
3572: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3573: <dt>U+0020 SPACE</dt>
1.541 mike 3574: <dd>Append the <a href="#current-input-character">current input character</a> to the comment token's data. Stay in
1.1 mike 3575: the <a href="#comment-end-space-state">comment end space state</a>.</dd>
3576:
1.333 mike 3577: <dt>U+002D HYPHEN-MINUS (-)</dt>
3578: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
3579:
3580: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3581: <dd>Emit the comment token. Switch to the <a href="#data-state">data
3582: state</a>.</dd>
3583:
1.1 mike 3584: <dt>EOF</dt>
3585: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
3586: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
3587: comment in comment end state -->
3588:
3589: <dt>Anything else</dt>
1.541 mike 3590: <dd>Append the <a href="#current-input-character">current input character</a> to the comment token's data. Switch
1.1 mike 3591: to the <a href="#comment-state">comment state</a>.</dd>
3592:
1.755 mike 3593: </dl><h5 id="doctype-state"><span class="secno">8.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 3594:
3595: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3596:
3597: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3598: <dt>U+000A LINE FEED (LF)</dt>
3599: <dt>U+000C FORM FEED (FF)</dt>
3600: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3601: <dt>U+0020 SPACE</dt>
3602: <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
3603:
3604: <dt>EOF</dt>
3605: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
3606: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
3607: the EOF character in the <a href="#data-state">data state</a>.</dd>
3608:
3609: <dt>Anything else</dt>
1.608 mike 3610: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in the
3611: <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
1.1 mike 3612:
1.755 mike 3613: </dl><h5 id="before-doctype-name-state"><span class="secno">8.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 3614:
3615: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3616:
3617: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3618: <dt>U+000A LINE FEED (LF)</dt>
3619: <dt>U+000C FORM FEED (FF)</dt>
3620: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3621: <dt>U+0020 SPACE</dt>
3622: <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
3623:
3624: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
3625: <dd>Create a new DOCTYPE token. Set the token's name to the
1.541 mike 3626: lowercase version of the <a href="#current-input-character">current input character</a> (add 0x0020 to the
1.1 mike 3627: character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
3628: state</a>.</dd>
3629:
1.333 mike 3630: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3631: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
3632: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
3633: the <a href="#data-state">data state</a>.</dd>
3634:
1.1 mike 3635: <dt>EOF</dt>
3636: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
3637: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
3638: the EOF character in the <a href="#data-state">data state</a>.</dd>
3639:
3640: <dt>Anything else</dt>
3641: <dd>Create a new DOCTYPE token. Set the token's name to the
3642: <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
3643: state</a>.</dd>
3644:
1.755 mike 3645: </dl><h5 id="doctype-name-state"><span class="secno">8.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 3646:
3647: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3648:
3649: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3650: <dt>U+000A LINE FEED (LF)</dt>
3651: <dt>U+000C FORM FEED (FF)</dt>
3652: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3653: <dt>U+0020 SPACE</dt>
3654: <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
3655:
3656: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3657: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3658: state</a>.</dd>
3659:
3660: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
1.541 mike 3661: <dd>Append the lowercase version of the <a href="#current-input-character">current input
3662: character</a> (add 0x0020 to the character's code point) to the
3663: current DOCTYPE token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name
3664: state</a>.</dd>
1.1 mike 3665:
3666: <dt>EOF</dt>
3667: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3668: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3669: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3670:
3671: <dt>Anything else</dt>
1.541 mike 3672: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3673: DOCTYPE token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name
3674: state</a>.</dd>
1.1 mike 3675:
1.755 mike 3676: </dl><h5 id="after-doctype-name-state"><span class="secno">8.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 3677:
3678: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3679:
3680: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3681: <dt>U+000A LINE FEED (LF)</dt>
3682: <dt>U+000C FORM FEED (FF)</dt>
3683: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3684: <dt>U+0020 SPACE</dt>
3685: <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
3686:
3687: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3688: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3689: state</a>.</dd>
3690:
3691: <dt>EOF</dt>
3692: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3693: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3694: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3695:
3696: <dt>Anything else</dt>
3697: <dd>
3698:
3699: <p>If the six characters starting from the <a href="#current-input-character">current input
3700: character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
3701: for the word "PUBLIC", then consume those characters and switch to
1.444 mike 3702: the <a href="#after-doctype-public-keyword-state">after DOCTYPE public keyword state</a>.</p>
1.1 mike 3703:
3704: <p>Otherwise, if the six characters starting from the
3705: <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
3706: case-insensitive</a> match for the word "SYSTEM", then consume
1.444 mike 3707: those characters and switch to the <a href="#after-doctype-system-keyword-state">after DOCTYPE system
3708: keyword state</a>.</p>
1.1 mike 3709:
3710: <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
3711: DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
3712: the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
3713:
3714: </dd>
3715:
1.755 mike 3716: </dl><h5 id="after-doctype-public-keyword-state"><span class="secno">8.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 3717:
3718: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3719:
3720: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3721: <dt>U+000A LINE FEED (LF)</dt>
3722: <dt>U+000C FORM FEED (FF)</dt>
3723: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3724: <dt>U+0020 SPACE</dt>
3725: <dd>Switch to the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier
3726: state</a>.</dd>
3727:
1.620 mike 3728: <dt>U+0022 QUOTATION MARK (")</dt>
3729: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's public
3730: identifier to the empty string (not missing), then switch to the
3731: <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier (double-quoted) state</a>.</dd>
3732:
3733: <dt>U+0027 APOSTROPHE (')</dt>
3734: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's public
3735: identifier to the empty string (not missing), then switch to the
3736: <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier (single-quoted) state</a>.</dd>
3737:
3738: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3739: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3740: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3741: token. Switch to the <a href="#data-state">data state</a>.</dd>
3742:
1.444 mike 3743: <dt>EOF</dt>
3744: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3745: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3746: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3747:
3748: <dt>Anything else</dt>
1.620 mike 3749: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3750: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3751: DOCTYPE state</a>.</dd>
1.444 mike 3752:
1.755 mike 3753: </dl><h5 id="before-doctype-public-identifier-state"><span class="secno">8.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 3754:
3755: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3756:
3757: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3758: <dt>U+000A LINE FEED (LF)</dt>
3759: <dt>U+000C FORM FEED (FF)</dt>
3760: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3761: <dt>U+0020 SPACE</dt>
3762: <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
3763:
3764: <dt>U+0022 QUOTATION MARK (")</dt>
3765: <dd>Set the DOCTYPE token's public identifier to the empty string
3766: (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
3767: (double-quoted) state</a>.</dd>
3768:
3769: <dt>U+0027 APOSTROPHE (')</dt>
3770: <dd>Set the DOCTYPE token's public identifier to the empty string
3771: (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
3772: (single-quoted) state</a>.</dd>
3773:
3774: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3775: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3776: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3777: token. Switch to the <a href="#data-state">data state</a>.</dd>
3778:
3779: <dt>EOF</dt>
3780: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3781: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3782: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3783:
3784: <dt>Anything else</dt>
3785: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3786: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3787: DOCTYPE state</a>.</dd>
3788:
1.755 mike 3789: </dl><h5 id="doctype-public-identifier-double-quoted-state"><span class="secno">8.2.4.59 </span><dfn>DOCTYPE public identifier (double-quoted) state</dfn></h5>
1.1 mike 3790:
3791: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3792:
3793: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
3794: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
3795:
3796: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3797: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3798: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3799: token. Switch to the <a href="#data-state">data state</a>.</dd>
3800:
3801: <dt>EOF</dt>
3802: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3803: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3804: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3805:
3806: <dt>Anything else</dt>
3807: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3808: token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
3809: identifier (double-quoted) state</a>.</dd>
3810:
1.755 mike 3811: </dl><h5 id="doctype-public-identifier-single-quoted-state"><span class="secno">8.2.4.60 </span><dfn>DOCTYPE public identifier (single-quoted) state</dfn></h5>
1.1 mike 3812:
3813: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3814:
3815: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
3816: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
3817:
3818: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3819: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3820: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3821: token. Switch to the <a href="#data-state">data state</a>.</dd>
3822:
3823: <dt>EOF</dt>
3824: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3825: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3826: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3827:
3828: <dt>Anything else</dt>
3829: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
3830: token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
3831: identifier (single-quoted) state</a>.</dd>
3832:
1.755 mike 3833: </dl><h5 id="after-doctype-public-identifier-state"><span class="secno">8.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 3834:
3835: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3836:
3837: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3838: <dt>U+000A LINE FEED (LF)</dt>
3839: <dt>U+000C FORM FEED (FF)</dt>
3840: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3841: <dt>U+0020 SPACE</dt>
1.541 mike 3842: <dd>Switch to the <a href="#between-doctype-public-and-system-identifiers-state">between DOCTYPE public and system
3843: identifiers state</a>.</dd>
1.444 mike 3844:
3845: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3846: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3847: state</a>.</dd>
3848:
3849: <dt>U+0022 QUOTATION MARK (")</dt>
3850: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
3851: identifier to the empty string (not missing), then switch to the
3852: <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier (double-quoted) state</a>.</dd>
3853:
3854: <dt>U+0027 APOSTROPHE (')</dt>
3855: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
3856: identifier to the empty string (not missing), then switch to the
3857: <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier (single-quoted) state</a>.</dd>
3858:
3859: <dt>EOF</dt>
3860: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3861: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3862: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3863:
3864: <dt>Anything else</dt>
3865: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3866: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3867: DOCTYPE state</a>.</dd>
3868:
1.755 mike 3869: </dl><h5 id="between-doctype-public-and-system-identifiers-state"><span class="secno">8.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 3870:
3871: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3872:
3873: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3874: <dt>U+000A LINE FEED (LF)</dt>
3875: <dt>U+000C FORM FEED (FF)</dt>
3876: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3877: <dt>U+0020 SPACE</dt>
1.541 mike 3878: <dd>Stay in the <a href="#between-doctype-public-and-system-identifiers-state">between DOCTYPE public and system identifiers
3879: state</a>.</dd>
1.444 mike 3880:
3881: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3882: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
3883: state</a>.</dd>
1.1 mike 3884:
3885: <dt>U+0022 QUOTATION MARK (")</dt>
3886: <dd>Set the DOCTYPE token's system identifier to the empty string
3887: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
3888: (double-quoted) state</a>.</dd>
3889:
3890: <dt>U+0027 APOSTROPHE (')</dt>
3891: <dd>Set the DOCTYPE token's system identifier to the empty string
3892: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
3893: (single-quoted) state</a>.</dd>
3894:
3895: <dt>EOF</dt>
3896: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3897: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3898: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3899:
3900: <dt>Anything else</dt>
3901: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3902: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3903: DOCTYPE state</a>.</dd>
3904:
1.755 mike 3905: </dl><h5 id="after-doctype-system-keyword-state"><span class="secno">8.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 3906:
3907: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3908:
3909: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3910: <dt>U+000A LINE FEED (LF)</dt>
3911: <dt>U+000C FORM FEED (FF)</dt>
3912: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3913: <dt>U+0020 SPACE</dt>
3914: <dd>Switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier
3915: state</a>.</dd>
3916:
1.620 mike 3917: <dt>U+0022 QUOTATION MARK (")</dt>
3918: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
3919: identifier to the empty string (not missing), then switch to the
3920: <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier (double-quoted) state</a>.</dd>
3921:
3922: <dt>U+0027 APOSTROPHE (')</dt>
3923: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
3924: identifier to the empty string (not missing), then switch to the
3925: <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier (single-quoted) state</a>.</dd>
3926:
3927: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3928: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3929: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3930: token. Switch to the <a href="#data-state">data state</a>.</dd>
3931:
1.444 mike 3932: <dt>EOF</dt>
3933: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3934: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3935: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3936:
3937: <dt>Anything else</dt>
1.620 mike 3938: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3939: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3940: DOCTYPE state</a>.</dd>
1.444 mike 3941:
1.755 mike 3942: </dl><h5 id="before-doctype-system-identifier-state"><span class="secno">8.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 3943:
3944: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3945:
3946: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3947: <dt>U+000A LINE FEED (LF)</dt>
3948: <dt>U+000C FORM FEED (FF)</dt>
3949: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3950: <dt>U+0020 SPACE</dt>
3951: <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
3952:
3953: <dt>U+0022 QUOTATION MARK (")</dt>
3954: <dd>Set the DOCTYPE token's system identifier to the empty string
3955: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
3956: (double-quoted) state</a>.</dd>
3957:
3958: <dt>U+0027 APOSTROPHE (')</dt>
3959: <dd>Set the DOCTYPE token's system identifier to the empty string
3960: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
3961: (single-quoted) state</a>.</dd>
3962:
3963: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3964: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3965: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3966: token. Switch to the <a href="#data-state">data state</a>.</dd>
3967:
3968: <dt>EOF</dt>
3969: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3970: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3971: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3972:
3973: <dt>Anything else</dt>
3974: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3975: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
3976: DOCTYPE state</a>.</dd>
3977:
1.755 mike 3978: </dl><h5 id="doctype-system-identifier-double-quoted-state"><span class="secno">8.2.4.65 </span><dfn>DOCTYPE system identifier (double-quoted) state</dfn></h5>
1.1 mike 3979:
3980: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
3981:
3982: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
1.541 mike 3983: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier
3984: state</a>.</dd>
1.1 mike 3985:
3986: <dt>U+003E GREATER-THAN SIGN (>)</dt>
3987: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3988: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
3989: token. Switch to the <a href="#data-state">data state</a>.</dd>
3990:
3991: <dt>EOF</dt>
3992: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
3993: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
3994: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
3995:
3996: <dt>Anything else</dt>
1.541 mike 3997: <dd>Append the <a href="#current-input-character">current input character</a> to the current
3998: DOCTYPE token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
1.1 mike 3999: identifier (double-quoted) state</a>.</dd>
4000:
1.755 mike 4001: </dl><h5 id="doctype-system-identifier-single-quoted-state"><span class="secno">8.2.4.66 </span><dfn>DOCTYPE system identifier (single-quoted) state</dfn></h5>
1.1 mike 4002:
4003: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
4004:
4005: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
1.541 mike 4006: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier
4007: state</a>.</dd>
1.1 mike 4008:
4009: <dt>U+003E GREATER-THAN SIGN (>)</dt>
4010: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
4011: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
4012: token. Switch to the <a href="#data-state">data state</a>.</dd>
4013:
4014: <dt>EOF</dt>
4015: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
4016: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
4017: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
4018:
4019: <dt>Anything else</dt>
1.541 mike 4020: <dd>Append the <a href="#current-input-character">current input character</a> to the current
4021: DOCTYPE token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
1.1 mike 4022: identifier (single-quoted) state</a>.</dd>
4023:
1.755 mike 4024: </dl><h5 id="after-doctype-system-identifier-state"><span class="secno">8.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 4025:
4026: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
4027:
4028: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
4029: <dt>U+000A LINE FEED (LF)</dt>
4030: <dt>U+000C FORM FEED (FF)</dt>
4031: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
4032: <dt>U+0020 SPACE</dt>
1.541 mike 4033: <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier
4034: state</a>.</dd>
1.1 mike 4035:
4036: <dt>U+003E GREATER-THAN SIGN (>)</dt>
4037: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
4038: state</a>.</dd>
4039:
4040: <dt>EOF</dt>
4041: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
4042: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
4043: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
4044:
4045: <dt>Anything else</dt>
4046: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
4047: state</a>. (This does <em>not</em> set the DOCTYPE token's
4048: <i>force-quirks flag</i> to <i>on</i>.)</dd>
4049:
1.755 mike 4050: </dl><h5 id="bogus-doctype-state"><span class="secno">8.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 4051:
4052: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
4053:
4054: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
4055: <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
4056: state</a>.</dd>
4057:
4058: <dt>EOF</dt>
4059: <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
4060: <a href="#data-state">data state</a>.</dd>
4061:
4062: <dt>Anything else</dt>
4063: <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
4064:
1.755 mike 4065: </dl><h5 id="cdata-section-state"><span class="secno">8.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 4066:
4067: <p>Consume every character up to the next occurrence of the three
4068: character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
4069: BRACKET U+003E GREATER-THAN SIGN (<code title="">]]></code>), or the
4070: end of the file (EOF), whichever comes first. Emit a series of
4071: character tokens consisting of all the characters consumed except
4072: the matching three character sequence at the end (if one was found
4073: before the end of the file).</p>
4074:
4075: <p>Switch to the <a href="#data-state">data state</a>.</p>
4076:
4077: <p>If the end of the file was reached, reconsume the EOF
4078: character.</p>
4079:
4080:
4081:
1.755 mike 4082: <h5 id="tokenizing-character-references"><span class="secno">8.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 4083:
4084: <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
4085: reference</dfn>. This definition is used when parsing character
1.299 mike 4086: references <a href="#character-reference-in-data-state" title="character reference in data state">in
1.1 mike 4087: text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
4088: state">in attributes</a>.</p>
4089:
4090: <p>The behavior depends on the identity of the next character (the
4091: one immediately after the U+0026 AMPERSAND character):</p>
4092:
4093: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
4094: <dt>U+000A LINE FEED (LF)</dt>
4095: <dt>U+000C FORM FEED (FF)</dt>
4096: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
4097: <dt>U+0020 SPACE</dt>
4098: <dt>U+003C LESS-THAN SIGN</dt>
4099: <dt>U+0026 AMPERSAND</dt>
4100: <dt>EOF</dt>
4101: <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
4102:
4103: <dd>Not a character reference. No characters are consumed, and
4104: nothing is returned. (This is not an error, either.)</dd>
4105:
4106:
4107: <dt>U+0023 NUMBER SIGN (#)</dt>
4108:
4109: <dd>
4110:
4111: <p>Consume the U+0023 NUMBER SIGN.</p>
4112:
4113: <p>The behavior further depends on the character after the U+0023
4114: NUMBER SIGN:</p>
4115:
4116: <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
4117: <dt>U+0058 LATIN CAPITAL LETTER X</dt>
4118:
4119: <dd>
4120:
4121: <p>Consume the X.</p>
4122:
4123: <p>Follow the steps below, but using the range of characters
1.464 mike 4124: U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), U+0061 LATIN
4125: SMALL LETTER A to U+0066 LATIN SMALL LETTER F, and U+0041 LATIN
4126: CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F (in other
4127: words, 0-9, A-F, a-f).</p>
1.1 mike 4128:
4129: <p>When it comes to interpreting the number, interpret it as a
4130: hexadecimal number.</p>
4131:
4132: </dd>
4133:
4134:
4135: <dt>Anything else</dt>
4136:
4137: <dd>
4138:
4139: <p>Follow the steps below, but using the range of characters
1.464 mike 4140: U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9).</p>
1.1 mike 4141:
4142: <p>When it comes to interpreting the number, interpret it as a
4143: decimal number.</p>
4144:
4145: </dd>
4146:
4147: </dl><p>Consume as many characters as match the range of characters
4148: given above.</p>
4149:
4150: <p>If no characters match the range, then don't consume any
4151: characters (and unconsume the U+0023 NUMBER SIGN character and, if
4152: appropriate, the X character). This is a <a href="#parse-error">parse
4153: error</a>; nothing is returned.</p>
4154:
4155: <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
4156: that too. If it isn't, there is a <a href="#parse-error">parse
4157: error</a>.</p>
4158:
4159: <p>If one or more characters match the range, then take them all
4160: and interpret the string of characters as a number (either
4161: hexadecimal or decimal as appropriate).</p>
4162:
4163: <p>If that number is one of the numbers in the first column of the
4164: following table, then this is a <a href="#parse-error">parse error</a>. Find the
4165: row with that number in the first column, and return a character
4166: token for the Unicode character given in the second column of that
4167: row.</p>
4168:
4169: <table><thead><tr><th>Number </th><th colspan="2">Unicode character
4170: </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
4171: </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
1.464 mike 4172: </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN (€)
1.1 mike 4173: </td></tr><tr><td>0x81 </td><td>U+0081 </td><td><control>
1.464 mike 4174: </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK (‚)
4175: </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK (ƒ)
4176: </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK („)
4177: </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS (…)
4178: </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER (†)
4179: </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER (‡)
4180: </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT (ˆ)
4181: </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN (‰)
4182: </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON (Š)
4183: </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK (‹)
4184: </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE (Œ)
1.1 mike 4185: </td></tr><tr><td>0x8D </td><td>U+008D </td><td><control>
1.464 mike 4186: </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON (Ž)
1.1 mike 4187: </td></tr><tr><td>0x8F </td><td>U+008F </td><td><control>
4188: </td></tr><tr><td>0x90 </td><td>U+0090 </td><td><control>
1.464 mike 4189: </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK (‘)
4190: </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK (’)
4191: </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK (“)
4192: </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK (”)
4193: </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET (•)
4194: </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH (–)
4195: </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH (—)
4196: </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE (˜)
4197: </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN (™)
4198: </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON (š)
4199: </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK (›)
4200: </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE (œ)
1.1 mike 4201: </td></tr><tr><td>0x9D </td><td>U+009D </td><td><control>
1.464 mike 4202: </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON (ž)
4203: </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS (Ÿ)
1.315 mike 4204: </td></tr></tbody></table><p>Otherwise, if the number is in the range 0xD800 to 0xDFFF<!--
4205: surrogates not allowed; see the comment in the "preprocessing the
4206: input stream" section for details --> or is greater than 0x10FFFF,
4207: then this is a <a href="#parse-error">parse error</a>. Return a U+FFFD
4208: REPLACEMENT CHARACTER.</p>
1.18 mike 4209:
4210: <p>Otherwise, return a character token for the Unicode character
1.1 mike 4211: whose code point is that number.
4212:
4213: <!-- this is the same as the equivalent list in the input stream
4214: section -->
4215: If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
4216: allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
4217: allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
1.315 mike 4218: 0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xFDD0 to
4219: 0xFDEF, or is one of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF,
4220: 0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE,
4221: 0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF,
4222: 0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE,
4223: 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF,
4224: 0x10FFFE, or 0x10FFFF, then this is a <a href="#parse-error">parse
4225: error</a>.</p>
1.1 mike 4226:
4227: </dd>
4228:
4229:
4230: <dt>Anything else</dt>
4231:
4232: <dd>
4233:
4234: <p>Consume the maximum number of characters possible, with the
4235: consumed characters matching one of the identifiers in the first
4236: column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
4237: <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
4238:
4239: <p>If no match can be made, then this is a <a href="#parse-error">parse
4240: error</a>. No characters are consumed, and nothing is
4241: returned.</p>
4242:
1.588 mike 4243: <p>If the last character matched is not a U+003B SEMICOLON
4244: character (;), there is a <a href="#parse-error">parse error</a>.</p>
1.1 mike 4245:
4246: <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
4247: attribute</a>, and the last character matched is not a U+003B
1.588 mike 4248: SEMICOLON character (;), and the next character is in the range
4249: U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), U+0041 LATIN
4250: CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z, or U+0061 LATIN
4251: SMALL LETTER A to U+007A LATIN SMALL LETTER Z, then, for
4252: historical reasons, all the characters that were matched after the
4253: U+0026 AMPERSAND character (&) must be unconsumed, and nothing
4254: is returned.</p>
1.1 mike 4255:
4256: <p>Otherwise, return a character token for the character
4257: corresponding to the character reference name (as given by the
4258: second column of the <a href="named-character-references.html#named-character-references">named character references</a>
4259: table).</p>
4260:
4261: <div class="example">
4262:
4263: <p>If the markup contains <code title="">I'm &notit; I tell
4264: you</code>, the character reference is parsed as "not", as in,
4265: <code title="">I'm ¬it; I tell you</code>. But if the markup
4266: was <code title="">I'm &notin; I tell you</code>, the
4267: character reference would be parsed as "notin;", resulting in
4268: <code title="">I'm ∉ I tell you</code>.</p>
4269:
4270: </div>
4271:
4272: </dd>
4273:
1.266 mike 4274: </dl></div><div class="impl">
4275:
1.363 mike 4276: <!-- v2: One thing that this doesn't define is handling deeply
4277: nested documents. There are compatibility requirements around that:
4278: you can't throw away the elements altogether, consider Tux made only
4279: with opening <font> elements, one per character. Seems that the best
4280: thing to do is to close some formatting elements from the middle of
4281: the stack when you hit a limit, or something. -->
4282:
1.755 mike 4283: <h4 id="tree-construction"><span class="secno">8.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 4284:
4285: <p>The input to the tree construction stage is a sequence of tokens
4286: from the <a href="#tokenization">tokenization</a> stage. The tree construction
1.810 mike 4287: stage is associated with a DOM <code><a href="infrastructure.html#document">Document</a></code> object when a
1.1 mike 4288: parser is created. The "output" of this stage consists of
4289: dynamically modifying or extending that document's DOM tree.</p>
4290:
4291: <p>This specification does not define when an interactive user agent
1.810 mike 4292: has to render the <code><a href="infrastructure.html#document">Document</a></code> so that it is available to
1.1 mike 4293: the user, or when it has to begin accepting user input.</p>
4294:
4295: <p>As each token is emitted from the tokenizer, the user agent must
4296: process the token according to the rules given in the section
4297: corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
4298:
4299: <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
4300: character</dfn> into a node, if that node has a child immediately
4301: before where the character is to be inserted, and that child is a
4302: <code>Text</code> node, and that <code>Text</code> node was the last
4303: node that the parser inserted into the document, then the character
4304: must be appended to that <code>Text</code> node; otherwise, a new
4305: <code>Text</code> node whose data is just that character must be
4306: inserted in the appropriate place.</p>
4307:
4308: <div class="example">
4309:
4310: <p>Here are some sample inputs to the parser and the corresponding
4311: number of text nodes that they result in, assuming a user agent
4312: that executes scripts.</p>
4313:
4314: <table><thead><tr><th>Input </th><th>Number of text nodes
4315: </th></tr></thead><tbody><tr><td><pre>A<script>
4316: var script = document.getElementsByTagName('script')[0];
4317: document.body.removeChild(script);
4318: </script>B</pre>
4319: </td><td>Two adjacent text nodes in the document, containing "A" and "B".
4320: </td></tr><tr><td><pre>A<script>
4321: var text = document.createTextNode('B');
4322: document.body.appendChild(text);
4323: </script>C</pre>
4324: </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
4325: </td></tr><tr><td><pre>A<script>
4326: var text = document.getElementsByTagName('script')[0].firstChild;
4327: text.data = 'B';
4328: document.body.appendChild(text);
4329: </script>B</pre>
4330: </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
4331: </td></tr><tr><td><pre>A<table>B<tr>C</tr>C</table></pre>
4332: </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>.)
4333: </td></tr><tr><td><pre>A<table><tr> B</tr> B</table></pre>
4334: </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>.)
4335: </td></tr><tr><td><pre>A<table><tr> B</tr> </em>C</table></pre>
4336: </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.)
4337: </td></tr></tbody></table></div>
4338:
4339: <p id="mutation-during-parsing">DOM mutation events must not fire
4340: for changes caused by the UA parsing the document. (Conceptually,
4341: the parser is not mutating the DOM, it is constructing it.) This
1.159 mike 4342: 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 4343:
4344: <p class="note">Not all of the tag names mentioned below are
4345: conformant tag names in this specification; many are included to
4346: handle legacy content. They still form part of the algorithm that
4347: implementations are required to implement to claim conformance.</p>
4348:
4349: <p class="note">The algorithm described below places no limit on the
4350: depth of the DOM tree generated, or on the length of tag names,
4351: attribute names, attribute values, text nodes, etc. While
4352: implementors are encouraged to avoid arbitrary limits, it is
4353: recognized that <a href="infrastructure.html#hardwareLimitations">practical
1.445 mike 4354: concerns</a> will likely force user agents to impose nesting depth
4355: constraints.</p>
1.1 mike 4356:
4357:
1.755 mike 4358: <h5 id="creating-and-inserting-elements"><span class="secno">8.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 4359:
4360: <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
4361: element for the token">create an element for a token</dfn> in a
4362: particular namespace, the UA must create a node implementing the
4363: interface appropriate for the element type corresponding to the tag
4364: name of the token in the given namespace (as given in the
4365: specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
1.724 mike 4366: element in the <a href="infrastructure.html#html-namespace-0">HTML namespace</a>, this specification
1.1 mike 4367: defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
4368: the tag name being the name of that element, with the node being in
4369: the given namespace, and with the attributes on the node being those
4370: given in the given token.</p>
4371:
1.724 mike 4372: <p>The interface appropriate for an element in the <a href="infrastructure.html#html-namespace-0">HTML
1.426 mike 4373: namespace</a> that is not defined in this specification (or
4374: <a href="infrastructure.html#other-applicable-specifications">other applicable specifications</a>) is
1.44 mike 4375: <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1 mike 4376: interface is not defined by that namespace's specification must use
1.810 mike 4377: the interface <code><a href="infrastructure.html#element">Element</a></code>.</p>
1.1 mike 4378:
4379: <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
4380: created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
4381: invoked once the attributes are set. (This initializes the element's
4382: <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
4383: attributes.)</p>
4384:
4385: <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
4386: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
1.724 mike 4387: for the token</a> in the <a href="infrastructure.html#html-namespace-0">HTML namespace</a>, and then
1.1 mike 4388: append this node to the <a href="#current-node">current node</a>, and push it onto
4389: the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
4390: <a href="#current-node">current node</a>.</p>
4391:
4392: <p>The steps below may also require that the UA insert an HTML
4393: element in a particular place, in which case the UA must follow the
4394: same steps except that it must insert or append the new node in the
4395: location specified instead of appending it to the <a href="#current-node">current
4396: node</a>. (This happens in particular during the parsing of
4397: tables with invalid content.)</p>
4398:
4399: <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
4400: algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
4401: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
4402: 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
4403: <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
4404: created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
4405: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
4406: inserting it wherever it is to be inserted.</p>
4407:
4408: <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
4409: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
4410: for the token</a> in the given namespace, and then append this
4411: node to the <a href="#current-node">current node</a>, and push it onto the
4412: <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
1.724 mike 4413: <a href="#current-node">current node</a>. If the newly created element has an <code title="">xmlns</code> attribute in the <a href="infrastructure.html#xmlns-namespace">XMLNS namespace</a>
1.1 mike 4414: whose value is not exactly the same as the element's namespace, that
4415: is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
4416: element has an <code title="">xmlns:xlink</code> attribute in the
1.724 mike 4417: <a href="infrastructure.html#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="infrastructure.html#xlink-namespace">XLink
1.1 mike 4418: Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
4419:
4420: <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
4421: attributes</dfn> for a token, then, if the token has an attribute
4422: named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
4423:
4424: <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
4425: attributes</dfn> for a token, then, for each attribute on the token
4426: whose attribute name is one of the ones in the first column of the
4427: following table, change the attribute's name to the name given in
4428: the corresponding cell in the second column. (This fixes the case of
4429: SVG attributes that are not all lowercase.)</p>
4430:
4431: <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
4432: </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
4433: </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
4434: </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
4435: </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
4436: </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
4437: </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
4438: </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
4439: </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
4440: </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
4441: </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
4442: </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
4443: </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
4444: </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
4445: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
4446: </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
4447: </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
4448: </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
4449: </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
4450: </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
4451: </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
4452: </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
4453: </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
4454: </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
4455: </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
4456: </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
4457: </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
4458: </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
4459: </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
4460: </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
4461: </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
4462: </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
4463: </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
4464: </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
4465: </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
4466: </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
4467: </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
4468: </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
4469: </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
4470: </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
4471: </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
4472: </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
4473: </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
4474: </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
4475: </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
4476: </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
4477: </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
4478: </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
4479: </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
4480: </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
4481: </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
4482: </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
4483: </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
4484: </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
4485: </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
4486: </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
4487: </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
4488: </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
4489: </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
4490: </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
4491: </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
4492: </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
4493: </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
4494: </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
4495: foreign attributes</dfn> for a token, then, if any of the attributes
4496: on the token match the strings given in the first column of the
4497: following table, let the attribute be a namespaced attribute, with
4498: the prefix being the string given in the corresponding cell in the
4499: second column, the local name being the string given in the
4500: corresponding cell in the third column, and the namespace being the
4501: namespace given in the corresponding cell in the fourth
4502: column. (This fixes the use of namespaced attributes, in particular
4503: <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
4504: the <span>XML namespace</span></a>.)</p>
4505:
4506: <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
1.724 mike 4507: </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="infrastructure.html#xlink-namespace">XLink namespace</a>
4508: </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="infrastructure.html#xlink-namespace">XLink namespace</a>
4509: </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="infrastructure.html#xlink-namespace">XLink namespace</a>
4510: </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="infrastructure.html#xlink-namespace">XLink namespace</a>
4511: </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="infrastructure.html#xlink-namespace">XLink namespace</a>
4512: </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="infrastructure.html#xlink-namespace">XLink namespace</a>
4513: </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="infrastructure.html#xlink-namespace">XLink namespace</a>
4514: </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="infrastructure.html#xml-namespace">XML namespace</a> <!-- attr-xml-base -->
4515: </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="infrastructure.html#xml-namespace">XML namespace</a>
4516: </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="infrastructure.html#xml-namespace">XML namespace</a>
4517: </td></tr><tr><td> <code title="">xmlns</code> </td><td> (none) </td><td> <code title="">xmlns</code> </td><td> <a href="infrastructure.html#xmlns-namespace">XMLNS namespace</a>
4518: </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="infrastructure.html#xmlns-namespace">XMLNS namespace</a>
1.91 mike 4519: </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 4520: <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
4521: following steps. These algorithms are always invoked in response to
4522: a start tag token.</p>
4523:
4524: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
4525:
1.91 mike 4526: <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
1.541 mike 4527: text element parsing algorithm</a>, switch the tokenizer to the
4528: <a href="#rawtext-state">RAWTEXT state</a>; otherwise the algorithm invoked
4529: was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>,
4530: switch the tokenizer to the <a href="#rcdata-state">RCDATA state</a>.</p></li>
1.1 mike 4531:
4532: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
4533: <a href="#insertion-mode">insertion mode</a>.</p>
4534:
1.540 mike 4535: </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 4536:
1.755 mike 4537: </ol><h5 id="closing-elements-that-have-implied-end-tags"><span class="secno">8.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 4538:
4539: <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
4540: tags</dfn>, then, while the <a href="#current-node">current node</a> is a
1.422 mike 4541: <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 4542: <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
4543: <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
4544: <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
4545: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4546: elements</a>.</p>
4547:
4548: <p>If a step requires the UA to generate implied end tags but lists
4549: an element to exclude from the process, then the UA must perform the
4550: above steps as if that element was not in the above list.</p>
4551:
4552:
1.755 mike 4553: <h5 id="foster-parenting"><span class="secno">8.2.5.3 </span>Foster parenting</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 4554:
4555: <p>Foster parenting happens when content is misnested in tables.</p>
4556:
4557: <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
4558: parent">foster parented</dfn>, the node <var title="">node</var>
4559: must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
4560:
4561: <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
4562: 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
4563: elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
4564: such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
4565: the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
4566: case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
4567: element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
1.159 mike 4568: <code><a href="semantics.html#the-html-element-0">html</a></code> element). Otherwise, if there is a
1.1 mike 4569: <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
4570: elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
4571: <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
4572: node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
4573: the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
4574: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
4575:
4576: <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
4577: 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
4578: elements</a>, then <var title="">node</var> must be inserted
4579: immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
4580: the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
4581: element</a></i>; otherwise, <var title="">node</var> must be
4582: <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
4583:
4584:
4585:
1.755 mike 4586: <h5 id="the-initial-insertion-mode"><span class="secno">8.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 4587:
4588: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
4589: mode: initial">initial</a>", tokens must be handled as follows:</p>
4590:
4591: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4592: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4593: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4594: <dd>
4595: <p>Ignore the token.</p>
4596: </dd>
4597:
4598: <dt>A comment token</dt>
4599: <dd>
1.810 mike 4600: <p>Append a <code>Comment</code> node to the <code><a href="infrastructure.html#document">Document</a></code>
1.1 mike 4601: object with the <code title="">data</code> attribute set to the
4602: data given in the comment token.</p>
4603: </dd>
4604:
4605: <dt>A DOCTYPE token</dt>
4606: <dd>
4607:
4608: <p>If the DOCTYPE token's name is not a
4609: <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
4610: missing, or the token's system identifier is neither missing nor a
4611: <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
1.465 mike 4612: "<code><a href="infrastructure.html#about:legacy-compat">about:legacy-compat</a></code>", and none of the sets of
1.1 mike 4613: conditions in the following list are matched, then there is a
4614: <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
4615: following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
4616: permitted DOCTYPE</dfn>.</p>
4617:
4618: <ul><!-- only things that trigger no-quirks mode and were valid in
1.688 mike 4619: some other spec are allowed in this list --><li>The DOCTYPE token's name is a <a href="infrastructure.html#case-sensitive">case-sensitive</a>
4620: match for the string "<code title="">html</code>", the token's
4621: public identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a> string
4622: "<code title="">-//W3C//DTD HTML 4.0//EN</code>", and
4623: the token's system identifier is either missing or the
1.1 mike 4624: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
4625:
1.688 mike 4626: <li>The DOCTYPE token's name is a <a href="infrastructure.html#case-sensitive">case-sensitive</a>
4627: match for the string "<code title="">html</code>", the token's
4628: public identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a> string
4629: "<code title="">-//W3C//DTD HTML 4.01//EN</code>", and
4630: the token's system identifier is either missing or the
1.1 mike 4631: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
4632:
1.688 mike 4633: <li>The DOCTYPE token's name is a <a href="infrastructure.html#case-sensitive">case-sensitive</a>
4634: match for the string "<code title="">html</code>", the token's
4635: public identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a> string
4636: "<code title="">-//W3C//DTD XHTML 1.0 Strict//EN</code>",
1.1 mike 4637: and the token's system identifier is the
4638: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
4639:
1.688 mike 4640: <li>The DOCTYPE token's name is a <a href="infrastructure.html#case-sensitive">case-sensitive</a>
4641: match for the string "<code title="">html</code>", the token's
4642: public identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a> string
4643: "<code title="">-//W3C//DTD XHTML 1.1//EN</code>", and
4644: the token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
1.1 mike 4645: string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
4646:
4647: </ul><p>Conformance checkers may, based on the values (including
4648: presence or lack thereof) of the DOCTYPE token's name, public
4649: identifier, or system identifier, switch to a conformance checking
4650: mode for another language (e.g. based on the DOCTYPE token a
4651: conformance checker could recognize that the document is an
1.183 mike 4652: HTML4-era document, and defer to an HTML4 conformance
1.1 mike 4653: checker.)</p>
4654:
4655: <p>Append a <code>DocumentType</code> node to the
1.810 mike 4656: <code><a href="infrastructure.html#document">Document</a></code> node, with the <code title="">name</code>
1.1 mike 4657: attribute set to the name given in the DOCTYPE token, or the empty
4658: string if the name was missing; the <code title="">publicId</code>
4659: attribute set to the public identifier given in the DOCTYPE token,
4660: or the empty string if the public identifier was missing; the
4661: <code title="">systemId</code> attribute set to the system
4662: identifier given in the DOCTYPE token, or the empty string if the
4663: system identifier was missing; and the other attributes specific
4664: to <code>DocumentType</code> objects set to null and empty lists
4665: as appropriate. Associate the <code>DocumentType</code> node with
1.810 mike 4666: the <code><a href="infrastructure.html#document">Document</a></code> object so that it is returned as the
1.1 mike 4667: value of the <code title="">doctype</code> attribute of the
1.810 mike 4668: <code><a href="infrastructure.html#document">Document</a></code> object.</p>
1.1 mike 4669:
4670: <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
4671: one of the conditions in the following list, then set the
1.810 mike 4672: <code><a href="infrastructure.html#document">Document</a></code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
1.1 mike 4673:
4674: <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
1.688 mike 4675: <li> The name is set to anything other than "<code title="">html</code>" (compared <a href="infrastructure.html#case-sensitive" title="case-sensitive">case-sensitively</a>). </li>
1.1 mike 4676: <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
4677: <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
4678: <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
4679: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
4680: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
4681: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
4682: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
4683: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
4684: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
4685: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
4686: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
4687: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
4688: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
4689: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
4690: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
4691: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
4692: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
4693: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
4694: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
4695: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
4696: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
4697: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
4698: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
4699: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
4700: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
4701: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
4702: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
4703: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
4704: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
4705: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
4706: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
4707: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
4708: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
4709: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
4710: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
4711: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
4712: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
4713: <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
4714: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
4715: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
4716: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
4717: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
4718: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
4719: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
4720: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
4721: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
4722: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
4723: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
4724: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
4725: <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
4726: <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
4727: <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
4728: <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
4729: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
4730: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
4731: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
4732: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
4733: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
4734: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
4735: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
4736: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
4737: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
4738: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
4739: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
4740: <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
4741: <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
4742: <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
4743: <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
4744: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
4745: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
4746: <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
4747: <li> The public identifier is set to: "<code title="">HTML</code>" </li>
4748: <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
4749: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
4750: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
4751: </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
1.810 mike 4752: in the following list, then set the <code><a href="infrastructure.html#document">Document</a></code> to
1.1 mike 4753: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
4754:
4755: <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
4756: <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
4757: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
4758: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
1.688 mike 4759: </ul><p>The system identifier and public identifier strings must be
4760: compared to the values given in the lists above in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
4761: case-insensitive</a> manner. A system identifier whose value is
4762: the empty string is not considered missing for the purposes of the
4763: conditions above.</p>
1.1 mike 4764:
4765: <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>
4766:
4767: </dd>
4768:
4769: <dt>Anything else</dt>
4770: <dd>
4771:
1.727 mike 4772: <p>If the document is <em>not</em> <a href="text-level-semantics.html#an-iframe-srcdoc-document">an <code>iframe</code>
4773: <code title="attr-iframe-srcdoc">srcdoc</code> document</a>,
4774: then this is a <a href="#parse-error">parse error</a>; set the
1.810 mike 4775: <code><a href="infrastructure.html#document">Document</a></code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
1.1 mike 4776:
1.727 mike 4777: <p>In any case, 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
1.1 mike 4778: reprocess the current token.</p>
4779:
4780: </dd>
4781:
1.755 mike 4782: </dl><h5 id="the-before-html-insertion-mode"><span class="secno">8.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 4783:
4784: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
4785: mode: before html">before html</a>", tokens must be handled as follows:</p>
4786:
4787: <dl class="switch"><dt>A DOCTYPE token</dt>
4788: <dd>
4789: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4790: </dd>
4791:
4792: <dt>A comment token</dt>
4793: <dd>
1.810 mike 4794: <p>Append a <code>Comment</code> node to the <code><a href="infrastructure.html#document">Document</a></code>
1.1 mike 4795: object with the <code title="">data</code> attribute set to the
4796: data given in the comment token.</p>
4797: </dd>
4798:
4799: <dt>A character token that is one of U+0009 CHARACTER
4800: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4801: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4802: <dd>
4803: <p>Ignore the token.</p>
4804: </dd>
4805:
4806: <dt>A start tag whose tag name is "html"</dt>
4807: <dd>
4808:
1.724 mike 4809: <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="infrastructure.html#html-namespace-0">HTML
1.810 mike 4810: namespace</a>. Append it to the <code><a href="infrastructure.html#document">Document</a></code>
1.1 mike 4811: object. Put this element in the <a href="#stack-of-open-elements">stack of open
4812: elements</a>.</p>
4813:
1.810 mike 4814: <p id="parser-appcache">If the <code><a href="infrastructure.html#document">Document</a></code> is being
1.1 mike 4815: loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
4816: <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
4817: has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
4818: then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
4819: attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
4820: 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 4821: algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
4822: any <a href="infrastructure.html#url-fragment" title="url-fragment"><fragment></a> component
4823: removed; otherwise, if there is no such attribute or resolving it
4824: fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
4825: cache selection algorithm</a> with no manifest. The algorithm
1.810 mike 4826: must be passed the <code><a href="infrastructure.html#document">Document</a></code> object.</p>
1.1 mike 4827:
4828: <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>
4829:
4830: </dd>
4831:
1.334 mike 4832: <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
4833: <dd>
4834: <p>Act as described in the "anything else" entry below.</p>
4835: </dd>
4836:
4837: <dt>Any other end tag</dt>
4838: <dd>
4839: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4840: </dd>
4841:
1.1 mike 4842: <dt>Anything else</dt>
4843: <dd>
4844:
1.159 mike 4845: <p>Create an <code><a href="semantics.html#the-html-element-0">html</a></code> element. Append it to the
1.810 mike 4846: <code><a href="infrastructure.html#document">Document</a></code> object. Put this element in the <a href="#stack-of-open-elements">stack
1.1 mike 4847: of open elements</a>.</p>
4848:
1.810 mike 4849: <p>If the <code><a href="infrastructure.html#document">Document</a></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
1.1 mike 4850: context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
4851: algorithm</a> with no manifest, passing it the
1.810 mike 4852: <code><a href="infrastructure.html#document">Document</a></code> object.</p>
1.1 mike 4853:
4854: <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
4855: reprocess the current token.</p>
4856:
4857: </dd>
4858:
4859: </dl><p>The root element can end up being removed from the
1.810 mike 4860: <code><a href="infrastructure.html#document">Document</a></code> object, e.g. by scripts; nothing in particular
1.1 mike 4861: happens in such cases, content continues being appended to the nodes
4862: as described in the next section.</p>
4863:
4864:
1.755 mike 4865: <h5 id="the-before-head-insertion-mode"><span class="secno">8.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 4866:
4867: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
4868: mode: before head">before head</a>", tokens must be handled as follows:</p>
4869:
4870: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4871: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4872: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4873: <dd>
4874: <p>Ignore the token.</p> <!-- :-( -->
4875: </dd>
4876:
4877: <dt>A comment token</dt>
4878: <dd>
4879: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4880: node</a> with the <code title="">data</code> attribute set to
4881: the data given in the comment token.</p>
4882: </dd>
4883:
4884: <dt>A DOCTYPE token</dt>
4885: <dd>
4886: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4887: </dd>
4888:
4889: <dt>A start tag whose tag name is "html"</dt>
4890: <dd>
4891: <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
4892: mode</a>.</p>
4893: </dd>
4894:
4895: <dt>A start tag whose tag name is "head"</dt>
4896: <dd>
4897:
4898: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4899:
4900: <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
1.159 mike 4901: to the newly created <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 4902:
4903: <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>
4904:
4905: </dd>
4906:
4907: <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
4908: <dd>
4909:
4910: <p>Act as if a start tag token with the tag name "head" and no
4911: attributes had been seen, then reprocess the current token.</p>
4912:
4913: </dd>
4914:
4915: <dt>Any other end tag</dt>
4916: <dd>
4917:
4918: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4919:
4920: </dd>
4921:
4922: <dt>Anything else</dt>
4923: <dd>
4924:
4925: <p>Act as if a start tag token with the tag name "head" and no
4926: attributes had been seen, then reprocess the current
4927: token.</p>
4928:
4929: </dd>
4930:
1.755 mike 4931: </dl><h5 id="parsing-main-inhead"><span class="secno">8.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 4932:
4933: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
4934: mode: in head">in head</a>", tokens must be handled as follows:</p>
4935:
4936: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4937: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4938: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4939: <dd>
4940: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
4941: the <a href="#current-node">current node</a>.</p>
4942: </dd>
4943:
4944: <dt>A comment token</dt>
4945: <dd>
4946: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4947: node</a> with the <code title="">data</code> attribute set to
4948: the data given in the comment token.</p>
4949: </dd>
4950:
4951: <dt>A DOCTYPE token</dt>
4952: <dd>
4953: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4954: </dd>
4955:
4956: <dt>A start tag whose tag name is "html"</dt>
4957: <dd>
4958: <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
4959: mode</a>.</p>
4960: </dd>
4961:
4962: <dt>A start tag whose tag name is one of: "base", "command",
4963: "link"</dt>
4964: <dd>
4965:
4966: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4967: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4968: elements</a>.</p>
4969:
4970: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4971: token's <i>self-closing flag</i></a>, if it is set.</p>
4972:
4973: </dd>
4974:
4975: <dt>A start tag whose tag name is "meta"</dt>
4976: <dd>
4977:
4978: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4979: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4980: elements</a>.</p>
4981:
4982: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4983: token's <i>self-closing flag</i></a>, if it is set.</p>
4984:
4985: <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
4986: value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
4987: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
4988: encoding</a> to the encoding given by the value of the
4989: <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
4990:
4991: <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
4992: applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
4993: Content-Type</a> to its value returns a supported encoding
4994: <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
4995: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
4996: encoding</a> to the encoding <var title="">encoding</var>.</p>
4997:
4998: </dd>
4999:
5000: <dt>A start tag whose tag name is "title"</dt>
5001: <dd>
5002: <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
5003: </dd>
5004:
5005: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
5006: <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
5007: <dd>
1.91 mike 5008: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5009: </dd>
5010:
5011: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
5012: <dd>
5013:
5014: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5015:
5016: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
5017: noscript</a>".</p>
5018:
5019: </dd>
5020:
5021: <dt id="scriptTag">A start tag whose tag name is "script"</dt>
5022: <dd>
5023:
5024: <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
1.724 mike 5025: <a href="infrastructure.html#html-namespace-0">HTML namespace</a>.</p></li>
1.1 mike 5026:
5027: <li>
5028:
5029: <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
5030:
5031: <p class="note">This ensures that, if the script is external,
1.159 mike 5032: any <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>
1.1 mike 5033: calls in the script will execute in-line, instead of blowing the
5034: document away, as would happen in most other cases. It also
5035: prevents the script from executing until the end tag is
5036: seen.</p>
5037:
5038: </li>
5039:
5040: <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
5041: fragment parsing algorithm</a>, then mark the
1.484 mike 5042: <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-started">"already
5043: started"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
1.1 mike 5044:
5045: <li><p>Append the new element to the <a href="#current-node">current node</a>
5046: and push it onto the <a href="#stack-of-open-elements">stack of open
5047: elements</a>.</p></li>
5048:
1.541 mike 5049: <li><p>Switch the tokenizer to the <a href="#script-data-state">script data
5050: state</a>.</p></li>
1.1 mike 5051:
5052: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
5053: <a href="#insertion-mode">insertion mode</a>.</p>
5054:
1.540 mike 5055: </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 5056:
5057: </ol></dd>
5058:
5059: <dt>An end tag whose tag name is "head"</dt>
5060: <dd>
5061:
5062: <p>Pop the <a href="#current-node">current node</a> (which will be the
1.159 mike 5063: <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 5064: elements</a>.</p>
5065:
5066: <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>
5067:
5068: </dd>
5069:
5070: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
5071: <dd>
5072: <p>Act as described in the "anything else" entry below.</p>
5073: </dd>
5074:
5075: <dt>A start tag whose tag name is "head"</dt>
5076: <dt>Any other end tag</dt>
5077: <dd>
5078: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5079: </dd>
5080:
5081: <dt>Anything else</dt>
5082: <dd>
5083:
5084: <!-- can't get here with an EOF and a fragment case -->
5085:
5086: <p>Act as if an end tag token with the tag name "head" had
5087: been seen, and reprocess the current token.</p>
5088:
5089: </dd>
5090:
1.755 mike 5091: </dl><h5 id="parsing-main-inheadnoscript"><span class="secno">8.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 5092:
5093: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
5094: mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
5095:
5096: <dl class="switch"><dt>A DOCTYPE token</dt>
5097: <dd>
5098: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5099: </dd>
5100:
5101: <dt>A start tag whose tag name is "html"</dt>
5102: <dd>
5103: <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
5104: mode</a>.</p>
5105: </dd>
5106:
5107: <dt>An end tag whose tag name is "noscript"</dt>
5108: <dd>
5109:
5110: <p>Pop the <a href="#current-node">current node</a> (which will be a
5111: <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
5112: elements</a>; the new <a href="#current-node">current node</a> will be a
1.159 mike 5113: <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1 mike 5114:
5115: <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>
5116:
5117: </dd>
5118:
5119: <dt>A character token that is one of U+0009 CHARACTER
5120: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
5121: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
5122: <dt>A comment token</dt>
5123: <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
5124: <dd>
5125: <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
5126: mode</a>.</p>
5127: </dd>
5128:
5129: <dt>An end tag whose tag name is "br"</dt>
5130: <dd>
5131: <p>Act as described in the "anything else" entry below.</p>
5132: </dd>
5133:
5134: <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
5135: <dt>Any other end tag</dt>
5136: <dd>
5137: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5138: </dd>
5139:
5140: <dt>Anything else</dt>
5141: <dd>
5142:
5143: <!-- can't get here with an EOF and a fragment case -->
5144:
5145: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
5146: name "noscript" had been seen and reprocess the current
5147: token.</p>
5148:
5149: </dd>
5150:
1.755 mike 5151: </dl><h5 id="the-after-head-insertion-mode"><span class="secno">8.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 5152:
5153: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
5154: mode: after head">after head</a>", tokens must be handled as follows:</p>
5155:
5156: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
5157: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
5158: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
5159: <dd>
5160: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
5161: the <a href="#current-node">current node</a>.</p>
5162: </dd>
5163:
5164: <dt>A comment token</dt>
5165: <dd>
5166: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
5167: node</a> with the <code title="">data</code> attribute set to
5168: the data given in the comment token.</p>
5169: </dd>
5170:
5171: <dt>A DOCTYPE token</dt>
5172: <dd>
5173: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5174: </dd>
5175:
5176: <dt>A start tag whose tag name is "html"</dt>
5177: <dd>
5178: <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
5179: mode</a>.</p>
5180: </dd>
5181:
5182: <dt>A start tag whose tag name is "body"</dt>
5183: <dd>
5184:
5185: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5186:
5187: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5188:
5189: <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>
5190:
5191: </dd>
5192:
5193: <dt>A start tag whose tag name is "frameset"</dt>
5194: <dd>
5195:
5196: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5197:
5198: <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>
5199:
5200: </dd>
5201:
5202: <dt>A start tag token whose tag name is one of: "base", "link",
5203: "meta", "noframes", "script", "style", "title"</dt>
5204: <dd>
5205:
5206: <p><a href="#parse-error">Parse error</a>.</p>
5207:
5208: <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
5209: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
5210:
5211: <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
5212: mode</a>.</p>
5213:
5214: <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
5215: of open elements</a>.</p>
5216:
5217: <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
5218: pointer</a> cannot be null at this point.</p>
5219:
5220: </dd>
5221:
5222: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
5223: <dd>
5224: <p>Act as described in the "anything else" entry below.</p>
5225: </dd>
5226:
5227: <dt>A start tag whose tag name is "head"</dt>
5228: <dt>Any other end tag</dt>
5229: <dd>
5230: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5231: </dd>
5232:
5233: <dt>Anything else</dt>
5234: <dd>
5235: <p>Act as if a start tag token with the tag name "body" and no
5236: attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
5237: flag</a> back to "ok", and then reprocess the current
5238: token.</p>
5239: </dd>
5240:
1.755 mike 5241: </dl><h5 id="parsing-main-inbody"><span class="secno">8.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 5242:
5243: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
5244: mode: in body">in body</a>", tokens must be handled as follows:</p>
5245:
5246: <dl class="switch"><dt>A character token</dt>
5247: <dd>
5248:
5249: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5250: any.</p>
5251:
5252: <p><a href="#insert-a-character" title="insert a character">Insert the token's
5253: character</a> into the <a href="#current-node">current node</a>.</p>
5254:
5255: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
5256: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
5257: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
5258: flag</a> to "not ok".</p>
5259:
5260: </dd>
5261:
5262: <dt>A comment token</dt>
5263: <dd>
5264: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
5265: node</a> with the <code title="">data</code> attribute set to
5266: the data given in the comment token.</p>
5267: </dd>
5268:
5269: <dt>A DOCTYPE token</dt>
5270: <dd>
5271: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5272: </dd>
5273:
5274: <dt>A start tag whose tag name is "html"</dt>
5275: <dd>
5276: <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
5277: check to see if the attribute is already present on the top
5278: element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
5279: add the attribute and its corresponding value to that element.</p>
5280: </dd>
5281:
5282: <dt>A start tag token whose tag name is one of: "base", "command",
5283: "link", "meta", "noframes", "script", "style", "title"</dt>
5284: <dd>
5285: <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
5286: mode</a>.</p>
5287: </dd>
5288:
5289: <dt>A start tag whose tag name is "body"</dt>
5290: <dd>
5291:
5292: <p><a href="#parse-error">Parse error</a>.</p>
5293:
5294: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159 mike 5295: elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1 mike 5296: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
5297: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
5298:
5299: <p>Otherwise, for each attribute on the token, check to see if
1.159 mike 5300: the attribute is already present on the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 5301: element (the second element) on the <a href="#stack-of-open-elements">stack of open
5302: elements</a>. If it is not, add the attribute and its
5303: corresponding value to that element.</p>
5304:
5305: </dd>
5306:
5307: <dt>A start tag whose tag name is "frameset"</dt>
5308: <dd>
5309:
5310: <p><a href="#parse-error">Parse error</a>.</p>
5311:
5312: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159 mike 5313: elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1 mike 5314: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
5315: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
5316:
5317: <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
5318: the token.</p>
5319:
5320: <p>Otherwise, run the following steps:</p>
5321:
5322: <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
5323: elements</a> from its parent node, if it has one.</p></li>
5324:
5325: <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
5326: open elements</a>, from the <a href="#current-node">current node</a> up to,
1.159 mike 5327: but not including, the root <code><a href="semantics.html#the-html-element-0">html</a></code> element.</p>
1.1 mike 5328:
5329: </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
5330: token.</p></li>
5331:
5332: <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>
5333:
5334: </li></ol></dd>
5335:
5336: <dt>An end-of-file token</dt>
5337: <dd>
5338:
5339: <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
1.422 mike 5340: 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>
5341: 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 5342: <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
5343: <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
5344: <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 5345: <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 5346: this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
1.422 mike 5347: fragment cases) -->
1.1 mike 5348:
5349: <p><a href="#stop-parsing">Stop parsing</a>.</p>
5350:
5351: </dd>
5352:
5353: <dt>An end tag whose tag name is "body"</dt>
5354: <dd>
5355:
5356: <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
5357: in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
5358: token.</p>
5359:
5360: <!-- if we get here, the insertion mode here is forcibly "in
5361: body". -->
5362:
5363: <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
1.422 mike 5364: elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
1.1 mike 5365: <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
5366: <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
5367: <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
5368: <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
5369: <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
5370: <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 5371: <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
5372: <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 5373: error</a>.</p> <!-- (some of those are fragment cases, e.g. for
5374: <tbody> you'd have hit the first paragraph since the <body>
1.422 mike 5375: wouldn't be in scope, unless it was a fragment case) -->
1.1 mike 5376:
5377: <!-- If we ever change the frameset-ok flag to an insertion mode,
5378: then we'd have to somehow keep track of its state when we switch
5379: to after-body. -->
5380:
5381: <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>
5382:
5383: </dd>
5384:
5385: <dt>An end tag whose tag name is "html"</dt>
5386: <dd>
5387:
5388: <p>Act as if an end tag with tag name "body" had been seen,
5389: then, if that token wasn't ignored, reprocess the current
5390: token.</p>
5391:
5392: </dd>
5393:
5394: <!-- start tags for non-phrasing flow content elements -->
5395:
5396: <!-- the normal ones -->
5397: <dt>A start tag whose tag name is one of: "address", "article",
1.683 mike 5398: "aside", "blockquote", "center", <!--v2DATAGRID"datagrid",-->
1.305 mike 5399: "details", "dir", "div", "dl", "fieldset", "figure", "footer",
5400: "header", "hgroup", "menu", "nav", "ol", "p", "section", "ul"</dt>
1.1 mike 5401: <dd>
5402:
5403: <!-- As of May 2008 this doesn't match any browser exactly, but is
5404: as close to what IE does as I can get without doing the non-tree
5405: DOM nonsense, and thus should actually afford better compatibility
5406: when implemented by the other browsers. -->
5407:
5408: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5409: an element in scope">has a <code>p</code> element in
5410: scope</a>, then act as if an end tag with the tag name
5411: "p" had been seen.</p>
5412:
5413: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5414:
5415: </dd>
5416:
5417: <!-- as normal, but close h1-h6 if it's the current node -->
5418: <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
5419: "h5", "h6"</dt>
5420: <dd>
5421:
5422: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5423: an element in scope">has a <code>p</code> element in
5424: scope</a>, then act as if an end tag with the tag name
5425: "p" had been seen.</p>
5426:
5427: <p>If the <a href="#current-node">current node</a> is an element whose tag name
5428: is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
5429: <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
5430: the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
5431: <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
5432:
5433: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5434:
5435: </dd>
5436:
5437: <!-- as normal, but drops leading newline -->
5438: <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
5439: <dd>
5440:
5441: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5442: an element in scope">has a <code>p</code> element in
5443: scope</a>, then act as if an end tag with the tag name
5444: "p" had been seen.</p>
5445:
5446: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5447:
5448: <p>If the next token is a U+000A LINE FEED (LF) character
5449: token, then ignore that token and move on to the next
5450: one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
5451: ignored as an authoring convenience.)</p>
5452:
5453: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5454:
5455: </dd>
5456:
5457: <!-- as normal, but interacts with the form element pointer -->
5458: <dt>A start tag whose tag name is "form"</dt>
5459: <dd>
5460:
5461: <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
5462: pointer</a> is not null, then this is a <a href="#parse-error">parse
5463: error</a>; ignore the token.</p>
5464:
5465: <p>Otherwise:</p>
5466:
5467: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5468: an element in scope">has a <code>p</code> element in
5469: scope</a>, then act as if an end tag with the tag name
5470: "p" had been seen.</p>
5471:
5472: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
5473: <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
5474: point to the element created.</p>
5475:
5476: </dd>
5477:
5478: <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
5479: <dt>A start tag whose tag name is "li"</dt>
5480: <dd>
5481:
5482: <p>Run the following algorithm:</p>
5483:
5484: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
5485:
5486: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
5487: node</a> (the bottommost node of the stack).</p></li>
5488:
1.578 mike 5489: <li><p><i>Loop</i>: If <var title="">node</var> is an
5490: <code><a href="semantics.html#the-li-element">li</a></code> element, then act as if an end tag with the tag
5491: name "li" had been seen, then jump to the last step.</p></li>
1.1 mike 5492:
1.578 mike 5493: <li><p>If <var title="">node</var> is not in the
1.1 mike 5494: <a href="#formatting">formatting</a> category, and is not in the
5495: <a href="#phrasing">phrasing</a> category, and is not an
1.306 mike 5496: <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 5497: element, then jump to the last step.</p></li> <!-- an element
5498: <foo> is in this list if the following markup:
5499:
5500: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
5501:
5502: ...results in the second <li> not being (in any way) a descendant
5503: of the first <li>, or if <foo> is a formatting element that gets
5504: reopened later. -->
5505:
5506: <li><p>Otherwise, set <var title="">node</var> to the previous
5507: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
5508: the step labeled <i>loop</i>.</p></li>
5509:
5510: <li>
5511:
5512: <p>This is the last step.</p>
5513:
5514: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5515: an element in scope">has a <code>p</code> element in
5516: scope</a>, then act as if an end tag with the tag name
5517: "p" had been seen.</p>
5518:
5519: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
5520: token.</p>
5521:
5522: </li>
5523:
5524: </ol></dd>
5525:
5526: <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases -->
1.422 mike 5527: <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
1.1 mike 5528: <dd>
5529:
5530: <p>Run the following algorithm:</p>
5531:
5532: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
5533:
5534: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
5535: node</a> (the bottommost node of the stack).</p></li>
5536:
5537: <li><p><i>Loop</i>: If <var title="">node</var> is a
1.422 mike 5538: <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
5539: tag with the same tag name as <var title="">node</var> had been
5540: seen, then jump to the last step.</p></li>
1.1 mike 5541:
5542: <li><p>If <var title="">node</var> is not in the
5543: <a href="#formatting">formatting</a> category, and is not in the
5544: <a href="#phrasing">phrasing</a> category, and is not an
1.306 mike 5545: <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 5546: element, then jump to the last step.</p></li> <!-- an element
5547: <foo> is in this list if the following markup:
5548:
5549: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
5550:
5551: ...results in the second <dt> not being (in any way) a descendant
5552: of the first <dt>, or if <foo> is a formatting element that gets
5553: reopened later. -->
5554:
5555: <li><p>Otherwise, set <var title="">node</var> to the previous
5556: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
5557: the step labeled <i>loop</i>.</p></li>
5558:
5559: <li>
5560:
5561: <p>This is the last step.</p>
5562:
5563: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5564: an element in scope">has a <code>p</code> element in
5565: scope</a>, then act as if an end tag with the tag name
5566: "p" had been seen.</p>
5567:
5568: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
5569: token.</p>
5570:
5571: </li>
5572:
5573: </ol></dd>
5574:
5575: <!-- same as normal, but effectively ends parsing -->
5576: <dt>A start tag whose tag name is "plaintext"</dt>
5577: <dd>
5578:
5579: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5580: an element in scope">has a <code>p</code> element in
5581: scope</a>, then act as if an end tag with the tag name
5582: "p" had been seen.</p>
5583:
5584: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5585:
1.541 mike 5586: <p>Switch the tokenizer to the <a href="#plaintext-state">PLAINTEXT state</a>.</p>
1.1 mike 5587:
1.541 mike 5588: <p class="note">Once a start tag with the tag name "plaintext" has
5589: been seen, that will be the last token ever seen other than
5590: character tokens (and the end-of-file token), because there is no
5591: way to switch out of the <a href="#plaintext-state">PLAINTEXT state</a>.</p>
1.1 mike 5592:
5593: </dd>
5594:
5595: <!-- end tags for non-phrasing flow content elements -->
5596:
5597: <!-- the normal ones -->
5598: <dt>An end tag whose tag name is one of: "address", "article",
1.683 mike 5599: "aside", "blockquote", "center", <!--v2DATAGRID"datagrid",-->
1.305 mike 5600: "details", "dir", "div", "dl", "fieldset", "figure", "footer",
5601: "header", "hgroup", "listing", "menu", "nav", "ol", "pre",
5602: "section", "ul"</dt>
1.1 mike 5603: <dd>
5604:
5605: <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>
5606: with the same tag name as that of the token, then this is a
5607: <a href="#parse-error">parse error</a>; ignore the token.</p>
5608:
5609: <p>Otherwise, run these steps:</p>
5610:
5611: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5612:
5613: <li><p>If the <a href="#current-node">current node</a> is not an element with
5614: the same tag name as that of the token, then this is a
5615: <a href="#parse-error">parse error</a>.</p></li>
5616:
5617: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5618: until an element with the same tag name as the token has been
5619: popped from the stack.</p></li>
5620:
5621: </ol></dd>
5622:
5623: <!-- removes the form element pointer instead of the matching node -->
5624: <dt>An end tag whose tag name is "form"</dt>
5625: <dd>
5626:
5627: <p>Let <var title="">node</var> be the element that the
5628: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
5629: to.</p>
5630:
5631: <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
5632: to null.</p>
5633:
5634: <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
5635: elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
5636: scope">have <var title="">node</var> in scope</a>, then this is
5637: a <a href="#parse-error">parse error</a>; ignore the token.</p>
5638:
5639: <p>Otherwise, run these steps:</p>
5640:
5641: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5642:
5643: <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
5644: error</a>.</p></li>
5645:
5646: <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
5647: open elements</a>.</p></li>
5648:
5649: </ol></dd>
5650:
5651: <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
5652: <dt>An end tag whose tag name is "p"</dt>
5653: <dd>
5654:
5655: <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>
5656: with the same tag name as that of the token, then this is a
5657: <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
5658: "p" had been seen, then reprocess the current token.</p>
5659:
5660: <p>Otherwise, run these steps:</p>
5661:
5662: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
5663: for elements with the same tag name as the token.</p></li>
5664:
5665: <li><p>If the <a href="#current-node">current node</a> is not an element with
5666: the same tag name as that of the token, then this is a
5667: <a href="#parse-error">parse error</a>.</p></li>
5668:
5669: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5670: until an element with the same tag name as the token has been
5671: popped from the stack.</p></li>
5672:
5673: </ol></dd>
5674:
1.234 mike 5675: <!-- as normal, but needs care as the elements have optional tags, and are further scoped by <ol>/<ul> -->
5676: <dt>An end tag whose tag name is "li"</dt>
5677: <dd>
5678:
5679: <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
5680: item scope</a> with the same tag name as that of the token,
5681: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
5682:
5683: <p>Otherwise, run these steps:</p>
5684:
5685: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
5686: for elements with the same tag name as the token.</p></li>
5687:
5688: <li><p>If the <a href="#current-node">current node</a> is not an element with
5689: the same tag name as that of the token, then this is a
5690: <a href="#parse-error">parse error</a>.</p></li>
5691:
5692: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5693: until an element with the same tag name as the token has been
5694: popped from the stack.</p></li>
5695:
5696: </ol></dd>
5697:
1.1 mike 5698: <!-- as normal, but needs care as the elements have optional tags -->
1.422 mike 5699: <dt>An end tag whose tag name is one of: "dd", "dt"</dt>
1.1 mike 5700: <dd>
5701:
5702: <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>
5703: with the same tag name as that of the token, then this is a
5704: <a href="#parse-error">parse error</a>; ignore the token.</p>
5705:
5706: <p>Otherwise, run these steps:</p>
5707:
5708: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
5709: for elements with the same tag name as the token.</p></li>
5710:
5711: <li><p>If the <a href="#current-node">current node</a> is not an element with
5712: the same tag name as that of the token, then this is a
5713: <a href="#parse-error">parse error</a>.</p></li>
5714:
5715: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5716: until an element with the same tag name as the token has been
5717: popped from the stack.</p></li>
5718:
5719: </ol></dd>
5720:
5721: <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
5722: <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
5723: <dd>
5724:
5725: <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>
5726: whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
5727: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
5728:
5729: <p>Otherwise, run these steps:</p>
5730:
5731: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5732:
5733: <li><p>If the <a href="#current-node">current node</a> is not an element with
5734: the same tag name as that of the token, then this is a
5735: <a href="#parse-error">parse error</a>.</p></li>
5736:
5737: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
5738: until an element whose tag name is one of "h1", "h2", "h3", "h4",
5739: "h5", or "h6" has been popped from the stack.</p></li>
5740:
5741: </ol></dd>
5742:
5743: <dt>An end tag whose tag name is "sarcasm"</dt>
5744: <dd>
5745: <p>Take a deep breath, then act as described in the "any other end
5746: tag" entry below.</p>
5747: </dd>
5748:
5749: <!-- ADOPTION AGENCY ELEMENTS
5750: Mozilla-only: bdo blink del ins sub sup q
5751: Safari-only: code dfn kbd nobr samp var wbr
5752: Both: a b big em font i s small strike strong tt u -->
5753:
5754: <dt>A start tag whose tag name is "a"</dt>
5755: <dd>
5756:
5757: <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
5758: contains an element whose tag name is "a" between the end of
5759: the list and the last marker on the list (or the start of the
5760: list if there is no marker on the list), then this is a
5761: <a href="#parse-error">parse error</a>; act as if an end tag with the tag
5762: name "a" had been seen, then remove that element from the
5763: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
5764: <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
5765: already remove it (it might not have if the element is not
5766: <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
5767: scope</a>).</p>
5768:
5769: <p class="example">In the non-conforming stream
5770: <code><a href="a">a<table><a href="b">b</table>x</code>,
5771: the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
5772: the second one, and the "x" character would be inside a link
5773: to "b", not to "a". This is despite the fact that the outer
5774: <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
5775: regular <code></a></code> end tag at the start of the table
5776: wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
5777:
5778: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5779: any.</p>
5780:
5781: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
5782: element to the <a href="#list-of-active-formatting-elements">list of active formatting
5783: elements</a>.</p>
5784:
5785: </dd>
5786:
5787: <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
5788: "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
5789: <dd>
5790:
5791: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5792: any.</p>
5793:
5794: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
5795: element to the <a href="#list-of-active-formatting-elements">list of active formatting
5796: elements</a>.</p>
5797:
5798: </dd>
5799:
5800: <dt>A start tag whose tag name is "nobr"</dt>
5801: <dd>
5802:
5803: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5804: any.</p>
5805:
5806: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5807: element in scope">has a <code>nobr</code> element in scope</a>,
5808: then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
5809: the tag name "nobr" had been seen, then once again
5810: <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
5811: any.</p>
5812:
5813: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
5814: element to the <a href="#list-of-active-formatting-elements">list of active formatting
5815: elements</a>.</p>
5816:
5817: </dd>
5818:
5819: <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
5820: "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
5821: "strike", "strong", "tt", "u"</dt>
5822: <dd>
5823:
5824: <p>Follow these steps:</p>
5825:
5826: <ol><li>
5827:
5828: <p>Let the <var title="">formatting element</var> be the
5829: last element in the <a href="#list-of-active-formatting-elements">list of active formatting
5830: elements</a> that:</p>
5831:
5832: <ul><li>is between the end of the list and the last scope
5833: marker in the list, if any, or the start of the list
5834: otherwise, and</li>
5835:
5836: <li>has the same tag name as the token.</li>
5837:
5838: </ul><p>If there is no such node, or, if that node is also in the
5839: <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
5840: <a href="#parse-error">parse error</a>; ignore the token, and abort these
5841: steps.</p>
5842:
5843: <p>Otherwise, if there is such a node, but that node is not
5844: in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
5845: <a href="#parse-error">parse error</a>; remove the element from the list,
5846: and abort these steps.</p>
5847:
5848: <p>Otherwise, there is a <var title="">formatting
5849: element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
5850: open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
5851: element in scope">in scope</a>. If the element is not the
5852: <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
5853: error</a>. In any case, proceed with the algorithm as
5854: written in the following steps.</p>
5855:
5856: </li>
5857:
5858: <li><p>Let the <var title="">furthest block</var> be the
5859: topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
5860: is lower in the stack than the <var title="">formatting
5861: element</var>, and is not an element in the
5862: <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
5863: categories. There might not be one.</p></li>
5864:
5865: <li><p>If there is no <var title="">furthest block</var>,
5866: then the UA must skip the subsequent steps and instead just
5867: pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
5868: elements</a>, from the <a href="#current-node">current node</a> up to and
5869: including the <var title="">formatting element</var>, and
5870: remove the <var title="">formatting element</var> from the
5871: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
5872:
5873: <li><p>Let the <var title="">common ancestor</var> be the element
5874: immediately above the <var title="">formatting element</var> in the
5875: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
5876:
5877: <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
5878: formatting elements</a> relative to the elements on either
5879: side of it in the list.</p></li>
5880:
5881: <li>
5882:
5883: <p>Let <var title="">node</var> and <var title="">last node</var> be the
5884: <var title="">furthest block</var>. Follow these steps:</p>
5885:
5886: <ol><li>Let <var title="">node</var> be the element immediately
5887: above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
1.436 mike 5888: elements</a>, or if <var title="">node</var> is no longer in
5889: the <a href="#stack-of-open-elements">stack of open elements</a> (e.g. because it got
5890: removed by the next step), the element that was immediately
5891: above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
5892: elements</a> before <var title="">node</var> was
5893: removed.</li>
1.1 mike 5894:
5895: <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
5896: active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
5897: elements</a> and then go back to step 1.</li>
5898:
5899: <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
5900: in the overall algorithm.</li>
5901:
5902: <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
5903: bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
5904: elements</a>.</li>
5905:
5906: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
5907: element <var title="">node</var> was created, replace the entry
5908: for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
5909: formatting elements</a> with an entry for the new element,
5910: replace the entry for <var title="">node</var> in the
5911: <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
5912: element, and let <var title="">node</var> be the new
5913: element.</li>
5914:
5915: <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
5916: parent node if any.</li>
5917:
5918: <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
5919:
5920: <li>Return to step 1 of this inner set of steps.</li>
5921:
5922: </ol></li>
5923:
5924: <li>
5925:
5926: <p>If the <var title="">common ancestor</var> node is a
5927: <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>,
5928: <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,
5929: <a href="#foster-parent">foster parent</a> whatever <var title="">last
5930: node</var> ended up being in the previous step, first removing
5931: it from its previous parent node if any.</p>
5932:
5933: <p>Otherwise, append whatever <var title="">last node</var>
5934: ended up being in the previous step to the <var title="">common
5935: ancestor</var> node, first removing it from its previous parent
5936: node if any.</p>
5937:
5938: </li>
5939:
5940: <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
5941: <var title="">formatting element</var> was created.</p></li>
5942:
5943: <li><p>Take all of the child nodes of the <var title="">furthest
5944: block</var> and append them to the element created in the last
5945: step.</p></li>
5946:
5947: <li><p>Append that new element to the <var title="">furthest
5948: block</var>.</p></li>
5949:
5950: <li><p>Remove the <var title="">formatting element</var> from the
5951: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
5952: new element into the <a href="#list-of-active-formatting-elements">list of active formatting
5953: elements</a> at the position of the aforementioned
5954: bookmark.</p></li>
5955:
5956: <li><p>Remove the <var title="">formatting element</var> from the
5957: <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
5958: into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
5959: the position of the <var title="">furthest block</var> in that
5960: stack.</p></li>
5961:
5962: <li><p>Jump back to step 1 in this series of steps.</p></li>
5963:
1.334 mike 5964: </ol><p class="note">Because of the way this algorithm causes elements
1.304 mike 5965: to change parents, it has been dubbed the "adoption agency
5966: algorithm" (in contrast with other possible algorithms for dealing
5967: with misnested content, which included the "incest algorithm", the
1.1 mike 5968: "secret affair algorithm", and the "Heisenberg algorithm").</p>
5969:
5970: </dd>
5971:
5972: <dt>A start tag whose tag name is "button"</dt>
5973: <dd>
5974:
5975: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
5976: an element in scope">has a <code>button</code> element in
5977: scope</a>, then this is a <a href="#parse-error">parse error</a>;
5978: act as if an end tag with the tag name "button" had been seen,
5979: then reprocess the token.</p>
5980:
5981: <p>Otherwise:</p>
5982:
5983: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5984: any.</p>
5985:
5986: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5987:
5988: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5989: formatting elements</a>.</p>
5990:
5991: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5992:
5993: </dd>
5994:
5995: <dt>A start tag token whose tag name is one of: "applet",
5996: "marquee", "object"</dt>
5997: <dd>
5998:
5999: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6000: any.</p>
6001:
6002: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6003:
6004: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
6005: formatting elements</a>.</p>
6006:
6007: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
6008:
6009: </dd>
6010:
6011: <dt>An end tag token whose tag name is one of: "applet", "button",
6012: "marquee", "object"</dt>
6013: <dd>
6014:
6015: <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>
6016: with the same tag name as that of the token, then this is a
6017: <a href="#parse-error">parse error</a>; ignore the token.</p>
6018:
6019: <p>Otherwise, run these steps:</p>
6020:
6021: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
6022:
6023: <li><p>If the <a href="#current-node">current node</a> is not an element with
6024: the same tag name as that of the token, then this is a
6025: <a href="#parse-error">parse error</a>.</p></li>
6026:
6027: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
6028: until an element with the same tag name as the token has been
6029: popped from the stack.</p></li>
6030:
6031: <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
6032: last marker</a>.</li>
6033:
6034: </ol></dd>
6035:
6036: <dt>A start tag whose tag name is "table"</dt>
6037: <dd>
6038:
1.810 mike 6039: <p>If the <code><a href="infrastructure.html#document">Document</a></code> is <em>not</em> set to
1.1 mike 6040: <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
6041: elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
6042: <code>p</code> element in scope</a>, then act as if an end tag
6043: with the tag name "p" had been seen.</p> <!-- i hate myself (this
6044: quirk was basically caused by acid2; if i'd realised we could
6045: change the specs when i wrote acid2, we could have avoided having
6046: any parsing-mode quirks) -Hixie -->
6047:
6048: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6049:
6050: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
6051:
6052: <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>
6053:
6054: </dd>
6055:
6056: <dt>A start tag whose tag name is one of: "area", "basefont",
1.589 mike 6057: "bgsound", "br", "embed", "img", "input", "keygen", "wbr"</dt>
1.1 mike 6058: <dd>
6059:
6060: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6061: any.</p>
6062:
6063: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
6064: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6065: elements</a>.</p>
6066:
6067: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6068: token's <i>self-closing flag</i></a>, if it is set.</p>
6069:
6070: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
1.589 mike 6071: shouldn't really do it for <area>, <basefont>, and <bgsound> -->
1.1 mike 6072:
6073: </dd>
6074:
6075: <dt>A start tag whose tag name is one of: "param", "source"</dt>
6076: <dd>
6077:
6078: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
6079: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6080: elements</a>.</p>
6081:
6082: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6083: token's <i>self-closing flag</i></a>, if it is set.</p>
6084:
6085: </dd>
6086:
6087: <dt>A start tag whose tag name is "hr"</dt>
6088: <dd>
6089:
6090: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
6091: an element in scope">has a <code>p</code> element in
6092: scope</a>, then act as if an end tag with the tag name
6093: "p" had been seen.</p>
6094:
6095: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
6096: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6097: elements</a>.</p>
6098:
6099: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6100: token's <i>self-closing flag</i></a>, if it is set.</p>
6101:
6102: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
6103:
6104: </dd>
6105:
6106: <dt>A start tag whose tag name is "image"</dt>
6107: <dd>
6108: <p><a href="#parse-error">Parse error</a>. Change the token's tag name
6109: to "img" and reprocess it. (Don't ask.)</p> <!-- As of
6110: 2005-12, studies showed that around 0.2% of pages used the
6111: <image> element. -->
6112: </dd>
6113:
6114: <dt id="isindex">A start tag whose tag name is "isindex"</dt>
6115: <dd>
6116:
6117: <p><a href="#parse-error">Parse error</a>.</p>
6118:
6119: <p>If the <a href="#form-element-pointer"><code title="">form</code> element
6120: pointer</a> is not null, then ignore the token.</p>
6121:
6122: <p>Otherwise:</p>
6123:
6124: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6125: token's <i>self-closing flag</i></a>, if it is set.</p> <!--
6126: purely to reduce the number of errors (we don't care if they
6127: included the /, they're not supposed to be including the tag at
6128: all! -->
6129:
6130: <p>Act as if a start tag token with the tag name "form" had been seen.</p>
6131:
6132: <p>If the token has an attribute called "action", set the
6133: <code title="attr-form-action">action</code> attribute on the
6134: resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
6135: "action" attribute of the token.</p>
6136:
6137: <p>Act as if a start tag token with the tag name "hr" had been
6138: seen.</p>
6139:
6140: <p>Act as if a start tag token with the tag name "label" had been
6141: seen.</p>
6142:
6143: <p>Act as if a stream of character tokens had been seen (see below
6144: for what they should say).</p>
6145:
6146: <p>Act as if a start tag token with the tag name "input" had been
6147: seen, with all the attributes from the "isindex" token except
6148: "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
6149: <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
6150:
6151: <p>Act as if a stream of character tokens had been seen (see
6152: below for what they should say).</p>
6153:
6154: <p>Act as if an end tag token with the tag name "label" had been
6155: seen.</p>
6156:
6157: <p>Act as if a start tag token with the tag name "hr" had been
6158: seen.</p>
6159:
6160: <p>Act as if an end tag token with the tag name "form" had been
6161: seen.</p>
6162:
6163: <p>If the token has an attribute with the name "prompt", then the
6164: first stream of characters must be the same string as given in
6165: that attribute, and the second stream of characters must be
6166: empty. Otherwise, the two streams of character tokens together
6167: should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
6168: equivalent of "This is a searchable index. Insert your search
6169: keywords here: (input field)" in the user's preferred
6170: language.</p>
6171:
6172: </dd>
6173:
6174: <dt>A start tag whose tag name is "textarea"</dt>
6175: <dd>
6176:
6177: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
6178: token.</p></li>
6179:
6180: <li><p>If the next token is a U+000A LINE FEED (LF) character
6181: token, then ignore that token and move on to the next
6182: one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
6183: ignored as an authoring convenience.)</p></li>
6184:
1.671 mike 6185: <li><p>Switch the tokenizer to the <a href="#rcdata-state">RCDATA
1.541 mike 6186: state</a>.</p></li>
1.1 mike 6187:
6188: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
6189: current <a href="#insertion-mode">insertion mode</a>.</p>
6190:
6191: </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
6192: ok".</p></li>
6193:
1.540 mike 6194: <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 6195:
6196: </ol></dd>
6197:
6198: <dt>A start tag whose tag name is "xmp"</dt>
6199: <dd>
6200:
1.233 mike 6201: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
6202: an element in scope">has a <code>p</code> element in
6203: scope</a>, then act as if an end tag with the tag name
6204: "p" had been seen.</p>
6205:
1.1 mike 6206: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6207: any.</p>
6208:
6209: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
6210:
1.91 mike 6211: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 6212:
6213: </dd>
6214:
6215: <dt>A start tag whose tag name is "iframe"</dt>
6216: <dd>
6217:
6218: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
6219:
1.91 mike 6220: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 6221:
6222: </dd>
6223:
6224: <dt>A start tag whose tag name is "noembed"</dt>
6225: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
6226: <dd>
6227:
1.91 mike 6228: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 6229:
6230: </dd>
6231:
6232: <dt>A start tag whose tag name is "select"</dt>
6233: <dd>
6234:
6235: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6236: any.</p>
6237:
6238: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6239:
6240: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
6241:
6242: <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>",
6243: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
6244: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
6245: row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
6246: cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
6247: "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
6248: table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
6249: to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
6250:
6251: </dd>
6252:
6253: <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
6254: <dd>
6255:
6256: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
6257: element in scope">has an <code>option</code> element in
6258: scope</a>, then act as if an end tag with the tag name "option"
6259: had been seen.</p>
6260:
6261: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6262: any.</p>
6263:
6264: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6265:
6266: </dd>
6267:
6268: <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
6269: <dd>
6270:
6271: <!-- the parsing rules for ruby really don't match IE much at all,
6272: but in practice the markup used is very simple and so strict
6273: compatibility with IE isn't required. For example, as defined
6274: here we get very, very different behaviour than IE for
6275: pathological cases like:
6276:
6277: <ruby><ol><li><p>a<rt>b
6278: <ruby>a<rt>b<p>c
6279:
6280: But in practice most ruby markup falls into these cases:
6281:
6282: <ruby>a<rt>b</ruby>
6283: <ruby>a<rp>b<rt>c<rp>d</ruby>
6284: <ruby>a<rt>b</rt></ruby>
6285: <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
6286:
6287: -->
6288:
6289: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
6290: element in scope">has a <code>ruby</code> element in scope</a>,
6291: then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
6292: node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
6293: <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
6294: node</a> up to the node immediately before the bottommost
6295: <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
6296: elements</a>.</p>
6297:
6298: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6299:
6300: </dd>
6301:
6302: <dt>An end tag whose tag name is "br"</dt>
6303: <dd>
6304: <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
6305: the tag name "br" had been seen. Ignore the end tag token.</p>
6306: </dd>
6307:
6308: <dt>A start tag whose tag name is "math"</dt>
6309: <dd>
6310:
6311: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6312: any.</p>
6313:
6314: <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
6315: fixes the case of MathML attributes that are not all
6316: 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.)</p>
6320:
6321: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
1.724 mike 6322: <a href="infrastructure.html#mathml-namespace">MathML namespace</a>.</p>
1.1 mike 6323:
6324: <!-- If we ever change the frameset-ok flag to an insertion mode,
6325: the following change would be implied, except we'd have to do it
6326: even in the face of a self-closed tag:
6327: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
6328: -->
6329:
6330: <p>If the token has its <i>self-closing flag</i> set, pop the
6331: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6332: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
6333: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
6334:
6335: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
6336: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
6337: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
6338: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
6339: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
6340: foreign content">in foreign content</a>".</p>
6341:
6342: </dd>
6343:
6344: <dt>A start tag whose tag name is "svg"</dt>
6345: <dd>
6346:
6347: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6348: any.</p>
6349:
6350: <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
6351: the case of SVG attributes that are not all lowercase.)</p>
6352:
6353: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
6354: fixes the use of namespaced attributes, in particular XLink in
6355: SVG.)</p>
6356:
6357: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
1.724 mike 6358: <a href="infrastructure.html#svg-namespace">SVG namespace</a>.</p>
1.1 mike 6359:
6360: <!-- If we ever change the frameset-ok flag to an insertion mode,
6361: the following change would be implied, except we'd have to do it
6362: even in the face of a self-closed tag:
6363: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
6364: -->
6365:
6366: <p>If the token has its <i>self-closing flag</i> set, pop the
6367: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6368: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
6369: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
6370:
6371: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
6372: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
6373: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
6374: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
6375: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
6376: foreign content">in foreign content</a>".</p>
6377:
6378: </dd>
6379:
6380: <dt>A start <!--or end--> tag whose tag name is one of: "caption",
6381: "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
6382: "thead", "tr"</dt>
6383: <!--<dt>An end tag whose tag name is one of: "area", "base",
6384: "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
6385: "img", "input", "isindex", "keygen", "link", "meta", "noembed",
1.589 mike 6386: "noframes", "param", "script", "select", "source", "style",
6387: "table", "textarea", "title", "wbr"</dt>-->
1.1 mike 6388: <!--<dt>An end tag whose tag name is "noscript", if the
6389: <span>scripting flag</span> is enabled</dt>-->
6390: <dd>
6391: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6392: <!-- end tags are commented out because since they can never end
6393: up on the stack anyway, the default end tag clause will
6394: automatically handle them. we don't want to have text in the spec
6395: that is just an optimisation, as that detracts from the spec
6396: itself -->
6397: </dd>
6398:
6399: <dt>Any other start tag</dt>
6400: <dd>
6401:
6402: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
6403: any.</p>
6404:
6405: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6406:
6407: <p class="note">This element will be a <a href="#phrasing">phrasing</a>
6408: element.</p>
6409:
6410: </dd>
6411:
6412: <dt>Any other end tag</dt>
6413: <dd>
6414:
6415: <p>Run the following steps:</p>
6416:
6417: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
6418: node</a> (the bottommost node of the stack).</p></li>
6419:
6420: <li><p>If <var title="">node</var> has the same tag name as
6421: the end tag token, then:</p>
6422:
6423: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
6424:
6425: <li><p>If the tag name of the end tag token does not match
6426: the tag name of the <a href="#current-node">current node</a>, this is a
6427: <a href="#parse-error">parse error</a>.</p></li>
6428:
6429: <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
6430: to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
6431:
6432: </ol></li>
6433:
6434: <li><p>Otherwise, if <var title="">node</var> is in neither the
6435: <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
6436: category, then this is a <a href="#parse-error">parse error</a>; ignore the
6437: token, and abort these steps.</p></li>
6438:
6439: <li><p>Set <var title="">node</var> to the previous entry in the
6440: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
6441:
6442: <li><p>Return to step 2.</p></li>
6443:
6444: </ol></dd>
6445:
1.755 mike 6446: </dl><h5 id="parsing-main-incdata"><span class="secno">8.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 6447:
6448: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.540 mike 6449: mode: text">text</a>", tokens must be handled as follows:</p>
1.1 mike 6450:
6451: <dl class="switch"><dt>A character token</dt>
6452: <dd>
6453:
6454: <p><a href="#insert-a-character" title="insert a character">Insert the token's
6455: character</a> into the <a href="#current-node">current node</a>.</p>
6456:
6457: </dd>
6458:
6459: <dt>An end-of-file token</dt>
6460: <dd>
6461:
6462: <!-- can't be the fragment case -->
6463: <p><a href="#parse-error">Parse error</a>.</p>
6464:
6465: <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
1.484 mike 6466: element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-started">"already
6467: started"</a>.</p>
1.1 mike 6468:
6469: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6470: elements</a>.</p>
6471:
6472: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
6473: insertion mode</a> and reprocess the current token.</p>
6474:
6475: </dd>
6476:
6477: <dt>An end tag whose tag name is "script"</dt>
6478: <dd>
6479:
6480: <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
6481: (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
6482:
6483: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6484: elements</a>.</p>
6485:
6486: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
6487: insertion mode</a>.</p>
6488:
6489: <p>Let the <var title="">old insertion point</var> have the
6490: same value as the current <a href="#insertion-point">insertion point</a>. Let
6491: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
6492: input character</a>.</p>
6493:
6494: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
6495: one.</p>
6496:
6497: <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 6498: which might cause <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters
1.1 mike 6499: to be inserted into the tokenizer</a>, and might cause the
6500: tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
6501:
6502: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
6503: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
6504: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
6505:
6506: <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
6507: <a href="#insertion-point">insertion point</a> to its previous value. This value
6508: might be the "undefined" value.)</p>
6509:
6510: <p id="scriptTagParserResumes">At this stage, if there is a
1.484 mike 6511: <a href="semantics.html#pending-parsing-blocking-script">pending parsing-blocking script</a>, then:</p>
1.1 mike 6512:
6513: <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
6514:
6515: <dd>
6516:
6517: <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
6518: processing of any nested invocations of the tokenizer, yielding
6519: control back to the caller. (Tokenization will resume when the
6520: caller returns to the "outer" tree construction stage.)</p>
6521:
6522: <p class="note">The tree construction stage of this particular
6523: parser is <a href="#nestedParsing">being called reentrantly</a>,
1.159 mike 6524: 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 6525:
6526: </dd>
6527:
6528:
6529: <dt>Otherwise:</dt>
6530:
6531: <dd>
6532:
6533: <p>Follow these steps:</p>
6534:
1.484 mike 6535: <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-parsing-blocking-script">pending
6536: parsing-blocking script</a>. There is no longer a <a href="semantics.html#pending-parsing-blocking-script">pending
6537: parsing-blocking script</a>.</p></li>
6538:
6539: <li><p>Block the <a href="#tokenization" title="tokenization">tokenizer</a>
6540: for this instance of the <a href="#html-parser">HTML parser</a>, such that
1.794 mike 6541: the <a href="webappapis.html#event-loop">event loop</a> will not run <a href="webappapis.html#concept-task" title="concept-task">tasks</a> that invoke the <a href="#tokenization" title="tokenization">tokenizer</a>.</p></li>
1.484 mike 6542:
1.794 mike 6543: <li><p><a href="webappapis.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
1.484 mike 6544: scripts</a> and <var title="">the script</var>'s
6545: <a href="semantics.html#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag is set.</p></li>
6546:
6547: <li><p>Unblock the <a href="#tokenization" title="tokenization">tokenizer</a>
6548: for this instance of the <a href="#html-parser">HTML parser</a>, such that
1.794 mike 6549: <a href="webappapis.html#concept-task" title="concept-task">tasks</a> that invoke the <a href="#tokenization" title="tokenization">tokenizer</a> can again be
1.484 mike 6550: run.</p></li>
1.1 mike 6551:
6552: <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
6553: <a href="#next-input-character">next input character</a>.</p></li>
6554:
6555: <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
6556: by one (it should be zero before this step, so this sets it to
6557: one).</p></li>
6558:
1.484 mike 6559: <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute</a>
6560: <var title="">the script</var>.</p></li>
1.1 mike 6561:
6562: <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
6563: by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
6564: zero (which it always should be at this point), then set the
6565: <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
6566:
6567: </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
6568: again.</p></li>
6569:
1.484 mike 6570: <li><p>If there is once again a <a href="semantics.html#pending-parsing-blocking-script">pending parsing-blocking
1.1 mike 6571: script</a>, then repeat these steps from step 1.</p></li>
6572:
6573: </ol></dd>
6574:
6575: </dl></dd>
6576:
6577: <dt>Any other end tag</dt>
6578: <dd>
6579:
6580: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6581: elements</a>.</p>
6582:
6583: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
6584: insertion mode</a>.</p>
6585:
6586: </dd>
6587:
1.755 mike 6588: </dl><h5 id="parsing-main-intable"><span class="secno">8.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 6589:
6590: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
6591: mode: in table">in table</a>", tokens must be handled as follows:</p>
6592:
6593: <dl class="switch"><dt>A character token</dt>
6594: <dd>
6595:
6596: <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
6597: be an empty list of tokens.</p>
6598:
6599: <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
6600: <a href="#insertion-mode">insertion mode</a>.</p>
6601:
6602: <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
6603: reprocess the token.</p>
6604:
6605: </dd>
6606:
6607: <dt>A comment token</dt>
6608: <dd>
6609: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6610: node</a> with the <code title="">data</code> attribute set to
6611: the data given in the comment token.</p>
6612: </dd>
6613:
6614: <dt>A DOCTYPE token</dt>
6615: <dd>
6616: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6617: </dd>
6618:
6619: <dt>A start tag whose tag name is "caption"</dt>
6620: <dd>
6621:
6622: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
6623: below.)</p>
6624:
6625: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
6626: formatting elements</a>.</p>
6627:
6628: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
6629: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
6630:
6631: </dd>
6632:
6633: <dt>A start tag whose tag name is "colgroup"</dt>
6634: <dd>
6635:
6636: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
6637: below.)</p>
6638:
6639: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
6640: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
6641: group</a>".</p>
6642:
6643: </dd>
6644:
6645: <dt>A start tag whose tag name is "col"</dt>
6646: <dd>
6647: <p>Act as if a start tag token with the tag name "colgroup"
6648: had been seen, then reprocess the current token.</p>
6649: </dd>
6650:
6651: <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
6652: <dd>
6653:
6654: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
6655: below.)</p>
6656:
6657: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
6658: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
6659: body</a>".</p>
6660:
6661: </dd>
6662:
6663: <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
6664: <dd>
6665: <p>Act as if a start tag token with the tag name "tbody" had
6666: been seen, then reprocess the current token.</p>
6667: </dd>
6668:
6669: <dt>A start tag whose tag name is "table"</dt>
6670: <dd>
6671:
6672: <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
6673: the tag name "table" had been seen, then, if that token wasn't
6674: ignored, reprocess the current token.</p>
6675:
6676: <p class="note">The fake end tag token here can only be
6677: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6678:
6679: </dd>
6680:
6681: <dt>An end tag whose tag name is "table"</dt>
6682: <dd>
6683:
6684: <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
6685: scope</a> with the same tag name as the token, this is a
6686: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6687: case</a>)</p>
6688:
6689: <p>Otherwise:</p>
6690:
6691: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
6692: element has been popped from the stack.</p>
6693:
6694: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
6695:
6696: </dd>
6697:
6698: <dt>An end tag whose tag name is one of: "body", "caption",
6699: "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
6700: "thead", "tr"</dt>
6701: <dd>
6702: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6703: </dd>
6704:
6705: <dt>A start tag whose tag name is one of: "style", "script"</dt>
6706: <dd>
6707:
6708: <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
6709: mode</a>.</p>
6710:
6711: </dd>
6712:
6713: <dt>A start tag whose tag name is "input"</dt>
6714: <dd>
6715:
6716: <p>If the token does not have an attribute with the name "type",
6717: or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
6718: case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
6719: else" entry below.</p>
6720:
6721: <p>Otherwise:</p>
6722:
6723: <p><a href="#parse-error">Parse error</a>.</p>
6724:
6725: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6726:
6727: <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
6728: open elements</a>.</p>
6729:
6730: </dd>
6731:
1.603 mike 6732: <dt>A start tag whose tag name is "form"</dt>
6733: <dd>
6734:
6735: <p><a href="#parse-error">Parse error</a>.</p>
6736:
1.717 mike 6737: <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
6738: pointer</a> is not null, ignore the token.</p>
6739:
6740: <p>Otherwise:</p>
6741:
1.603 mike 6742: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6743:
1.637 mike 6744: <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 6745: open elements</a>.</p>
6746:
6747: </dd>
6748:
1.721 mike 6749: <!-- "form" end tag falls through to in-body, which does the right thing -->
1.717 mike 6750:
1.1 mike 6751: <dt>An end-of-file token</dt>
6752: <dd>
6753:
6754: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 6755: <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 6756: error</a>.</p>
6757:
6758: <p class="note">It can only be the <a href="#current-node">current node</a> in
6759: the <a href="#fragment-case">fragment case</a>.</p>
6760:
6761: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6762:
6763: </dd>
6764:
6765: <dt>Anything else</dt>
6766: <dd>
6767:
6768: <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
6769: rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
6770: body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
6771: <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
6772: <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
6773: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
6774: into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
6775:
6776: </dd>
6777:
6778: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
6779: back to a table context</dfn>, it means that the UA must, while
6780: 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 6781: element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1 mike 6782: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6783:
6784: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 6785: <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 6786: case</a>.</p>
6787:
6788:
6789:
1.755 mike 6790: <h5 id="parsing-main-intabletext"><span class="secno">8.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 6791:
6792: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
6793: mode: in table text">in table text</a>", tokens must be handled
6794: as follows:</p>
6795:
6796: <dl class="switch"><dt>A character token</dt>
6797: <dd>
6798:
6799: <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
6800: tokens</a></var> list.</p>
6801:
6802: </dd>
6803:
6804:
6805: <dt>Anything else</dt>
6806: <dd>
6807:
6808: <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
6809: tokens</a></var> list are character tokens that are not one of U+0009
6810: CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
6811: (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
6812: reprocess those character tokens using the rules given in the
6813: "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
6814: table">in table</a>" insertion mode.</p>
6815:
6816: <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
6817: characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
6818: tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
6819:
6820: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
6821: insertion mode</a> and reprocess the token.</p>
6822:
6823: </dd>
6824:
1.755 mike 6825: </dl><h5 id="parsing-main-incaption"><span class="secno">8.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 6826:
6827: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
6828: mode: in caption">in caption</a>", tokens must be handled as follows:</p>
6829:
6830: <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
6831: <dd>
6832:
6833: <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
6834: scope</a> with the same tag name as the token, this is a
6835: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6836: case</a>)</p>
6837:
6838: <p>Otherwise:</p>
6839:
6840: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
6841:
6842: <p>Now, if the <a href="#current-node">current node</a> is not a
6843: <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
6844: error</a>.</p>
6845:
6846: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
6847: element has been popped from the stack.</p>
6848:
6849: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
6850: the last marker</a>.</p>
6851:
6852: <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>
6853:
6854: </dd>
6855:
6856: <dt>A start tag whose tag name is one of: "caption", "col",
6857: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
6858: <dt>An end tag whose tag name is "table"</dt>
6859: <dd>
6860:
6861: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
6862: name "caption" had been seen, then, if that token wasn't
6863: ignored, reprocess the current token.</p>
6864:
6865: <p class="note">The fake end tag token here can only be
6866: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6867:
6868: </dd>
6869:
6870: <dt>An end tag whose tag name is one of: "body", "col",
6871: "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
6872: "tr"</dt>
6873: <dd>
6874: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6875: </dd>
6876:
6877: <dt>Anything else</dt>
6878: <dd>
6879: <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
6880: mode</a>.</p>
6881: </dd>
6882:
1.755 mike 6883: </dl><h5 id="parsing-main-incolgroup"><span class="secno">8.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 6884:
6885: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
6886: mode: in column group">in column group</a>", tokens must be handled as follows:</p>
6887:
6888: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6889: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6890: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6891: <dd>
6892: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6893: the <a href="#current-node">current node</a>.</p>
6894: </dd>
6895:
6896: <dt>A comment token</dt>
6897: <dd>
6898: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6899: node</a> with the <code title="">data</code> attribute set to
6900: the data given in the comment token.</p>
6901: </dd>
6902:
6903: <dt>A DOCTYPE token</dt>
6904: <dd>
6905: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6906: </dd>
6907:
6908: <dt>A start tag whose tag name is "html"</dt>
6909: <dd>
6910: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
6911: mode</a>.</p>
6912: </dd>
6913:
6914: <dt>A start tag whose tag name is "col"</dt>
6915: <dd>
6916:
6917: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
6918: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6919: elements</a>.</p>
6920:
6921: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6922: token's <i>self-closing flag</i></a>, if it is set.</p>
6923:
6924: </dd>
6925:
6926: <dt>An end tag whose tag name is "colgroup"</dt>
6927: <dd>
6928:
6929: <p>If the <a href="#current-node">current node</a> is the root
1.159 mike 6930: <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 6931: error</a>; ignore the token. (<a href="#fragment-case">fragment
6932: case</a>)</p>
6933:
6934: <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
6935: 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
6936: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
6937: "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
6938:
6939: </dd>
6940:
6941: <dt>An end tag whose tag name is "col"</dt>
6942: <dd>
6943: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6944: </dd>
6945:
6946: <dt>An end-of-file token</dt>
6947: <dd>
6948:
1.159 mike 6949: <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 6950: element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
6951: case</a>)</p>
6952:
6953: <p>Otherwise, act as described in the "anything else" entry
6954: below.</p>
6955:
6956: </dd>
6957:
6958: <dt>Anything else</dt>
6959: <dd>
6960:
6961: <p>Act as if an end tag with the tag name "colgroup" had been
6962: seen, and then, if that token wasn't ignored, reprocess the
6963: current token.</p>
6964:
6965: <p class="note">The fake end tag token here can only be
6966: ignored in the <a href="#fragment-case">fragment case</a>.</p>
6967:
6968: </dd>
6969:
1.755 mike 6970: </dl><h5 id="parsing-main-intbody"><span class="secno">8.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 6971:
6972: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
6973: mode: in table body">in table body</a>", tokens must be handled as follows:</p>
6974:
6975: <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
6976: <dd>
6977:
6978: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
6979: context</a>. (See below.)</p>
6980:
6981: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
6982: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
6983: in row">in row</a>".</p>
6984:
6985: </dd>
6986:
6987: <dt>A start tag whose tag name is one of: "th", "td"</dt>
6988: <dd>
6989: <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
6990: the tag name "tr" had been seen, then reprocess the current
6991: token.</p>
6992: </dd>
6993:
6994: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
6995: "thead"</dt>
6996: <dd>
6997:
6998: <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
6999: scope</a> with the same tag name as the token, this is a
7000: <a href="#parse-error">parse error</a>. Ignore the token.</p>
7001:
7002: <p>Otherwise:</p>
7003:
7004: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
7005: context</a>. (See below.)</p>
7006:
7007: <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
7008: open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
7009: to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
7010:
7011: </dd>
7012:
7013: <dt>A start tag whose tag name is one of: "caption", "col",
7014: "colgroup", "tbody", "tfoot", "thead"</dt>
7015: <dt>An end tag whose tag name is "table"</dt>
7016: <dd>
7017:
7018: <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
7019: <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
7020: element in table scope</a>, this is a <a href="#parse-error">parse
7021: error</a>. Ignore the token. (<a href="#fragment-case">fragment
7022: case</a>)</p>
7023:
7024: <p>Otherwise:</p>
7025:
7026: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
7027: context</a>. (See below.)</p>
7028:
7029: <p>Act as if an end tag with the same tag name as the
7030: <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
7031: been seen, then reprocess the current token.</p>
7032:
7033: </dd>
7034:
7035: <dt>An end tag whose tag name is one of: "body", "caption",
7036: "col", "colgroup", "html", "td", "th", "tr"</dt>
7037: <dd>
7038: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7039: </dd>
7040:
7041: <dt>Anything else</dt>
7042: <dd>
7043: <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
7044: mode</a>.</p>
7045: </dd>
7046:
7047: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
7048: back to a table body context</dfn>, it means that the UA must,
7049: 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 7050: <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 7051: element, pop elements from the <a href="#stack-of-open-elements">stack of open
7052: elements</a>.</p>
7053:
7054: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 7055: <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 7056: case</a>.</p>
7057:
7058:
1.755 mike 7059: <h5 id="parsing-main-intr"><span class="secno">8.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 7060:
7061: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
7062: mode: in row">in row</a>", tokens must be handled as follows:</p>
7063:
7064: <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
7065: <dd>
7066:
7067: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
7068: context</a>. (See below.)</p>
7069:
7070: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
7071: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
7072: in cell">in cell</a>".</p>
7073:
7074: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
7075: formatting elements</a>.</p>
7076:
7077: </dd>
7078:
7079: <dt>An end tag whose tag name is "tr"</dt>
7080: <dd>
7081:
7082: <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
7083: scope</a> with the same tag name as the token, this is a
7084: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
7085: case</a>)</p>
7086:
7087: <p>Otherwise:</p>
7088:
7089: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
7090: context</a>. (See below.)</p>
7091:
7092: <p>Pop the <a href="#current-node">current node</a> (which will be a
7093: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
7094: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
7095: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
7096: body</a>".</p>
7097:
7098: </dd>
7099:
7100: <dt>A start tag whose tag name is one of: "caption", "col",
7101: "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
7102: <dt>An end tag whose tag name is "table"</dt>
7103: <dd>
7104:
7105: <p>Act as if an end tag with the tag name "tr" had been seen,
7106: then, if that token wasn't ignored, reprocess the current
7107: token.</p>
7108:
7109: <p class="note">The fake end tag token here can only be
7110: ignored in the <a href="#fragment-case">fragment case</a>.</p>
7111:
7112: </dd>
7113:
7114: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
7115: "thead"</dt>
7116: <dd>
7117:
7118: <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
7119: scope</a> with the same tag name as the token, this is a
7120: <a href="#parse-error">parse error</a>. Ignore the token.</p>
7121:
7122: <p>Otherwise, act as if an end tag with the tag name "tr" had
7123: been seen, then reprocess the current token.</p>
7124:
7125: </dd>
7126:
7127: <dt>An end tag whose tag name is one of: "body", "caption",
7128: "col", "colgroup", "html", "td", "th"</dt>
7129: <dd>
7130: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7131: </dd>
7132:
7133: <dt>Anything else</dt>
7134: <dd>
7135: <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
7136: mode</a>.</p>
7137: </dd>
7138:
7139: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
7140: back to a table row context</dfn>, it means that the UA must,
7141: 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 7142: element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1 mike 7143: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
7144:
7145: <p class="note">The <a href="#current-node">current node</a> being an
1.159 mike 7146: <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 7147: case</a>.</p>
7148:
7149:
1.755 mike 7150: <h5 id="parsing-main-intd"><span class="secno">8.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 7151:
7152: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
7153: mode: in cell">in cell</a>", tokens must be handled as follows:</p>
7154:
7155: <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
7156: <dd>
7157:
7158: <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
7159: scope</a> with the same tag name as that of the token, then
7160: this is a <a href="#parse-error">parse error</a> and the token must be
7161: ignored.</p>
7162:
7163: <p>Otherwise:</p>
7164:
7165: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
7166:
7167: <p>Now, if the <a href="#current-node">current node</a> is not an element
7168: with the same tag name as the token, then this is a
7169: <a href="#parse-error">parse error</a>.</p>
7170:
7171: <p>Pop elements from this stack until an element with the same
7172: tag name as the token has been popped from the stack.</p>
7173:
7174: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
7175: the last marker</a>.</p>
7176:
7177: <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
7178: <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
7179: this point.)</p>
7180:
7181: </dd>
7182:
7183: <dt>A start tag whose tag name is one of: "caption", "col",
7184: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
7185: <dd>
7186:
7187: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
7188: <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
7189: a <code>td</code> or <code>th</code> element in table
7190: scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
7191: the token. (<a href="#fragment-case">fragment case</a>)</p>
7192:
7193: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
7194: reprocess the current token.</p>
7195:
7196: </dd>
7197:
7198: <dt>An end tag whose tag name is one of: "body", "caption",
7199: "col", "colgroup", "html"</dt>
7200: <dd>
7201: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7202: </dd>
7203:
7204: <dt>An end tag whose tag name is one of: "table", "tbody",
7205: "tfoot", "thead", "tr"</dt>
7206: <dd>
7207:
7208: <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
7209: scope</a> with the same tag name as that of the token
7210: (which can only happen for "tbody", "tfoot" and "thead", or,
7211: in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
7212: error</a> and the token must be ignored.</p>
7213:
7214: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
7215: reprocess the current token.</p>
7216:
7217: </dd>
7218:
7219: <dt>Anything else</dt>
7220: <dd>
7221: <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
7222: mode</a>.</p>
7223: </dd>
7224:
7225: </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
7226: mean to run the following algorithm:</p>
7227:
7228: <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>
7229: element in table scope</a>, then act as if an end tag token
7230: with the tag name "td" had been seen.</p></li>
7231:
7232: <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
7233: <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
7234: <code>th</code> element in table scope</a>; act as if an end
7235: tag token with the tag name "th" had been seen.</p></li>
7236:
7237: </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
7238: 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
7239: the same time, nor can it have neither when the <a href="#insertion-mode">insertion
7240: mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
7241: cell</a>".</p>
7242:
7243:
1.755 mike 7244: <h5 id="parsing-main-inselect"><span class="secno">8.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 7245:
7246: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
7247: mode: in select">in select</a>", tokens must be handled as follows:</p>
7248:
7249: <dl class="switch"><dt>A character token</dt>
7250: <dd>
7251: <p><a href="#insert-a-character" title="insert a character">Insert the token's
7252: character</a> into the <a href="#current-node">current node</a>.</p>
7253: </dd>
7254:
7255: <dt>A comment token</dt>
7256: <dd>
7257: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
7258: node</a> with the <code title="">data</code> attribute set to
7259: the data given in the comment token.</p>
7260: </dd>
7261:
7262: <dt>A DOCTYPE token</dt>
7263: <dd>
7264: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7265: </dd>
7266:
7267: <dt>A start tag whose tag name is "html"</dt>
7268: <dd>
7269: <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
7270: mode</a>.</p>
7271: </dd>
7272:
7273: <dt>A start 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, act as if an end tag with the tag name "option" had
7278: been seen.</p>
7279:
7280: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
7281:
7282: </dd>
7283:
7284: <dt>A start tag whose tag name is "optgroup"</dt>
7285: <dd>
7286:
7287: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
7288: element, act as if an end tag with the tag name "option" had
7289: been seen.</p>
7290:
7291: <p>If the <a href="#current-node">current node</a> is an
7292: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
7293: tag name "optgroup" had been seen.</p>
7294:
7295: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
7296:
7297: </dd>
7298:
7299: <dt>An end tag whose tag name is "optgroup"</dt>
7300: <dd>
7301:
7302: <p>First, if the <a href="#current-node">current node</a> is an
7303: <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
7304: it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
7305: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
7306: the tag name "option" had been seen.</p>
7307:
7308: <p>If the <a href="#current-node">current node</a> is an
7309: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
7310: <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
7311: <a href="#parse-error">parse error</a>; ignore the token.</p>
7312:
7313: </dd>
7314:
7315: <dt>An end tag whose tag name is "option"</dt>
7316: <dd>
7317:
7318: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
7319: element, then pop that node from the <a href="#stack-of-open-elements">stack of open
7320: elements</a>. Otherwise, this is a <a href="#parse-error">parse
7321: error</a>; ignore the token.</p>
7322:
7323: </dd>
7324:
7325: <dt>An end tag whose tag name is "select"</dt>
7326: <dd>
7327:
7328: <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
7329: scope</a> with the same tag name as the token, this is a
7330: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
7331: case</a>)</p>
7332:
7333: <p>Otherwise:</p>
7334:
7335: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
7336: until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
7337: stack.</p>
7338:
7339: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
7340:
7341: </dd>
7342:
7343: <dt>A start tag whose tag name is "select"</dt>
7344: <dd>
7345:
7346: <p><a href="#parse-error">Parse error</a>. Act as if the token had been
7347: an end tag with the tag name "select" instead.</p>
7348:
7349: </dd>
7350:
7351: <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
7352: <dd>
1.73 mike 7353:
7354: <p><a href="#parse-error">Parse error</a>.</p>
7355:
1.124 mike 7356: <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>
7357: element in table scope</a>, ignore the token. (<a href="#fragment-case">fragment
7358: case</a>)</p>
1.73 mike 7359:
7360: <p>Otherwise, act as if an end tag with the tag name "select" had
7361: been seen, and reprocess the token.</p>
7362:
1.1 mike 7363: </dd>
7364:
7365: <dt>A start tag token whose tag name is "script"</dt>
7366: <dd>
7367: <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
7368: mode</a>.</p>
7369: </dd>
7370:
7371: <dt>An end-of-file token</dt>
7372: <dd>
7373:
7374: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 7375: <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 7376: error</a>.</p>
7377:
7378: <p class="note">It can only be the <a href="#current-node">current node</a> in
7379: the <a href="#fragment-case">fragment case</a>.</p>
7380:
7381: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7382:
7383: </dd>
7384:
7385: <dt>Anything else</dt>
7386: <dd>
7387: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7388: </dd>
7389:
1.755 mike 7390: </dl><h5 id="parsing-main-inselectintable"><span class="secno">8.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 7391:
7392: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
7393: mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
7394:
7395: <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
7396: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
7397: <dd>
7398: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
7399: name "select" had been seen, and reprocess the token.</p>
7400: </dd>
7401:
7402: <dt>An end tag whose tag name is one of: "caption", "table",
7403: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
7404: <dd>
7405:
7406: <p><a href="#parse-error">Parse error</a>.</p>
7407:
7408: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
7409: element in table scope</a> with the same tag name as that
7410: of the token, then act as if an end tag with the tag name
7411: "select" had been seen, and reprocess the token. Otherwise,
7412: ignore the token.</p>
7413:
7414: </dd>
7415:
7416: <dt>Anything else</dt>
7417: <dd>
7418: <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
7419: mode</a>.</p>
7420: </dd>
7421:
1.755 mike 7422: </dl><h5 id="parsing-main-inforeign"><span class="secno">8.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 7423:
7424: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
7425: mode: in foreign content">in foreign content</a>", tokens must be
7426: handled as follows:</p>
7427:
7428: <dl class="switch"><dt>A character token</dt>
7429: <dd>
7430:
7431: <p><a href="#insert-a-character" title="insert a character">Insert the token's
7432: character</a> into the <a href="#current-node">current node</a>.</p>
7433:
7434: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
7435: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
7436: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
7437: flag</a> to "not ok".</p>
7438:
7439: </dd>
7440:
7441: <dt>A comment token</dt>
7442: <dd>
7443: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
7444: node</a> with the <code title="">data</code> attribute set to
7445: the data given in the comment token.</p>
7446: </dd>
7447:
7448: <dt>A DOCTYPE token</dt>
7449: <dd>
7450: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7451: </dd>
7452:
1.724 mike 7453: <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="infrastructure.html#svg-namespace">SVG namespace</a>.</dt>
1.1 mike 7454: <dd>
7455:
7456: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
7457: elements</a>.</p>
7458:
7459: <p>Let the <var title="">old insertion point</var> have the
7460: same value as the current <a href="#insertion-point">insertion point</a>. Let
7461: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
7462: input character</a>.</p>
7463:
7464: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
7465: one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
7466:
7467: <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
7468: the <code title="">script</code> element</a> according to the SVG
1.187 mike 7469: rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
1.1 mike 7470:
1.159 mike 7471: <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 7472: tokenizer</a>, the parser will not be executed reentrantly,
7473: since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
7474:
7475: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
7476: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
7477: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
7478:
7479: <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
7480: <a href="#insertion-point">insertion point</a> to its previous value. This value
7481: might be the "undefined" value.)</p>
7482:
7483: </dd>
7484:
1.724 mike 7485: <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="infrastructure.html#mathml-namespace">MathML namespace</a>.</dt>
7486: <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="infrastructure.html#mathml-namespace">MathML namespace</a>.</dt>
7487: <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="infrastructure.html#mathml-namespace">MathML namespace</a>.</dt>
7488: <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="infrastructure.html#mathml-namespace">MathML namespace</a>.</dt>
7489: <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="infrastructure.html#mathml-namespace">MathML namespace</a>.</dt>
7490: <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="infrastructure.html#mathml-namespace">MathML namespace</a>.</dt>
7491: <dt>A start tag, if the <a href="#current-node">current node</a> is a <code title="">foreignObject</code> element in the <a href="infrastructure.html#svg-namespace">SVG namespace</a>.</dt>
7492: <dt>A start tag, if the <a href="#current-node">current node</a> is a <code title="">desc</code> element in the <a href="infrastructure.html#svg-namespace">SVG namespace</a>.</dt>
7493: <dt>A start tag, if the <a href="#current-node">current node</a> is a <code title="">title</code> element in the <a href="infrastructure.html#svg-namespace">SVG namespace</a>.</dt>
7494: <dt>A start tag, if the <a href="#current-node">current node</a> is an element in the <a href="infrastructure.html#html-namespace-0">HTML namespace</a>.</dt>
1.1 mike 7495: <dt>An end tag</dt>
7496: <dd>
7497:
7498: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
7499: <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
7500:
7501: <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
7502: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
1.336 mike 7503: content</a>", but there is no element <a href="#has-an-element-in-scope" title="has an
7504: element in scope">in scope</a> that has a namespace other than
1.724 mike 7505: the <a href="infrastructure.html#html-namespace-0">HTML namespace</a>, switch the <a href="#insertion-mode">insertion
1.1 mike 7506: mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
7507:
7508: </dd>
7509:
7510: <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
7511: "blockquote", "body"<!--by inspection-->, "br", "center", "code",
1.422 mike 7512: "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
7513: uniformly throughout the parser -->, "em", "embed", "h1", "h2",
7514: "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
1.1 mike 7515: completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
7516: "li", "listing"<!-- so that pre and listing can be handled
7517: uniformly throughout the parser -->, "menu", "meta", "nobr",
7518: "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
7519: the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
7520: "span", "strong", "strike"<!-- so that s and strike can be handled
7521: uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
1.305 mike 7522: "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt> <!-- this
7523: list was determined empirically by studying over 6,000,000,000
1.422 mike 7524: pages that were specifically not XML pages -->
7525: <dt>A start tag whose tag name is "font", if the token has any
7526: attributes named "color", "face", or "size"</dt> <!-- the
7527: attributes here are required so that SVG <font> will go through as
7528: SVG but legacy <font>s won't -->
7529: <dt>An end-of-file token</dt> <dd>
1.1 mike 7530:
7531: <p><a href="#parse-error">Parse error</a>.</p>
7532:
7533: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
1.724 mike 7534: the <a href="#current-node">current node</a> is in the <a href="infrastructure.html#html-namespace-0">HTML
1.1 mike 7535: namespace</a>.</p>
7536:
7537: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
7538: insertion mode</a>, and reprocess the token.</p>
7539:
7540: </dd>
7541:
7542: <dt>Any other start tag</dt>
7543: <dd>
7544:
7545: <p>If the <a href="#current-node">current node</a> is an element in the
1.724 mike 7546: <a href="infrastructure.html#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
1.1 mike 7547: attributes</a> for the token. (This fixes the case of MathML
7548: attributes that are not all lowercase.)</p>
7549:
1.724 mike 7550: <p>If the <a href="#current-node">current node</a> is an element in the <a href="infrastructure.html#svg-namespace">SVG
1.1 mike 7551: namespace</a>, and the token's tag name is one of the ones in
7552: the first column of the following table, change the tag name to
7553: the name given in the corresponding cell in the second
7554: column. (This fixes the case of SVG elements that are not all
7555: lowercase.)</p>
7556:
7557: <table><thead><tr><th> Tag name </th><th> Element name
7558: </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
7559: </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
7560: </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
7561: </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
7562: </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
7563: </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
7564: </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
7565: </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
7566: </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
7567: </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
7568: </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
7569: </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
7570: </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
7571: </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
7572: </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
7573: </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
7574: </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
7575: </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
7576: </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
7577: </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
7578: </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
7579: </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
7580: </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
7581: </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
7582: </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
7583: </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
7584: </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
7585: </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
7586: </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
7587: </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
7588: </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
7589: </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
7590: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
7591: </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
7592: </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
7593: <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
7594: </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
1.724 mike 7595: </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="infrastructure.html#svg-namespace">SVG
1.1 mike 7596: namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
7597: token. (This fixes the case of SVG attributes that are not all
7598: lowercase.)</p>
7599:
7600: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
7601: fixes the use of namespaced attributes, in particular XLink in
7602: SVG.)</p>
7603:
7604: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
7605: same namespace as the <a href="#current-node">current node</a>.</p>
7606:
7607: <p>If the token has its <i>self-closing flag</i> set, pop the
7608: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
7609: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
7610: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
7611:
7612: </dd>
7613:
1.755 mike 7614: </dl><h5 id="parsing-main-afterbody"><span class="secno">8.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 7615:
7616: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
7617: mode: after body">after body</a>", tokens must be handled as follows:</p>
7618:
7619: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
7620: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7621: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7622: <dd>
7623: <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
7624: mode</a>.</p>
7625: </dd>
7626:
7627: <dt>A comment token</dt>
7628: <dd>
7629: <p>Append a <code>Comment</code> node to the first element in
1.159 mike 7630: 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 7631: element), with the <code title="">data</code> attribute set to
7632: the data given in the comment token.</p>
7633: </dd>
7634:
7635: <dt>A DOCTYPE token</dt>
7636: <dd>
7637: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7638: </dd>
7639:
7640: <dt>A start tag whose tag name is "html"</dt>
7641: <dd>
7642: <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
7643: mode</a>.</p>
7644: </dd>
7645:
7646: <dt>An end tag whose tag name is "html"</dt>
7647: <dd>
7648:
7649: <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
7650: fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
7651: error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
7652:
7653: <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
7654: body</a>".</p>
7655:
7656: </dd>
7657:
7658: <dt>An end-of-file token</dt>
7659: <dd>
7660: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7661: </dd>
7662:
7663: <dt>Anything else</dt>
7664: <dd>
7665:
7666: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
7667: mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
7668: body</a>" and reprocess the token.</p>
7669:
7670: </dd>
7671:
1.755 mike 7672: </dl><h5 id="parsing-main-inframeset"><span class="secno">8.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 7673:
7674: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
7675: mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
7676:
7677: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
7678: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7679: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7680: <dd>
7681: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
7682: the <a href="#current-node">current node</a>.</p>
7683: </dd>
7684:
7685: <dt>A comment token</dt>
7686: <dd>
7687: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
7688: node</a> with the <code title="">data</code> attribute set to
7689: the data given in the comment token.</p>
7690: </dd>
7691:
7692: <dt>A DOCTYPE token</dt>
7693: <dd>
7694: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7695: </dd>
7696:
7697: <dt>A start tag whose tag name is "html"</dt>
7698: <dd>
7699: <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
7700: mode</a>.</p>
7701: </dd>
7702:
7703: <dt>A start tag whose tag name is "frameset"</dt>
7704: <dd>
7705: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
7706: </dd>
7707:
7708: <dt>An end tag whose tag name is "frameset"</dt>
7709: <dd>
7710:
7711: <p>If the <a href="#current-node">current node</a> is the root
1.159 mike 7712: <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 7713: error</a>; ignore the token. (<a href="#fragment-case">fragment
7714: case</a>)</p>
7715:
7716: <p>Otherwise, pop the <a href="#current-node">current node</a> from the
7717: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
7718:
7719: <p>If the parser was <em>not</em> originally created as part
7720: of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
7721: (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5 mike 7722: node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1 mike 7723: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
7724: frameset</a>".</p>
7725:
7726: </dd>
7727:
7728: <dt>A start tag whose tag name is "frame"</dt>
7729: <dd>
7730:
7731: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
7732: Immediately pop the <a href="#current-node">current node</a> off the
7733: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
7734:
7735: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
7736: token's <i>self-closing flag</i></a>, if it is set.</p>
7737:
7738: </dd>
7739:
7740: <dt>A start tag whose tag name is "noframes"</dt>
7741: <dd>
7742: <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
7743: mode</a>.</p>
7744: </dd>
7745:
7746: <dt>An end-of-file token</dt>
7747: <dd>
7748:
7749: <p>If the <a href="#current-node">current node</a> is not the root
1.159 mike 7750: <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 7751: error</a>.</p>
7752:
7753: <p class="note">It can only be the <a href="#current-node">current node</a> in
7754: the <a href="#fragment-case">fragment case</a>.</p>
7755:
7756: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7757:
7758: </dd>
7759:
7760: <dt>Anything else</dt>
7761: <dd>
7762: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7763: </dd>
7764:
1.755 mike 7765: </dl><h5 id="parsing-main-afterframeset"><span class="secno">8.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 7766:
7767: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
7768: mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
7769:
7770: <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
7771: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
7772: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7773: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7774: <dd>
7775: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
7776: the <a href="#current-node">current node</a>.</p>
7777: </dd>
7778:
7779: <dt>A comment token</dt>
7780: <dd>
7781: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
7782: node</a> with the <code title="">data</code> attribute set to
7783: the data given in the comment token.</p>
7784: </dd>
7785:
7786: <dt>A DOCTYPE token</dt>
7787: <dd>
7788: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7789: </dd>
7790:
7791: <dt>A start tag whose tag name is "html"</dt>
7792: <dd>
7793: <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
7794: mode</a>.</p>
7795: </dd>
7796:
7797: <dt>An end tag whose tag name is "html"</dt>
7798: <dd>
7799: <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
7800: frameset</a>".</p>
7801: </dd>
7802:
7803: <dt>A start tag whose tag name is "noframes"</dt>
7804: <dd>
7805: <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
7806: mode</a>.</p>
7807: </dd>
7808:
7809: <dt>An end-of-file token</dt>
7810: <dd>
7811: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7812: </dd>
7813:
7814: <dt>Anything else</dt>
7815: <dd>
7816: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7817: </dd>
7818:
1.755 mike 7819: </dl><h5 id="the-after-after-body-insertion-mode"><span class="secno">8.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 7820:
7821: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
7822: mode: after after body">after after body</a>", tokens must be handled as follows:</p>
7823:
7824: <dl class="switch"><dt>A comment token</dt>
7825: <dd>
1.810 mike 7826: <p>Append a <code>Comment</code> node to the <code><a href="infrastructure.html#document">Document</a></code>
1.1 mike 7827: object with the <code title="">data</code> attribute set to the
7828: data given in the comment token.</p>
7829: </dd>
7830:
7831: <dt>A DOCTYPE token</dt>
7832: <dt>A character token that is one of U+0009 CHARACTER
7833: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7834: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7835: <dt>A start tag whose tag name is "html"</dt>
7836: <dd>
7837: <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
7838: mode</a>.</p>
7839: </dd>
7840:
7841: <dt>An end-of-file token</dt>
7842: <dd>
7843: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7844: </dd>
7845:
7846: <dt>Anything else</dt>
7847: <dd>
7848: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
7849: to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
7850: reprocess the token.</p>
7851: </dd>
7852:
1.755 mike 7853: </dl><h5 id="the-after-after-frameset-insertion-mode"><span class="secno">8.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 7854:
7855: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
7856: mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
7857:
7858: <dl class="switch"><dt>A comment token</dt>
7859: <dd>
1.810 mike 7860: <p>Append a <code>Comment</code> node to the <code><a href="infrastructure.html#document">Document</a></code>
1.1 mike 7861: object with the <code title="">data</code> attribute set to the
7862: data given in the comment token.</p>
7863: </dd>
7864:
7865: <dt>A DOCTYPE token</dt>
7866: <dt>A character token that is one of U+0009 CHARACTER
7867: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
7868: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
7869: <dt>A start tag whose tag name is "html"</dt>
7870: <dd>
7871: <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
7872: mode</a>.</p>
7873: </dd>
7874:
7875: <dt>An end-of-file token</dt>
7876: <dd>
7877: <p><a href="#stop-parsing">Stop parsing</a>.</p>
7878: </dd>
7879:
7880: <dt>A start tag whose tag name is "noframes"</dt>
7881: <dd>
7882: <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
7883: mode</a>.</p>
7884: </dd>
7885:
7886: <dt>Anything else</dt>
7887: <dd>
7888: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
7889: </dd>
7890:
1.266 mike 7891: </dl></div><div class="impl">
7892:
1.755 mike 7893: <h4 id="the-end"><span class="secno">8.2.6 </span>The end</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 7894:
7895: <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
1.484 mike 7896: the document, the user agent must run the following steps:</p>
1.1 mike 7897:
1.484 mike 7898: <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
7899: "interactive" <!-- this also synchronously fires an event --> and
7900: the <a href="#insertion-point">insertion point</a> to undefined.</p></li>
7901:
7902: <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
7903: document has finished parsing</a> is not empty, run these
7904: substeps:</p>
7905:
1.794 mike 7906: <ol><li><p><a href="webappapis.html#spin-the-event-loop">Spin the event loop</a> until the first
1.484 mike 7907: <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
7908: execute when the document has finished parsing</a> has its
7909: <a href="semantics.html#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag set <em>and</em> there
7910: is no <a href="semantics.html#a-style-sheet-blocking-scripts" title="a style sheet blocking scripts">style sheet
7911: blocking scripts</a>.</p></li>
7912:
7913: <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute</a> the
7914: 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
7915: execute when the document has finished parsing</a>.</p></li>
7916:
7917: <li><p>Remove the first <code><a href="semantics.html#script">script</a></code> element from the
7918: <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
7919: finished parsing</a> (i.e. shift out the first entry in the
7920: list).</p></li>
7921:
7922: <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
7923: document has finished parsing</a> is still not empty, repeat
7924: these substeps again from substep 1.</p>
7925:
7926: </li></ol></li>
7927:
1.794 mike 7928: <li><p><a href="webappapis.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 7929: scripts that will execute as soon as possible</a> is
7930: empty.</p></li>
7931:
1.794 mike 7932: <li><p><a href="webappapis.html#queue-a-task">Queue a task</a> to <a href="webappapis.html#fire-a-simple-event">fire a simple
1.484 mike 7933: event</a> named <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
1.810 mike 7934: <code><a href="infrastructure.html#document">Document</a></code>.</p></li>
1.484 mike 7935:
1.794 mike 7936: <li><p><a href="webappapis.html#spin-the-event-loop">Spin the event loop</a> until there is nothing that
1.484 mike 7937: <dfn id="delay-the-load-event" title="delay the load event">delays the load event</dfn> in
1.810 mike 7938: the <code><a href="infrastructure.html#document">Document</a></code>.</p></li>
1.484 mike 7939:
1.794 mike 7940: <li><p><a href="webappapis.html#queue-a-task">Queue a task</a> to set the <a href="dom.html#current-document-readiness">current document
1.484 mike 7941: readiness</a> to "complete". <!-- this also fires an event
7942: synchronously during the task --></p></li>
1.1 mike 7943:
1.810 mike 7944: <li><p>If the <code><a href="infrastructure.html#document">Document</a></code> is in a <a href="browsers.html#browsing-context">browsing
1.794 mike 7945: context</a>, then <a href="webappapis.html#queue-a-task">queue a task</a> to <a href="webappapis.html#fire-a-simple-event">fire a
1.460 mike 7946: simple event</a> named <code title="event-load">load</code> at
1.810 mike 7947: the <code><a href="infrastructure.html#document">Document</a></code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
1.1 mike 7948: its <code title="dom-event-target">target</code> set to the
1.810 mike 7949: <code><a href="infrastructure.html#document">Document</a></code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
1.484 mike 7950: <code><a href="browsers.html#window">Window</a></code> object).</p></li>
1.1 mike 7951:
1.810 mike 7952: <li><p>If the <code><a href="infrastructure.html#document">Document</a></code> is in a <a href="browsers.html#browsing-context">browsing
1.794 mike 7953: context</a>, then <a href="webappapis.html#queue-a-task">queue a task</a> to <a href="webappapis.html#fire-a-simple-event">fire a
1.569 mike 7954: simple event</a> named <code title="event-pageshow">pageshow</code> at the
1.810 mike 7955: <code><a href="infrastructure.html#document">Document</a></code>'s <code><a href="browsers.html#window">Window</a></code> object.</p></li>
1.569 mike 7956:
1.810 mike 7957: <li><p>If the <code><a href="infrastructure.html#document">Document</a></code> has a <a href="history.html#pending-state-object">pending state
1.794 mike 7958: object</a>, then <a href="webappapis.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.810 mike 7959: <code><a href="infrastructure.html#document">Document</a></code>'s <code><a href="browsers.html#window">Window</a></code> object using the
1.1 mike 7960: <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
7961: current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
1.484 mike 7962: must bubble but not be cancelable and has no default
7963: action.</p></li>
1.1 mike 7964:
1.810 mike 7965: <li><p>If the <code><a href="infrastructure.html#document">Document</a></code> has any <a href="offline.html#pending-application-cache-download-process-tasks">pending
1.794 mike 7966: application cache download process tasks</a>, then <a href="webappapis.html#queue-a-task" title="queue a task">queue</a> each such <a href="webappapis.html#concept-task" title="concept-task">task</a> in the order they were added to
1.725 mike 7967: the list of <a href="offline.html#pending-application-cache-download-process-tasks">pending application cache download process
7968: tasks</a>, and then empty the list of <a href="offline.html#pending-application-cache-download-process-tasks">pending application
1.794 mike 7969: cache download process tasks</a>. The <a href="webappapis.html#task-source">task source</a>
7970: for these <a href="webappapis.html#concept-task" title="concept-task">tasks</a> is the
7971: <a href="webappapis.html#networking-task-source">networking task source</a>.</p></li>
1.725 mike 7972:
1.810 mike 7973: <li><p>The <code><a href="infrastructure.html#document">Document</a></code> is now <dfn id="completely-loaded">completely
1.725 mike 7974: loaded</dfn>.</p></li>
7975:
1.794 mike 7976: </ol><p>Except where otherwise specified, the <a href="webappapis.html#task-source">task source</a>
7977: for the <a href="webappapis.html#concept-task" title="concept-task">tasks</a> mentioned in this
7978: section is the <a href="webappapis.html#dom-manipulation-task-source">DOM manipulation task source</a>.</p>
1.1 mike 7979:
1.266 mike 7980: </div><div class="impl">
1.1 mike 7981:
1.755 mike 7982: <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">8.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 7983:
7984: <p>When an application uses an <a href="#html-parser">HTML parser</a> in
7985: conjunction with an XML pipeline, it is possible that the
7986: constructed DOM is not compatible with the XML tool chain in certain
7987: subtle ways. For example, an XML toolchain might not be able to
7988: represent attributes with the name <code title="">xmlns</code>,
7989: since they conflict with the Namespaces in XML syntax. There is also
7990: some data that the <a href="#html-parser">HTML parser</a> generates that isn't
7991: included in the DOM itself. This section specifies some rules for
7992: handling these issues.</p>
7993:
7994: <p>If the XML API being used doesn't support DOCTYPEs, the tool may
7995: drop DOCTYPEs altogether.</p>
7996:
7997: <p>If the XML API doesn't support attributes in no namespace that
7998: are named "<code title="">xmlns</code>", attributes whose names
7999: start with "<code title="">xmlns:</code>", or attributes in the
1.724 mike 8000: <a href="infrastructure.html#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
1.1 mike 8001: attributes.</p>
8002:
8003: <p>The tool may annotate the output with any namespace declarations
8004: required for proper operation.</p>
8005:
8006: <p>If the XML API being used restricts the allowable characters in
8007: the local names of elements and attributes, then the tool may map
8008: all element and attribute local names that the API wouldn't support
8009: to a set of names that <em>are</em> allowed, by replacing any
8010: character that isn't supported with the uppercase letter U and the
8011: six digits of the character's Unicode code point when expressed in
8012: hexadecimal, using digits 0-9 and capital letters A-F as the
8013: symbols, in increasing numeric order.</p>
8014:
8015: <p class="example">For example, the element name <code title="">foo<bar</code>, which can be output by the <a href="#html-parser">HTML
8016: parser</a>, though it is neither a legal HTML element name nor a
8017: well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
8018: element name (though it's still not legal in HTML by any means).</p>
8019:
8020: <p class="example">As another example, consider the attribute
8021: <code>xlink:href</code>. Used on a MathML element, it becomes, after
8022: being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
8023: attribute with a prefix "<code title="">xlink</code>" and a local
8024: name "<code title="">href</code>". However, used on an HTML element,
8025: it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
8026: might not be accepted by an XML API. It could thus get converted,
8027: becoming "<code title="">xlinkU00003Ahref</code>".</p>
8028:
8029: <p class="note">The resulting names from this conversion
8030: conveniently can't clash with any attribute generated by the
8031: <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
8032: those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
8033: algorithm's table.</p>
8034:
8035: <p>If the XML API restricts comments from having two consecutive
8036: U+002D HYPHEN-MINUS characters (--), the tool may insert a single
8037: U+0020 SPACE character between any such offending characters.</p>
8038:
8039: <p>If the XML API restricts comments from ending in a
8040: U+002D HYPHEN-MINUS character (-), the tool may insert a single
8041: U+0020 SPACE character at the end of such comments.</p>
8042:
8043: <p>If the XML API restricts allowed characters in character data,
1.439 mike 8044: attribute values, or comments, the tool may replace any U+000C FORM
8045: FEED (FF) character with a U+0020 SPACE character, and any other
8046: literal non-XML character with a U+FFFD REPLACEMENT CHARACTER.</p>
1.1 mike 8047:
8048: <p>If the tool has no way to convey out-of-band information, then
8049: the tool may drop the following information:</p>
8050:
8051: <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
8052: <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>
8053:
8054: <li>The association between form controls and forms that aren't
8055: their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
8056: <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
8057:
8058: </ul><p class="note">The mutations allowed by this section apply
8059: <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
8060: applied. For example, a <code title=""><a::></code> start tag
8061: will be closed by a <code title=""></a::></code> end tag, and
8062: never by a <code title=""></aU00003AU00003A></code> end tag, even
8063: if the user agent is using the rules above to then generate an
8064: actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
8065:
1.266 mike 8066: </div><div class="impl">
1.1 mike 8067:
1.755 mike 8068: <h4 id="an-introduction-to-error-handling-and-strange-cases-in-the-parser"><span class="secno">8.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 8069:
8070: <p><i>This section is non-normative.</i></p>
8071:
8072: <p>This section examines some erroneous markup and discusses how
8073: the <a href="#html-parser">HTML parser</a> handles these cases.</p>
8074:
8075:
1.755 mike 8076: <h5 id="misnested-tags:-b-i-b-i"><span class="secno">8.2.8.1 </span>Misnested tags: <b><i></b></i></h5>
1.1 mike 8077:
8078: <p><i>This section is non-normative.</i></p>
8079:
8080: <p>The most-often discussed example of erroneous markup is as
8081: follows:</p>
8082:
8083: <pre><p>1<b>2<i>3</b>4</i>5</p></pre>
8084:
8085: <p>The parsing of this markup is straightforward up to the "3". At
8086: this point, the DOM looks like this:</p>
8087:
1.159 mike 8088: <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
8089: 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 8090: <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
8091: formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
8092: <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>
8093:
8094: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
8095: invoked. This is a simple case, in that the <var title="">formatting
8096: element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
8097: <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
1.159 mike 8098: elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element-0">html</a></code>,
8099: <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 8100: active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
8101: DOM tree is unmodified at this point.</p>
8102:
8103: <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
8104: the active formatting elements</a>, in this case just the
8105: <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
8106: for the "4" text node. After the end tag token for the "i" is also
8107: received, and the "5" text node is inserted, the DOM looks as
8108: follows:</p>
8109:
1.755 mike 8110: <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">8.2.8.2 </span>Misnested tags: <b><p></b></p></h5>
1.1 mike 8111:
8112: <p><i>This section is non-normative.</i></p>
8113:
8114: <p>A case similar to the previous one is the following:</p>
8115:
8116: <pre><b>1<p>2</b>3</p></pre>
8117:
8118: <p>Up to the "2" the parsing here is straightforward:</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="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 8121: "b" is parsed.</p>
8122:
8123: <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
1.159 mike 8124: elements</a> has four elements on it: <code><a href="semantics.html#the-html-element-0">html</a></code>,
8125: <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 8126: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
8127: <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>
8128:
8129: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
8130: in the previous example. However, in this case, there <em>is</em> a
8131: <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
8132: this time the adoption agency algorithm isn't skipped over.</p>
8133:
1.159 mike 8134: <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1 mike 8135: element. A conceptual "bookmark" marks the position of the
8136: <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
8137: elements</a>, but since that list has only one element in it,
8138: it won't have much effect.</p>
8139:
8140: <p>As the algorithm progresses, <var title="">node</var> ends up set
8141: to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
8142: node</var> ends up set to the <var title="">furthest block</var>
8143: (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
8144:
8145: <p>The <var title="">last node</var> gets appended (moved) to the
8146: <var title="">common ancestor</var>, so that the DOM looks like:</p>
8147:
1.159 mike 8148: <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 8149: <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
8150:
1.159 mike 8151: <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 8152: <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
8153:
1.159 mike 8154: <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 8155: active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
8156: elements</a>, so that when the "3" is parsed, it is appended to
8157: the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
8158:
1.755 mike 8159: <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">8.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 8160:
8161: <p><i>This section is non-normative.</i></p>
8162:
8163: <p>Error handling in tables is, for historical reasons, especially
8164: strange. For example, consider the following markup:</p>
8165:
8166: <pre><table><strong><b></strong><tr><td>aaa</td></tr><strong>bbb</strong></table>ccc</pre>
8167:
8168: <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
8169: directly inside a table like that, and the parser handles this case
8170: 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
8171: examining the DOM tree as it stands just after the
8172: <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
8173:
1.159 mike 8174: <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 8175: tag has been seen:</p>
8176:
1.159 mike 8177: <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
8178: 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 8179: <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
8180: resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
8181: elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
8182: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
8183: table">in table</a>".</p>
8184:
8185: <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
8186: to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
8187: 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
8188: then handled in a rather straight-forward manner, taking the parser
8189: through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
8190: body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
8191: row</a>" insertion modes, after which the DOM looks as
8192: follows:</p>
8193:
1.159 mike 8194: <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
8195: 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 8196: <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
8197: formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
8198: it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
8199: mode: in row">in row</a>".</p>
8200:
8201: <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
8202: <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
8203: 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
8204: mode</a>).</p>
8205:
1.159 mike 8206: <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 8207: no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
8208: node:</p>
8209:
1.159 mike 8210: <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 8211: handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
1.159 mike 8212: 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 8213: 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
8214: elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
8215: marker having been removed by the "td" end tag token); and the
8216: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
8217: table body">in table body</a>".</p>
8218:
8219: <p>Thus it is that the "bbb" character tokens are found. These
8220: trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
8221: text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
8222: insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
8223: body">in table body</a>"). The character tokens are collected,
8224: and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
8225: seen, they are processed as a group. Since they are not all spaces,
8226: 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,
8227: which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
8228: body</a>" insertion mode but with <a href="#foster-parent" title="foster
8229: parent">foster parenting</a>.</p>
8230:
8231: <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
8232: active formatting elements are reconstructed</a>, a
8233: <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
8234: parent">foster parented</a>, and then the "bbb" text node is
8235: appended to it:</p>
8236:
1.159 mike 8237: <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
8238: <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 8239: <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
8240: this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
8241: formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
8242: and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
8243: mode: in table body">in table body</a>".</p>
8244:
8245: <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
8246: character">space characters</a> instead of "bbb", then those
8247: <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
8248: appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
8249:
8250: <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
8251: tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
8252: elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
8253: but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
8254: elements</a>, so the "ccc" character tokens after the table
8255: result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
8256: time after the table:</p>
8257:
1.755 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="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">8.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 8259:
8260: <p><i>This section is non-normative.</i></p>
8261:
8262: <p>Consider the following markup, which for this example we will
8263: 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 8264: content of an <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code> in another document with the
1.1 mike 8265: <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
8266:
8267: <pre><div id=a>
8268: <script>
8269: var div = document.getElementById('a');
8270: parent.document.body.appendChild(div);
8271: </script>
8272: <script>
8273: alert(document.URL);
8274: </script>
8275: </div>
8276: <script>
8277: alert(document.URL);
8278: </script></pre>
8279:
8280: <p>Up to the first "script" end tag, before the script is parsed,
8281: the result is relatively straightforward:</p>
8282:
1.306 mike 8283: <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="">
8284: </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 8285: and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
8286:
1.810 mike 8287: <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><a href="infrastructure.html#document">Document</a></code> of the
1.1 mike 8288: aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
8289: <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
1.306 mike 8290: <code><a href="semantics.html#the-div-element">div</a></code> element</em>.</p>
1.1 mike 8291:
8292: <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
1.810 mike 8293: is inserted <em>into the outer <code><a href="infrastructure.html#document">Document</a></code>
1.1 mike 8294: object</em>.</p>
8295:
1.794 mike 8296: <p>This also means that the <a href="webappapis.html#script-s-global-object">script's global object</a> is
1.1 mike 8297: the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
8298: object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
1.159 mike 8299: <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>.</p>
1.1 mike 8300:
8301: <p class="note">This isn't a security problem since the script that
1.810 mike 8302: moves the <code><a href="semantics.html#the-div-element">div</a></code> into the outer <code><a href="infrastructure.html#document">Document</a></code> can
8303: only do so because the two <code><a href="infrastructure.html#document">Document</a></code> object have the
1.714 mike 8304: same <a href="browsers.html#origin">origin</a>.</p>
1.1 mike 8305:
8306: <p>Thus, the first alert says "http://example.com/outer".</p>
8307:
1.306 mike 8308: <p>Once the <code><a href="semantics.html#the-div-element">div</a></code> element's end tag is parsed, the
8309: <code><a href="semantics.html#the-div-element">div</a></code> element is popped off the stack, and so the next
1.810 mike 8310: <code><a href="semantics.html#script">script</a></code> element is in the inner <code><a href="infrastructure.html#document">Document</a></code>:</p>
1.1 mike 8311:
1.159 mike 8312: <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 8313:
8314:
8315:
8316:
1.755 mike 8317: <h3 id="serializing-html-fragments"><span class="secno">8.3 </span>Serializing HTML fragments</h3><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 8318:
8319: <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
8320: algorithm</dfn>. The algorithm takes as input a DOM
1.810 mike 8321: <code><a href="infrastructure.html#element">Element</a></code> or <code><a href="infrastructure.html#document">Document</a></code>, referred to as <var title="">the node</var>, and either returns a string or raises an
1.1 mike 8322: exception.</p>
8323:
8324: <p class="note">This algorithm serializes the <em>children</em> of
8325: the node being serialized, not the node itself.</p>
8326:
8327: <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
8328: the empty string.</p></li>
8329:
8330: <li>
8331:
8332: <p>For each child node of <var title="">the node</var>, in
8333: <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
8334:
8335: </p><ol><li><p>Let <var title="">current node</var> be the child node
8336: being processed.</p></li>
8337:
8338: <li>
8339:
8340: <p>Append the appropriate string from the following list to
8341: <var title="">s</var>:</p>
8342:
8343: <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
8344:
8345: <dd>
8346:
1.588 mike 8347: <p>Append a U+003C LESS-THAN SIGN character character (<),
8348: followed by the element's tag name. (For nodes created by the
8349: <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
1.1 mike 8350: lowercase.)</p>
8351:
8352: <p>For each attribute that the element has, append a U+0020
8353: SPACE character, the attribute's name (which, for attributes
8354: 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 8355: U+003D EQUALS SIGN character (=), a U+0022 QUOTATION MARK
8356: character ("), the attribute's value, <a href="#escapingString" title="escaping a string">escaped as described below</a> in
8357: <i>attribute mode</i>, and a second U+0022 QUOTATION MARK
8358: character (").</p>
1.1 mike 8359:
8360: <p>While the exact order of attributes is UA-defined, and may
8361: depend on factors such as the order that the attributes were
8362: given in the original markup, the sort order must be stable,
8363: such that consecutive invocations of this algorithm serialize an
8364: element's attributes in the same order.</p>
8365:
1.588 mike 8366: <p>Append a U+003E GREATER-THAN SIGN character (>).</p>
1.1 mike 8367:
8368: <p>If <var title="">current node</var> is an
1.5 mike 8369: <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.724 mike 8370: <code><a href="obsolete.html#bgsound">bgsound</a></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 8371: <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>,
8372: <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 8373: <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
1.724 mike 8374: <code><a href="obsolete.html#wbr">wbr</a></code> element, then continue on to the next child
1.589 mike 8375: node at this point.</p> <!-- also, i guess: image and isindex,
8376: but we don't list those because we don't consider those
8377: "elements", more "macros", and thus we should never serialize
8378: them -->
1.1 mike 8379:
8380: <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42 mike 8381: <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 8382: a U+000A LINE FEED (LF) character.</p>
8383:
8384: <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
8385: serialization algorithm</a> on the <var title="">current
8386: node</var> element (thus recursing into this algorithm for
1.588 mike 8387: that element), followed by a U+003C LESS-THAN SIGN character
8388: (<), a U+002F SOLIDUS character (/), the element's tag name
8389: again, and finally a U+003E GREATER-THAN SIGN character
8390: (>).</p>
1.1 mike 8391:
8392: </dd>
8393:
8394:
8395: <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
8396: node</dt>
8397:
8398: <dd>
8399:
1.19 mike 8400: <p>If the parent of <var title="">current node</var> is a
1.42 mike 8401: <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 8402: <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 8403: <code><a href="obsolete.html#noframes">noframes</a></code>, or <code><a href="obsolete.html#plaintext">plaintext</a></code> element, or
8404: if the parent of <var title="">current node</var> is
1.794 mike 8405: <code><a href="semantics.html#the-noscript-element">noscript</a></code> element and <a href="webappapis.html#concept-n-script" title="concept-n-script">scripting is enabled</a> for the
1.222 mike 8406: node, then append the value of <var title="">current
8407: node</var>'s <code title="">data</code> IDL attribute
8408: literally.</p>
1.1 mike 8409:
8410: <p>Otherwise, append the value of <var title="">current
1.192 mike 8411: node</var>'s <code title="">data</code> IDL attribute, <a href="#escapingString" title="escaping a string">escaped as described
1.1 mike 8412: below</a>.</p>
8413:
8414: </dd>
8415:
8416:
8417: <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
8418:
8419: <dd>
8420:
8421: <p>Append the literal string <code><!--</code> (U+003C
8422: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
1.192 mike 8423: U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1 mike 8424: attribute, followed by the literal string <code>--></code>
8425: (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
8426: SIGN).</p>
8427:
8428: </dd>
8429:
8430:
8431: <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
8432:
8433: <dd>
8434:
8435: <p>Append the literal string <code><?</code> (U+003C
8436: LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
1.192 mike 8437: of <var title="">current node</var>'s <code title="">target</code> IDL attribute, followed by a single
8438: U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1 mike 8439: attribute, followed by a single U+003E GREATER-THAN SIGN
1.464 mike 8440: character (>).</p>
1.1 mike 8441:
8442: </dd>
8443:
8444:
8445: <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
8446:
8447: <dd>
8448:
8449: <p>Append the literal string <code><!DOCTYPE</code> (U+003C
8450: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
8451: LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
8452: LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
8453: LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
8454: LETTER E), followed by a space (U+0020 SPACE), followed by the
1.192 mike 8455: value of <var title="">current node</var>'s <code title="">name</code> IDL attribute, followed by the literal
1.1 mike 8456: string <code>></code> (U+003E GREATER-THAN SIGN).</p>
8457:
8458: </dd>
8459:
8460:
8461: </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
8462: occur as children of elements. If, despite this, they somehow do
8463: occur, this algorithm must raise an
8464: <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
8465:
8466: </li>
8467:
8468: </ol></li>
8469:
8470: <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
8471:
8472: </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
8473: purposes of the algorithm above) consists of replacing any
8474: occurrences of the "<code title="">&</code>" character by the
8475: string "<code title="">&amp;</code>", any occurrences of the
8476: U+00A0 NO-BREAK SPACE character by the string "<code title="">&nbsp;</code>", and, if the algorithm was invoked in
8477: 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
8478: 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>
8479:
8480: <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
8481: agent, and are therefore not covered in the algorithm above.</p>
8482:
8483: <p class="note">It is possible that the output of this algorithm, if
8484: parsed with an <a href="#html-parser">HTML parser</a>, will not return the
8485: original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
8486: element to which a <code title="">Comment</code> node has been
8487: appended is serialized and the output is then reparsed, the comment
8488: will end up being displayed in the text field. Similarly, if, as a
8489: result of DOM manipulation, an element contains a comment that
8490: contains the literal string "<code title="">--></code>", then
8491: when the result of serializing the element is parsed, the comment
8492: will be truncated at that point and the rest of the comment will be
8493: interpreted as markup. More examples would be making a
8494: <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
8495: "<code></script></code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
8496: 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
8497: <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
8498: tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
8499:
8500:
1.755 mike 8501: <h3 id="parsing-html-fragments"><span class="secno">8.4 </span>Parsing HTML fragments</h3><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1 mike 8502:
8503: <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
8504: algorithm</dfn>. The algorithm optionally takes as input an
1.810 mike 8505: <code><a href="infrastructure.html#element">Element</a></code> node, referred to as the <var title="">context</var> element, which gives the context for the
1.1 mike 8506: parser, as well as <var title="">input</var>, a string to parse, and
8507: returns a list of zero or more nodes.</p>
8508:
8509: <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
8510: in the parser section are parts that only occur if the parser was
8511: created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
8512: with such markings for informational purposes only; such markings
8513: have no normative weight. If it is possible for a condition
8514: described as a <a href="#fragment-case">fragment case</a> to occur even when the
8515: parser wasn't created for the purposes of handling this algorithm,
8516: then that is an error in the specification.</p>
8517:
8518: <ol><li>
8519:
1.810 mike 8520: <p>Create a new <code><a href="infrastructure.html#document">Document</a></code> node, and mark it as being
1.1 mike 8521: an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
8522:
8523: </li>
8524:
8525: <li>
8526:
8527: <p>If there is a <var title="">context</var> element, and the
1.810 mike 8528: <code><a href="infrastructure.html#document">Document</a></code> of the <var title="">context</var> element
8529: is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code><a href="infrastructure.html#document">Document</a></code>
8530: be in <a href="dom.html#quirks-mode">quirks mode</a>. Otherwise, if there is a <var title="">context</var> element, and the <code><a href="infrastructure.html#document">Document</a></code> of
1.1 mike 8531: the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
1.810 mike 8532: mode</a>, then let the <code><a href="infrastructure.html#document">Document</a></code> be in
1.1 mike 8533: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
1.810 mike 8534: <code><a href="infrastructure.html#document">Document</a></code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
1.1 mike 8535:
8536: </li>
8537:
8538: <li>
8539:
8540: <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
1.810 mike 8541: the just created <code><a href="infrastructure.html#document">Document</a></code> node.</p>
1.1 mike 8542:
8543: </li>
8544:
8545: <li>
8546:
8547: <p>If there is a <var title="">context</var> element, run these
8548: substeps:</p>
8549:
8550: <ol><li>
8551:
1.541 mike 8552: <p>Set the state of the <a href="#html-parser">HTML parser</a>'s
8553: <a href="#tokenization">tokenization</a> stage as follows:</p>
1.1 mike 8554:
1.159 mike 8555: <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 8556: element</dt>
8557:
1.541 mike 8558: <dd>Switch the tokenizer to the <a href="#rcdata-state">RCDATA state</a>.</dd>
1.1 mike 8559:
8560:
1.672 mike 8561: <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>,
8562: <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 8563: <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1 mike 8564:
1.541 mike 8565: <dd>Switch the tokenizer to the <a href="#rawtext-state">RAWTEXT state</a>.</dd>
1.1 mike 8566:
8567:
1.672 mike 8568: <dt>If it is a <code><a href="semantics.html#script">script</a></code> element</dt>
8569:
8570: <dd>Switch the tokenizer to the <a href="#script-data-state">script data state</a>.</dd>
8571:
8572:
1.1 mike 8573: <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
8574:
1.541 mike 8575: <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, switch the
8576: tokenizer to the <a href="#rawtext-state">RAWTEXT state</a>. Otherwise,
8577: leave the tokenizer in the <a href="#data-state">data state</a>.</dd>
1.1 mike 8578:
8579:
1.42 mike 8580: <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1 mike 8581:
1.541 mike 8582: <dd>Switch the tokenizer to the <a href="#plaintext-state">PLAINTEXT
8583: state</a>.</dd>
1.1 mike 8584:
8585:
8586: <dt>Otherwise</dt>
8587:
1.541 mike 8588: <dd>Leave the tokenizer in the <a href="#data-state">data state</a>.</dd>
1.1 mike 8589:
1.672 mike 8590: </dl><p class="note">For performance reasons, an implementation that
1.756 mike 8591: does not report errors and that uses the actual state machine
8592: described in this specification directly could use the PLAINTEXT
8593: state instead of the RAWTEXT and script data states where those
8594: are mentioned in the list above. Except for rules regarding
8595: parse errors, they are equivalent, since there is no
8596: <a href="#appropriate-end-tag-token">appropriate end tag token</a> in the fragment case, yet
8597: they involve far fewer state transitions.</p>
1.672 mike 8598:
8599: </li>
1.1 mike 8600:
8601: <li>
8602:
1.159 mike 8603: <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 8604: with no attributes.</p>
8605:
8606: </li>
8607:
8608: <li>
8609:
8610: <p>Append the element <var title="">root</var> to the
1.810 mike 8611: <code><a href="infrastructure.html#document">Document</a></code> node created above.</p>
1.1 mike 8612:
8613: </li>
8614:
8615: <li>
8616:
8617: <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
8618: it contains just the single element <var title="">root</var>.</p>
8619:
8620: </li>
8621:
8622: <li>
8623:
8624: <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
8625: parser's insertion mode appropriately</a>.</p>
8626:
8627: <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
8628:
8629: </li>
8630:
8631: <li>
8632:
8633: <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
8634: to the nearest node to the <var title="">context</var> element
8635: that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
8636: ancestor chain, and including the element itself, if it is a
8637: <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
8638: <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
8639:
8640: </li>
8641:
8642: </ol></li>
8643:
8644: <li>
8645:
8646: <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
8647: parser</a> just created the <var title="">input</var>. The
8648: encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
8649: <i>irrelevant</i>.</p>
8650:
8651: </li>
8652:
8653: <li>
8654:
8655: <p>Start the parser and let it run until it has consumed all the
8656: characters just inserted into the input stream.</p>
8657:
8658: </li>
8659:
8660: <li>
8661:
8662: <p>If there is a <var title="">context</var> element, return the
8663: child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
8664: order</a>.</p>
8665:
1.810 mike 8666: <p>Otherwise, return the children of the <code><a href="infrastructure.html#document">Document</a></code>
1.1 mike 8667: object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
8668:
8669: </li>
8670:
1.123 mike 8671: </ol></div></body></html>
Webmaster