Annotation of html5/spec/syntax.html, revision 1.128
1.2 mike 1: <!DOCTYPE HTML>
1.12 mike 2: <html lang="en-US-x-Hixie"><head><title>9 The HTML syntax — HTML 5</title><style type="text/css">
1.1 mike 3: pre { margin-left: 2em; white-space: pre-wrap; }
4: h2 { margin: 3em 0 1em 0; }
5: h3 { margin: 2.5em 0 1em 0; }
6: h4 { margin: 2.5em 0 0.75em 0; }
7: h5, h6 { margin: 2.5em 0 1em; }
8: h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
9: h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
10: p { margin: 1em 0; }
11: hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
12: dl, dd { margin-top: 0; margin-bottom: 0; }
13: dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
14: dt + dt { margin-top: 0; }
15: dd dt { margin-top: 0.25em; margin-bottom: 0; }
16: dd p { margin-top: 0; }
17: dd dl + p { margin-top: 1em; }
18: dd table + p { margin-top: 1em; }
19: p + * > li, dd li { margin: 1em 0; }
20: dt, dfn { font-weight: bold; font-style: normal; }
21: dt dfn { font-style: italic; }
22: pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
23: pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
24: pre em { font-weight: bolder; font-style: normal; }
25: @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
26: var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
27: table { border-collapse: collapse; border-style: hidden hidden none hidden; }
28: table thead { border-bottom: solid; }
29: table tbody th:first-child { border-left: solid; }
30: table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
31: blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
32:
33: .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
34: .matrix, .matrix td { border: none; text-align: right; }
35: .matrix { margin-left: 2em; }
36: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
37: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
38: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
1.2 mike 39: .applies th > * { display: block; }
1.1 mike 40: .applies thead code { display: block; }
41: .applies td { text-align: center; }
42: .applies .yes { background: yellow; }
43:
44: .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
45: img.extra { float: right; }
46: pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
47: pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
48: pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
49: pre.css:first-line { color: #AAAA50; }
50: dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #EEFFEE; }
51: hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
52: dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
53: dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
54: dl.domintro dd p { margin: 0.5em 0; }
55: dl.switch { padding-left: 2em; }
56: dl.switch > dt { text-indent: -1.5em; }
57: dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
58: dl.triple { padding: 0 0 0 1em; }
59: dl.triple dt, dl.triple dd { margin: 0; display: inline }
60: dl.triple dt:after { content: ':'; }
61: dl.triple dd:after { content: '\A'; white-space: pre; }
62: .diff-old { text-decoration: line-through; color: silver; background: transparent; }
63: .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
64: a .diff-new { border-bottom: 1px blue solid; }
65:
66: h2 { page-break-before: always; }
67: h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
68: h1 + h2, hr + h2.no-toc { page-break-before: auto; }
69:
70: p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
71:
72: div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
73: div.head p { margin: 0; }
74: div.head h1 { margin: 0; }
75: div.head .logo { float: right; margin: 0 1em; }
76: div.head .logo img { border: none } /* remove border from top image */
77: div.head dl { margin: 1em 0; }
78: p.copyright { font-size: x-small; font-style: oblique; margin: 0; }
79:
80: body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
81: body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
82: body > .toc > li > * { margin-bottom: 0.5em; }
83: body > .toc > li > * > li > * { margin-bottom: 0.25em; }
84: .toc, .toc li { list-style: none; }
85:
86: .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
87: .brief li { margin: 0; padding: 0; }
88: .brief li p { margin: 0; padding: 0; }
89:
90: .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
91: .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
92: .category-list li { display: inline; }
93: .category-list li:not(:last-child)::after { content: ', '; }
94: .category-list li > span, .category-list li > a { text-transform: lowercase; }
95: .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
96:
97: .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
98: .XXX > :first-child { margin-top: 0; }
99: p .XXX { line-height: 3em; }
100: .note { color: green; background: transparent; font-family: sans-serif; }
101: .warning { color: red; background: transparent; }
102: .note, .warning { font-weight: bolder; font-style: italic; }
103: p.note, div.note { padding: 0.5em 2em; }
104: span.note { padding: 0 2em; }
105: .note p:first-child, .warning p:first-child { margin-top: 0; }
106: .note p:last-child, .warning p:last-child { margin-bottom: 0; }
107: .warning:before { font-style: normal; }
108: p.note:before { content: 'Note: '; }
109: p.warning:before { content: '\26A0 Warning! '; }
110:
111: .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
112: .bookkeeping { font-size: 0.8em; margin: 2em 0; }
113: .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
114:
115: h4 { position: relative; z-index: 3; }
116: h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
117: .element {
118: background: #EEEEFF;
119: color: black;
120: margin: 0 0 1em 0.15em;
121: padding: 0 1em 0.25em 0.75em;
122: border-left: solid #9999FF 0.25em;
123: position: relative;
124: z-index: 1;
125: }
126: .element:before {
127: position: absolute;
128: z-index: 2;
129: top: 0;
130: left: -1.15em;
131: height: 2em;
132: width: 0.9em;
133: background: #EEEEFF;
134: content: ' ';
135: border-style: none none solid solid;
136: border-color: #9999FF;
137: border-width: 0.25em;
138: }
139:
140: .example {
141: display: block;
142: color: #222222;
143: background: #FCFCFC;
144: border-left: double;
145: margin-left: 2em;
146: padding-left: 1em;
147: }
148:
149: .tall-and-narrow {
150: font-size: 0.6em;
151: column-width: 25em;
152: column-gap: 1em;
153: -moz-column-width: 25em;
154: -moz-column-gap: 1em;
155: -webkit-column-width: 25em;
156: -webkit-column-gap: 1em;
157: }
158:
159: ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
160: ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
161: ul.domTree li li { list-style: none; }
162: 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; }
163: 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; }
164: ul.domTree span { font-style: italic; font-family: serif; }
165: ul.domTree .t1 code { color: purple; font-weight: bold; }
166: ul.domTree .t2 { font-style: normal; font-family: monospace; }
167: ul.domTree .t2 .name { color: black; font-weight: bold; }
168: ul.domTree .t2 .value { color: blue; font-weight: normal; }
169: ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
170: ul.domTree .t7 code, .domTree .t8 code { color: green; }
171: ul.domTree .t10 code { color: teal; }
172:
1.2 mike 173: </style><link href="data:text/css," rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D" rel="alternate stylesheet" title="Highlight implementation requirements"><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css"><!-- ZZZ ED vs WD -->
174: <script src="link-fixup.js"></script>
175: <link href="comms.html" title="8 Communication" rel="prev">
176: <link href="spec.html#contents" title="Table of contents" rel="index">
1.1 mike 177: <link href="named-character-references.html" title="9.6 Named character references" rel="next">
1.16 mike 178: </head><body onload="fixBrokenLink(); fixBrokenLink()"><div class="head">
1.1 mike 179: <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.4 mike 180: <h1>HTML 5</h1>
1.1 mike 181: <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 182: </div><nav>
1.1 mike 183: <a href="comms.html">← 8 Communication</a> –
1.2 mike 184: <a href="spec.html#contents">Table of contents</a> –
1.1 mike 185: <a href="named-character-references.html">9.6 Named character references →</a>
1.128 ! mike 186: </nav><p>This is revision 1.2800.</p>
1.11 mike 187:
1.1 mike 188:
1.123 mike 189: <h2 id="syntax"><span class="secno">9 </span><dfn>The HTML syntax</dfn></h2><p class="note">This section only describes the rules for
1.83 mike 190: <code><a href="iana-considerations.html#text-html">text/html</a></code> resources. Rules for XML resources are
1.1 mike 191: discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.123 mike 192: syntax</a>".</p><h3 id="writing"><span class="secno">9.1 </span>Writing HTML documents</h3><div class="impl">
1.1 mike 193:
194: <p><i>This section only applies to documents, authoring tools, and
195: markup generators. In particular, it does not apply to conformance
196: checkers; conformance checkers must use the requirements given in
197: the next section ("parsing HTML documents").</i></p>
198:
1.123 mike 199: </div><p>Documents must consist of the following parts, in the given
200: order:</p><ol><li>Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.</li>
1.1 mike 201:
202: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
203: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
204:
205: <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
206:
207: </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
208: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
209:
210: <li>The root element, in the form of an <code><a href="semantics.html#the-html-element">html</a></code> <a href="#syntax-elements" title="syntax-elements">element</a>.</li>
211:
212: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
213: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
214:
215: </ol><p>The various types of content mentioned above are described in the
1.123 mike 216: 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 217: declarations</a> are to be serialized, as discussed in the
1.123 mike 218: section on that topic.</p><div class="note">
1.1 mike 219:
220: <p>Space characters before the root <code><a href="semantics.html#the-html-element">html</a></code> element, and
221: space characters at the start of the <code><a href="semantics.html#the-html-element">html</a></code> element and
222: before the <code><a href="semantics.html#the-head-element">head</a></code> element, will be dropped when the
223: document is parsed; space characters <em>after</em> the root
224: <code><a href="semantics.html#the-html-element">html</a></code> element will be parsed as if they were at the end
225: of the <code><a href="semantics.html#the-body-element">body</a></code> element. Thus, space characters around the
226: root element do not round-trip.</p>
227:
228: <p>It is suggested that newlines be inserted after the DOCTYPE,
229: after any comments that are before the root element, after the
230: <code><a href="semantics.html#the-html-element">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
231: that are inside the <code><a href="semantics.html#the-html-element">html</a></code> element but before the
232: <code><a href="semantics.html#the-head-element">head</a></code> element.</p>
233:
1.123 mike 234: </div><p>Many strings in the HTML syntax (e.g. the names of elements and
1.1 mike 235: their attributes) are case-insensitive, but only for characters in
236: the ranges U+0041 .. U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
237: LETTER Z) and U+0061 .. U+007A (LATIN SMALL LETTER A to LATIN SMALL
238: LETTER Z). For convenience, in this section this is just referred to
1.123 mike 239: as "case-insensitive".</p><h4 id="the-doctype"><span class="secno">9.1.1 </span>The DOCTYPE</h4><p>A <dfn id="syntax-doctype" title="syntax-doctype">DOCTYPE</dfn> is a mostly useless,
240: but required, header.</p><p class="note">DOCTYPEs are required for legacy reasons. When
1.1 mike 241: omitted, browsers tend to use a different rendering mode that is
242: incompatible with some specifications. Including the DOCTYPE in a
243: document ensures that the browser makes a best-effort attempt at
1.123 mike 244: following the relevant specifications.</p><p>A DOCTYPE must consist of the following characters, in this
245: order:</p><ol class="brief"><li>A U+003C LESS-THAN SIGN (<code><</code>) character.</li>
1.1 mike 246: <li>A U+0021 EXCLAMATION MARK (<code>!</code>) character.</li>
247: <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>
248: <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
249: <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>
250: <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> (defined below).</li>
251: <li>Zero or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
252: <li>A U+003E GREATER-THAN SIGN (<code>></code>) character.</li>
253: </ol><p class="note">In other words, <code><!DOCTYPE HTML></code>,
1.123 mike 254: case-insensitively.</p><p>For the purposes of HTML generators that cannot output HTML
1.1 mike 255: markup with the short DOCTYPE "<code title=""><!DOCTYPE
256: HTML></code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
257: into the DOCTYPE (in the position defined above). This string must
1.123 mike 258: 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 259: <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>
260: <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
261: <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
262: <li>The literal string "<code title="">about:legacy-compat</code>".</li>
263: <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>
264: </ol><p class="note">In other words, <code><!DOCTYPE HTML SYSTEM
265: "about:legacy-compat"></code> or <code><!DOCTYPE HTML SYSTEM
266: 'about:legacy-compat'></code>, case-insensitively except for the bit
1.123 mike 267: in quotes.</p><p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1 mike 268: the document is generated from a system that cannot output the
1.123 mike 269: shorter string.</p><h4 id="elements-0"><span class="secno">9.1.2 </span>Elements</h4><p>There are five different kinds of <dfn id="syntax-elements" title="syntax-elements">elements</dfn>: void elements, raw text
1.1 mike 270: elements, RCDATA elements, foreign elements, and normal
1.123 mike 271: elements.</p><dl><dt><dfn id="void-elements">Void elements</dfn></dt>
1.1 mike 272:
273: <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>,
274: <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="embedded-content-0.html#the-embed-element">embed</a></code>,
275: <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="embedded-content-0.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>,
276: <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>,
277: <code><a href="embedded-content-0.html#the-param-element">param</a></code>, <code><a href="video.html#the-source-element">source</a></code></dd>
278:
1.91 mike 279: <dt>Raw text elements</dt>
1.1 mike 280:
281: <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 282: noscript don't count as raw text for syntax purposes -->
1.1 mike 283:
284: <dt>RCDATA elements</dt>
285:
286: <dd><code><a href="forms.html#the-textarea-element">textarea</a></code>, <code><a href="semantics.html#the-title-element">title</a></code></dd>
287:
288: <dt>Foreign elements</dt>
289:
290: <dd>Elements from the <a href="#mathml-namespace">MathML namespace</a>
291: and the <a href="#svg-namespace">SVG namespace</a>.</dd>
292:
293: <dt>Normal elements</dt>
294:
295: <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
296: elements.</dd>
297:
298: </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.91 mike 299: and end of elements in the markup. Raw text, RCDATA, and normal
1.1 mike 300: elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to
301: indicate where they begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end
302: tag</a> to indicate where they end. The start and end tags of
303: certain normal elements can be <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>, as described
304: later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
305: elements</a> only have a start tag; end tags must not be
306: specified for void elements. Foreign elements must either have a
307: start tag and an end tag, or a start tag that is marked as
1.123 mike 308: self-closing, in which case they must not have an end tag.</p><p>The contents of the element must be placed between just after the
1.1 mike 309: start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
310: in certain cases</a>) and just before the end tag (which again,
311: <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
312: cases</a>). The exact allowed contents of each individual element
313: depends on the content model of that element, as described earlier
314: in this specification. Elements must not contain content that their
315: content model disallows. In addition to the restrictions placed on
316: the contents by those content models, however, the five types of
1.123 mike 317: 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 318: no end tag, no content can be put between the start tag and the end
1.123 mike 319: tag).</p><p>Raw text elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1 mike 320: though it has <a href="#cdata-rcdata-restrictions">restrictions</a>
1.123 mike 321: described below.</p><p>RCDATA elements can have <a href="#syntax-text" title="syntax-text">text</a>
1.1 mike 322: and <a href="#syntax-charref" title="syntax-charref">character references</a>, but
323: the text must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
324: There are also <a href="#cdata-rcdata-restrictions">further
1.123 mike 325: restrictions</a> described below.</p><p>Foreign elements whose start tag is marked as self-closing can't
1.1 mike 326: have any contents (since, again, as there's no end tag, no content
327: can be put between the start tag and the end tag). Foreign elements
328: whose start tag is <em>not</em> marked as self-closing can have
329: <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
330: contain the character U+003C LESS-THAN SIGN (<code><</code>) or
331: an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.123 mike 332: ampersand</a>.</p><p>Normal elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1 mike 333: <a href="#syntax-charref" title="syntax-charref">character references</a>, other
334: <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
335: contain the character U+003C LESS-THAN SIGN (<code><</code>) or
336: an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
337: ampersand</a>. Some normal elements also have <a href="#element-restrictions">yet more restrictions</a> on what
338: content they are allowed to hold, beyond the restrictions imposed by
339: the content model and those described in this paragraph. Those
1.123 mike 340: restrictions are described below.</p><p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1 mike 341: giving the element's name. HTML elements all have names that only
342: use characters in the range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE,
343: U+0061 LATIN SMALL LETTER A .. U+007A LATIN SMALL LETTER Z, U+0041
344: LATIN CAPITAL LETTER A .. U+005A LATIN CAPITAL LETTER Z, and U+002D
345: HYPHEN-MINUS (<code>-</code>). In the HTML syntax, tag names may be
346: written with any mix of lower- and uppercase letters that, when
347: converted to all-lowercase, matches the element's tag name; tag
1.123 mike 348: names are case-insensitive.</p><h5 id="start-tags"><span class="secno">9.1.2.1 </span>Start tags</h5><p><dfn id="syntax-start-tag" title="syntax-start-tag">Start tags</dfn> must have the
349: following format:</p><ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.1 mike 350: SIGN (<code><</code>).</li>
351:
352: <li>The next few characters of a start tag must be the element's
353: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
354:
355: <li>If there are to be any attributes in the next step, there must
356: first be one or more <a href="infrastructure.html#space-character" title="space character">space
357: characters</a>.</li>
358:
359: <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
360: below. Attributes may be separated from each other by one or more
361: <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
362:
363: <li>After the attributes, there may be one or more <a href="infrastructure.html#space-character" title="space character">space characters</a>. (Some attributes
364: are required to be followed by a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes section</a> below.)</li>
365:
366: <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
367: or if the element is a foreign element, then there may be a single
368: U+002F SOLIDUS (<code>/</code>) character. This character has no
369: effect on void elements, but on foreign elements it marks the start
370: tag as self-closing.</li>
371:
372: <li>Finally, start tags must be closed by a U+003E GREATER-THAN
373: SIGN (<code>></code>) character.</li>
374:
1.123 mike 375: </ol><h5 id="end-tags"><span class="secno">9.1.2.2 </span>End tags</h5><p><dfn id="syntax-end-tag" title="syntax-end-tag">End tags</dfn> must have the
376: following format:</p><ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.1 mike 377: SIGN (<code><</code>).</li>
378:
379: <li>The second character of an end tag must be a U+002F SOLIDUS
380: (<code>/</code>).</li>
381:
382: <li>The next few characters of an end tag must be the element's
383: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
384:
385: <li>After the tag name, there may be one or more <a href="infrastructure.html#space-character" title="space
386: character">space characters</a>.</li>
387:
388: <li>Finally, end tags must be closed by a U+003E GREATER-THAN
389: SIGN (<code>></code>) character.</li>
390:
1.123 mike 391: </ol><h5 id="attributes"><span class="secno">9.1.2.3 </span>Attributes</h5><p><dfn id="syntax-attributes" title="syntax-attributes">Attributes</dfn> for an element
392: 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 393: one or more characters other than the <a href="infrastructure.html#space-character" title="space
394: character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
395: MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
396: (>), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters,
397: the control characters, and any characters that are not defined by
398: Unicode. In the HTML syntax, attribute names may be written with any
399: mix of lower- and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.123 mike 400: 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 401: 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 402: 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 403:
404: <dd>
405:
406: <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
407: name</a>.</p>
408:
409: <div class="example">
410:
411: <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
412: the empty attribute syntax:</p>
413:
414: <pre><input <em>disabled</em>></pre>
415:
416: </div>
417:
418: <p>If an attribute using the empty attribute syntax is to be
419: followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
420: character</a> separating the two.</p>
421:
422: </dd>
423:
1.2 mike 424: <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1 mike 425:
426: <dd>
427:
428: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
429: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
430: characters</a>, followed by a single U+003D EQUALS SIGN
431: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
432: character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
433: addition to the requirements given above for attribute values,
434: must not contain any literal <a href="infrastructure.html#space-character" title="space character">space
435: characters</a>, any U+0022 QUOTATION MARK (<code>"</code>)
436: characters, U+0027 APOSTROPHE (<code>'</code>) characters,
437: U+003D EQUALS SIGN (<code>=</code>) characters, U+003C LESS-THAN
438: SIGN (<code><</code>) characters, or U+003E GREATER-THAN SIGN
439: (<code>></code>) characters, and must not be the empty
440: string.</p>
441:
442: <div class="example">
443:
444: <p>In the following example, the <code title="attr-input-value"><a href="forms.html#attr-input-value">value</a></code> attribute is given
445: with the unquoted attribute value syntax:</p>
446:
447: <pre><input <em>value=yes</em>></pre>
448:
449: </div>
450:
451: <p>If an attribute using the unquoted attribute syntax is to be
1.101 mike 452: followed by another attribute or by the optional U+002F SOLIDUS
453: (<code>/</code>) character allowed in step 6 of the <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> syntax above, then there
1.1 mike 454: must be a <a href="infrastructure.html#space-character">space character</a> separating the two.</p>
455:
456: </dd>
457:
458: <dt>Single-quoted attribute value syntax</dt>
459:
460: <dd>
461:
462: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
463: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
464: characters</a>, followed by a single U+003D EQUALS SIGN
465: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
466: character">space characters</a>, followed by a single U+0027
467: APOSTROPHE (<code>'</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
468: addition to the requirements given above for attribute values,
469: must not contain any literal U+0027 APOSTROPHE (<code>'</code>)
470: characters, and finally followed by a second single U+0027
471: APOSTROPHE (<code>'</code>) character.</p>
472:
473: <div class="example">
474:
475: <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
476: single-quoted attribute value syntax:</p>
477:
478: <pre><input <em>type='checkbox'</em>></pre>
479:
480: </div>
481:
482: <p>If an attribute using the single-quoted attribute syntax is to
483: be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
484: character</a> separating the two.</p>
485:
486: </dd>
487:
488: <dt>Double-quoted attribute value syntax</dt>
489:
490: <dd>
491:
492: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
493: followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
494: characters</a>, followed by a single U+003D EQUALS SIGN
495: character, followed by zero or more <a href="infrastructure.html#space-character" title="space
496: character">space characters</a>, followed by a single U+0022
497: QUOTATION MARK (<code>"</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
498: addition to the requirements given above for attribute values,
499: must not contain any literal U+0022 QUOTATION MARK
500: (<code>"</code>) characters, and finally followed by a second
501: single U+0022 QUOTATION MARK (<code>"</code>) character.</p>
502:
503: <div class="example">
504:
505: <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
506: double-quoted attribute value syntax:</p>
507:
508: <pre><input <em>name="be evil"</em>></pre>
509:
510: </div>
511:
512: <p>If an attribute using the double-quoted attribute syntax is to
513: be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
514: character</a> separating the two.</p>
515:
516: </dd>
517:
518: </dl><p>There must never be two or more attributes on the same start tag
519: whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.123 mike 520: each other.</p><h5 id="optional-tags"><span class="secno">9.1.2.4 </span>Optional tags</h5><p>Certain tags can be <dfn id="syntax-tag-omission" title="syntax-tag-omission">omitted</dfn>.</p><p class="note">Omitting an element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> does not mean the element
1.1 mike 521: is not present; it is implied, but it is still there. An HTML
522: document always has a root <code><a href="semantics.html#the-html-element">html</a></code> element, even if the
523: string <code title=""><html></code> doesn't appear anywhere in
1.123 mike 524: the markup.</p><!-- <html> --><p>An <code><a href="semantics.html#the-html-element">html</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
525: first thing inside the <code><a href="semantics.html#the-html-element">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">html</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 526: tag</a> may be omitted if the <code><a href="semantics.html#the-html-element">html</a></code> element is not
1.123 mike 527: 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">head</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted <!--if the
1.1 mike 528: element is empty, or--> if the first thing inside the
1.123 mike 529: <code><a href="semantics.html#the-head-element">head</a></code> element is an element.</p><!-- </head> --><p>A <code><a href="semantics.html#the-head-element">head</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 530: tag</a> may be omitted if the <code><a href="semantics.html#the-head-element">head</a></code> element is not
1.123 mike 531: 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">body</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.1 mike 532: element is empty, or if the first thing inside the <code><a href="semantics.html#the-body-element">body</a></code>
533: 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
534: inside the <code><a href="semantics.html#the-body-element">body</a></code> element is a <code><a href="semantics.html#script">script</a></code> or
535: <code><a href="semantics.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
536: tag is present, the parser makes <style> and <script> elements
537: between </head> and <body> end up in the <head> instead of implying
1.123 mike 538: the <body> --></p><!-- </body> --><p>A <code><a href="semantics.html#the-body-element">body</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 539: tag</a> may be omitted if the <code><a href="semantics.html#the-body-element">body</a></code> element is not
1.123 mike 540: 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 541: tag</a> may be omitted if the <code><a href="semantics.html#the-li-element">li</a></code> element is
542: immediately followed by another <code><a href="semantics.html#the-li-element">li</a></code> element or if there
1.123 mike 543: 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 544: tag</a> may be omitted if the <code><a href="semantics.html#the-dt-element">dt</a></code> element is
545: immediately followed by another <code><a href="semantics.html#the-dt-element">dt</a></code> element or a
1.123 mike 546: <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 547: tag</a> may be omitted if the <code><a href="semantics.html#the-dd-element">dd</a></code> element is
548: immediately followed by another <code><a href="semantics.html#the-dd-element">dd</a></code> element or a
549: <code><a href="semantics.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.123 mike 550: 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 551: tag</a> may be omitted if the <code><a href="semantics.html#the-p-element">p</a></code> element is
552: immediately followed by an <code><a href="semantics.html#the-address-element">address</a></code>,
553: <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.86 mike 554: <!--v2DATAGRID <code>datagrid</code>,--> <code><a href="semantics.html#the-dialog-element">dialog</a></code>,
555: <code><a href="obsolete.html#dir">dir</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, <code><a href="semantics.html#the-dl-element">dl</a></code>,
556: <code><a href="forms.html#the-fieldset-element">fieldset</a></code>, <code><a href="semantics.html#the-footer-element">footer</a></code>, <code><a href="forms.html#the-form-element">form</a></code>,
557: <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>, <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>,
558: <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>, <code><a href="semantics.html#the-header-element">header</a></code>,
559: <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="interactive-elements.html#menus">menu</a></code>,
560: <code><a href="semantics.html#the-nav-element">nav</a></code>, <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 561: <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>,
562: element, or if there is no more content in the parent element and
1.123 mike 563: 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 564: tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element is
565: 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 566: 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 567: tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element is
568: 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 569: 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 570: <select>; commented out text below can handle the non-<select> case
1.123 mike 571: 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 572: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
573: <code>select</code> element and--> is immediately followed by
574: another <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
575: that are ancestors of the <code>optgroup</code> element, up to and
576: including the first ancestor element that is not an
577: <code>optgroup</code> element, have no more content--> there is no
1.123 mike 578: more content in the parent element.</p><!-- so e.g. the max number of </optgroup>s are omitted here:
1.1 mike 579: <select><optgroup></select>
580: <p id=x><optgroup></optgroup>x</p>
581: <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
582: <p><optgroup id=x><optgroup></optgroup>x</p>
583: <p><optgroup><optgroup id=x>x</p>
1.123 mike 584: --><!-- </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 585: tag</a> may be omitted if the <code><a href="forms.html#the-option-element">option</a></code> element is
586: immediately followed by another <code><a href="forms.html#the-option-element">option</a></code> element, or if
587: it is immediately followed by an <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or
1.123 mike 588: 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 589: first thing inside the <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is a
590: <code><a href="tabular-data.html#the-col-element">col</a></code> element, and if the element is not immediately
591: 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 592: 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 593: <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.123 mike 594: <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 595: tag</a> may be omitted if the <code><a href="tabular-data.html#the-thead-element">thead</a></code> element is
596: 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 597: 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 598: first thing inside the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is a
599: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, and if the element is not immediately
600: 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
601: <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
602: tag</a> has been omitted. (It can't be omitted if the element is
1.123 mike 603: 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 604: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is
605: 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 606: 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 607: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element is
608: immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, or if there is
1.123 mike 609: 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 610: tag</a> may be omitted if the <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
611: immediately followed by another <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, or if there
1.123 mike 612: 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 613: tag</a> may be omitted if the <code><a href="tabular-data.html#the-td-element">td</a></code> element is
614: 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 615: 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 616: tag</a> may be omitted if the <code><a href="tabular-data.html#the-th-element">th</a></code> element is
617: 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 618: 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
619: tag</a> must never be omitted if it has any attributes.</p><h5 id="element-restrictions"><span class="secno">9.1.2.5 </span>Restrictions on content models</h5><p>For historical reasons, certain elements have extra restrictions
620: 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 621: elements, even though these elements are technically allowed inside
622: <code><a href="tabular-data.html#the-table-element">table</a></code> elements according to the content models
623: described in this specification. (If a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
624: put inside a <code><a href="tabular-data.html#the-table-element">table</a></code> in the markup, it will in fact imply
1.123 mike 625: a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag before it.)</p><p>A single U+000A LINE FEED (LF) character may be placed
1.1 mike 626: immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
627: 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>
628: elements. This does not affect the processing of the element. The
629: otherwise optional U+000A LINE FEED (LF) character <em>must</em> be
630: included if the element's contents start with that character
631: (because otherwise the leading newline in the contents would be
1.123 mike 632: treated like the optional newline, and ignored).</p><div class="example">
1.1 mike 633: <p>The following two <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
634: <pre><pre>Hello</pre></pre>
635: <pre><pre><br>Hello</pre></pre>
1.123 mike 636: </div><h5 id="cdata-rcdata-restrictions"><span class="secno">9.1.2.6 </span>Restrictions on the contents of raw text and RCDATA elements</h5><p>The text in raw text and RCDATA elements must not contain any
1.1 mike 637: occurrences of the string "<code title=""></</code>" (U+003C
638: LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that
639: case-insensitively match the tag name of the element followed by one
640: of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM
641: FEED (FF), U+0020 SPACE, U+003E GREATER-THAN SIGN (>), or U+002F
1.123 mike 642: SOLIDUS (/), unless that string is part of an <a href="#syntax-escape" title="syntax-escape">escaping text span</a>.</p><p>An <dfn id="syntax-escape" title="syntax-escape">escaping text span</dfn> is a span
1.1 mike 643: of <a href="#syntax-text" title="syntax-text">text</a> that starts with an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a> that is
644: not itself in an <a href="#syntax-escape" title="syntax-escape">escaping text
645: span</a>, and ends at the next <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span end</a>. There
646: cannot be any <a href="#syntax-charref" title="syntax-charref">character
647: references</a> inside an <a href="#syntax-escape" title="syntax-escape">escaping
648: text span</a> — sequences of characters that would look
649: like <a href="#syntax-charref" title="syntax-charref">character references</a> do not
1.123 mike 650: have special meaning.</p><p>An <dfn id="syntax-escape-start" title="syntax-escape-start">escaping text span
1.1 mike 651: start</dfn> is a part of <a href="#syntax-text" title="syntax-text">text</a> that
652: consists of the four character sequence "<code title=""><!--</code>" (U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
1.123 mike 653: MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS).</p><p>An <dfn id="syntax-escape-end" title="syntax-escape-end">escaping text span end</dfn> is
1.1 mike 654: a part of <a href="#syntax-text" title="syntax-text">text</a> that consists of the
655: three character sequence "<code title="">--></code>" (U+002D
656: HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN) whose
1.123 mike 657: U+003E GREATER-THAN SIGN (>).</p><p>An <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span
1.1 mike 658: start</a> may share its U+002D HYPHEN-MINUS characters with its
659: corresponding <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span
1.123 mike 660: end</a>.</p><p>The text in raw text elements and RCDATA elements must not have
1.91 mike 661: an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a>
662: that is not followed by an <a href="#syntax-escape-end" title="syntax-escape-end">escaping
1.123 mike 663: text span end</a>.</p><h4 id="text-0"><span class="secno">9.1.3 </span>Text</h4><p><dfn id="syntax-text" title="syntax-text">Text</dfn> is allowed inside elements,
1.1 mike 664: attributes, and comments. Text must consist of Unicode characters.
665: Text must not contain U+0000 characters. Text must not contain
666: permanently undefined Unicode characters. Text must not contain
667: control characters other than <a href="infrastructure.html#space-character" title="space character">space
668: characters</a>. Extra constraints are placed on what is and what
669: is not allowed in text based on where the text is to be put, as
1.123 mike 670: described in the other sections.</p><h5 id="newlines"><span class="secno">9.1.3.1 </span>Newlines</h5><p><dfn id="syntax-newlines" title="syntax-newlines">Newlines</dfn> in HTML may be
1.1 mike 671: represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A
672: LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR),
1.123 mike 673: U+000A LINE FEED (LF) characters in that order.</p><h4 id="character-references"><span class="secno">9.1.4 </span>Character references</h4><p>In certain cases described in other sections, <a href="#syntax-text" title="syntax-text">text</a> may be mixed with <dfn id="syntax-charref" title="syntax-charref">character references</dfn>. These can be used
1.1 mike 674: to escape characters that couldn't otherwise legally be included in
1.123 mike 675: <a href="#syntax-text" title="syntax-text">text</a>.</p><p>Character references must start with a U+0026 AMPERSAND
1.1 mike 676: (<code>&</code>). Following this, there are three possible kinds
1.123 mike 677: of character references:</p><dl><dt>Named character references</dt>
1.1 mike 678:
679: <dd>The ampersand must be followed by one of the names given in the
680: <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
681: case. The name must be one that is terminated by a U+003B SEMICOLON
682: (<code title="">;</code>) character.</dd>
683:
684:
685: <dt>Decimal numeric character reference</dt>
686:
687: <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
688: (<code>#</code>) character, followed by one or more digits in the
689: range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, representing a
690: base-ten integer that itself is a Unicode code point that is
691: not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
692: 0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
693: a U+003B SEMICOLON character (<code title="">;</code>).</dd>
694:
695:
696: <dt>Hexadecimal numeric character reference</dt>
697:
698: <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
699: (<code>#</code>) character, which must be followed by either a
700: U+0078 LATIN SMALL LETTER X or a U+0058 LATIN CAPITAL LETTER X
701: character, which must then be followed by one or more digits in the
702: range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, U+0061 LATIN SMALL
703: LETTER A .. U+0066 LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL
704: LETTER A .. U+0046 LATIN CAPITAL LETTER F, representing a
705: base-sixteen integer that itself is a Unicode code point that is
706: not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
707: 0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
708: a U+003B SEMICOLON character (<code title="">;</code>).</dd>
709:
710: </dl><p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
711: ampersand</dfn> is a U+0026 AMPERSAND (<code>&</code>) character
712: that is followed by some <a href="#syntax-text" title="syntax-text">text</a> other
713: than a <a href="infrastructure.html#space-character">space character</a>, a U+003C LESS-THAN SIGN
714: character ('<'), or another U+0026 AMPERSAND (<code>&</code>)
1.123 mike 715: character.</p><h4 id="cdata-sections"><span class="secno">9.1.5 </span>CDATA sections</h4><p><dfn id="syntax-cdata" title="syntax-cdata">CDATA sections</dfn> must start with
1.1 mike 716: the character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
717: MARK, U+005B LEFT SQUARE BRACKET, U+0043 LATIN CAPITAL LETTER C,
718: U+0044 LATIN CAPITAL LETTER D, U+0041 LATIN CAPITAL LETTER A, U+0054
719: LATIN CAPITAL LETTER T, U+0041 LATIN CAPITAL LETTER A, U+005B LEFT
720: SQUARE BRACKET (<code title=""><![CDATA[</code>). Following this
721: sequence, the CDATA section may have <a href="#syntax-text" title="syntax-text">text</a>, with the additional restriction
722: that the text must not contain the three character sequence U+005D
723: RIGHT SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E
724: GREATER-THAN SIGN (<code title="">]]></code>). Finally, the CDATA
725: section must be ended by the three character sequence U+005D RIGHT
726: SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E GREATER-THAN
1.123 mike 727: SIGN (<code title="">]]></code>).</p><h4 id="comments"><span class="secno">9.1.6 </span>Comments</h4><p><dfn id="syntax-comments" title="syntax-comments">Comments</dfn> must start with the
1.1 mike 728: four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
729: MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title=""><!--</code>). Following this sequence, the comment may
730: have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
731: restriction that the text must not start with a single U+003E
732: GREATER-THAN SIGN ('>') character, nor start with a U+002D
733: HYPHEN-MINUS (<code title="">-</code>) character followed by a
734: U+003E GREATER-THAN SIGN ('>') character, nor contain two
735: consecutive U+002D HYPHEN-MINUS (<code title="">-</code>)
736: characters, nor end with a U+002D HYPHEN-MINUS (<code title="">-</code>) character. Finally, the comment must be ended by
737: the three character sequence U+002D HYPHEN-MINUS, U+002D
1.123 mike 738: HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--></code>).</p><div class="impl">
1.1 mike 739:
740: <h3 id="parsing"><span class="secno">9.2 </span>Parsing HTML documents</h3>
741:
742: <p><i>This section only applies to user agents, data mining tools,
743: and conformance checkers.</i></p>
744:
745: <p class="note">The rules for parsing XML documents into DOM trees
746: are covered by the next section, entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
747: syntax</a>".</p>
748:
749: <p>For <a href="dom.html#html-documents">HTML documents</a>, user agents must use the parsing
750: rules described in this section to generate the DOM trees. Together,
751: these rules define what is referred to as the <dfn id="html-parser">HTML
752: parser</dfn>.</p>
753:
754: <div class="note">
755:
756: <p>While the HTML syntax described in this specification bears a
757: close resemblance to SGML and XML, it is a separate language with
758: its own parsing rules.</p>
759:
760: <p>Some earlier versions of HTML (in particular from HTML 2 to
761: HTML 4) were based on SGML and used SGML parsing rules. However, few
762: (if any) web browsers ever implemented true SGML parsing for HTML
763: documents; the only user agents to strictly handle HTML as an SGML
764: application have historically been validators. The resulting
765: confusion — with validators claiming documents to have one
766: representation while widely deployed Web browsers interoperably
767: implemented a different representation — has wasted decades
768: of productivity. This version of HTML thus returns to a non-SGML
769: basis.</p>
770:
771: <p>Authors interested in using SGML tools in their authoring
772: pipeline are encouraged to use XML tools and the XML serialization
773: of HTML.</p>
774:
775: </div>
776:
777: <p>This specification defines the parsing rules for HTML documents,
778: whether they are syntactically correct or not. Certain points in the
779: parsing algorithm are said to be <dfn id="parse-error" title="parse error">parse
780: errors</dfn>. The error handling for parse errors is well-defined:
781: user agents must either act as described below when encountering
782: such problems, or must abort processing at the first error that they
783: encounter for which they do not wish to apply the rules described
784: below.</p>
785:
786: <p>Conformance checkers must report at least one parse error
787: condition to the user if one or more parse error conditions exist in
788: the document and must not report parse error conditions if none
789: exist in the document. Conformance checkers may report more than one
790: parse error condition if more than one parse error conditions exist
791: in the document. Conformance checkers are not required to recover
792: from parse errors.</p>
793:
794: <p class="note">Parse errors are only errors with the
795: <em>syntax</em> of HTML. In addition to checking for parse errors,
796: conformance checkers will also verify that the document obeys all
797: the other conformance requirements described in this
798: specification.</p>
799:
800: <p>For the purposes of conformance checkers, if a resource is
801: determined to be in <a href="#syntax">the HTML syntax</a>, then it is an
802: <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
803:
804:
805: <h4 id="overview-of-the-parsing-model"><span class="secno">9.2.1 </span>Overview of the parsing model</h4>
806:
807: <p>The input to the HTML parsing process consists of a stream of
808: Unicode characters, which is passed through a
809: <a href="#tokenization">tokenization</a> stage followed by a <a href="#tree-construction">tree
810: construction</a> stage. The output is a <code>Document</code>
811: object.</p>
812:
813: <p class="note">Implementations that <a href="infrastructure.html#non-scripted">do not
814: support scripting</a> do not have to actually create a DOM
815: <code>Document</code> object, but the DOM tree in such cases is
816: still used as the model for the rest of the specification.</p>
817:
818: <p>In the common case, the data handled by the tokenization stage
819: comes from the network, but <a href="dom.html#dynamic-markup-insertion" title="dynamic markup
820: insertion">it can also come from script</a>, e.g. using the <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code> API.</p>
821:
822: <p><img alt="" src="images/parsing-model-overview.png"></p>
823:
824: <p id="nestedParsing">There is only one set of states for the
825: tokenizer stage and the tree construction stage, but the tree
826: construction stage is reentrant, meaning that while the tree
827: construction stage is handling one token, the tokenizer might be
828: resumed, causing further tokens to be emitted and processed before
829: the first token's processing is complete.</p>
830:
831: <div class="example">
832:
833: <p>In the following example, the tree construction stage will be
834: called upon to handle a "p" start tag token while handling the
835: "script" start tag token:</p>
836:
837: <pre>...
838: <script>
839: document.write('<p>');
840: </script>
841: ...</pre>
842:
843: </div>
844:
845: <p>To handle these cases, parsers have a <dfn id="script-nesting-level">script nesting
846: level</dfn>, which must be initially set to zero, and a <dfn id="parser-pause-flag">parser
847: pause flag</dfn>, which must be initially set to false.</p>
848:
849:
850:
851: <h4 id="the-input-stream"><span class="secno">9.2.2 </span>The <dfn>input stream</dfn></h4>
852:
853: <p>The stream of Unicode characters that comprises the input to the
854: tokenization stage will be initially seen by the user agent as a
855: stream of bytes (typically coming over the network or from the local
856: file system). The bytes encode the actual characters according to a
857: particular <em>character encoding</em>, which the user agent must
858: use to decode the bytes into characters.</p>
859:
860: <p class="note">For XML documents, the algorithm user agents must
861: use to determine the character encoding is given by the XML
1.104 mike 862: specification. This section does not apply to XML documents. <a href="references.html#refsXML">[XML]</a></p>
1.1 mike 863:
864:
865: <h5 id="determining-the-character-encoding"><span class="secno">9.2.2.1 </span>Determining the character encoding</h5>
866:
867: <p>In some cases, it might be impractical to unambiguously determine
868: the encoding before parsing the document. Because of this, this
869: specification provides for a two-pass mechanism with an optional
870: pre-scan. Implementations are allowed, as described below, to apply
871: a simplified parsing algorithm to whatever bytes they have available
872: before beginning to parse the document. Then, the real parser is
873: started, using a tentative encoding derived from this pre-parse and
874: other out-of-band metadata. If, while the document is being loaded,
875: the user agent discovers an encoding declaration that conflicts with
876: this information, then the parser can get reinvoked to perform a
877: parse of the document with the real encoding.</p>
878:
879: <p id="documentEncoding">User agents must use the following
880: algorithm (the <dfn id="encoding-sniffing-algorithm">encoding sniffing algorithm</dfn>) to determine
881: the character encoding to use when decoding a document in the first
882: pass. This algorithm takes as input any out-of-band metadata
883: available to the user agent (e.g. the <a href="infrastructure.html#content-type" title="Content-Type">Content-Type metadata</a> of the document)
884: and all the bytes available so far, and returns an encoding and a
885: <dfn id="concept-encoding-confidence" title="concept-encoding-confidence">confidence</dfn>. The
886: confidence is either <i>tentative</i>, <i>certain</i>, or
887: <i>irrelevant</i>. The encoding used, and whether the confidence in
888: that encoding is <i>tentative</i> or <i>certain</i>, is <a href="#meta-charset-during-parse">used during the parsing</a> to
889: determine whether to <a href="#change-the-encoding">change the encoding</a>. If no
890: encoding is necessary, e.g. because the parser is operating on a
891: stream of Unicode characters and doesn't have to use an encoding at
892: all, then the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
893: <i>irrelevant</i>.</p>
894:
895: <ol><li><p>If the transport layer specifies an encoding, and it is
896: supported, return that encoding with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
897: <i>certain</i>, and abort these steps.</p></li>
898:
899: <li><p>The user agent may wait for more bytes of the resource to be
900: available, either in this step or at any later step in this
901: algorithm. For instance, a user agent might wait 500ms or 512
902: bytes, whichever came first. In general preparsing the source to
903: find the encoding improves performance, as it reduces the need to
904: throw away the data structures used when parsing upon finding the
905: encoding information. However, if the user agent delays too long to
906: obtain data to determine the encoding, then the cost of the delay
907: could outweigh any performance improvements from the
908: preparse.</p></li>
909:
910: <li><p>For each of the rows in the following table, starting with
911: the first one and going down, if there are as many or more bytes
912: available than the number of bytes in the first column, and the
913: first bytes of the file match the bytes given in the first column,
914: then return the encoding given in the cell in the second column of
915: that row, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
916: <i>certain</i>, and abort these steps:</p>
917:
918: <!-- this table is present in several forms in this file; keep them in sync -->
919: <table><thead><tr><th>Bytes in Hexadecimal
920: </th><th>Encoding
921: </th></tr></thead><tbody><!-- nobody uses this
922: <tr>
923: <td>00 00 FE FF
924: <td>UTF-32BE
925: <tr>
926: <td>FF FE 00 00
927: <td>UTF-32LE
928: --><tr><td>FE FF
929: </td><td>UTF-16BE
930: </td></tr><tr><td>FF FE
931: </td><td>UTF-16LE
932: </td></tr><tr><td>EF BB BF
933: </td><td>UTF-8
934: <!-- nobody uses this
935: <tr>
936: <td>DD 73 66 73
937: <td>UTF-EBCDIC
938: -->
939: </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
940: (BOMs).</p></li>
941:
942: <li><p>Otherwise, the user agent will have to search for explicit
943: character encoding information in the file itself. This should
944: proceed as follows:
945:
946: </p><p>Let <var title="">position</var> be a pointer to a byte in the
947: input stream, initially pointing at the first byte. If at any
948: point during these substeps the user agent either runs out of
949: bytes or decides that scanning further bytes would not be
950: efficient, then skip to the next step of the overall character
951: encoding detection algorithm. User agents may decide that scanning
952: <em>any</em> bytes is not efficient, in which case these substeps
953: are entirely skipped.</p>
954:
955: <p>Now, repeat the following "two" steps until the algorithm
956: aborts (either because user agent aborts, as described above, or
957: because a character encoding is found):</p>
958:
959: <ol><li><p>If <var title="">position</var> points to:</p>
960:
961: <dl class="switch"><dt>A sequence of bytes starting with: 0x3C 0x21 0x2D 0x2D (ASCII '<!--')</dt>
962: <dd>
963:
964: <p>Advance the <var title="">position</var> pointer so that it
965: points at the first 0x3E byte which is preceded by two 0x2D
966: bytes (i.e. at the end of an ASCII '-->' sequence) and comes
967: after the 0x3C byte that was found. (The two 0x2D bytes can be
968: the same as the those in the '<!--' sequence.)</p>
969:
970: </dd>
971:
972: <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>
973: <dd>
974:
975: <ol><li><p>Advance the <var title="">position</var> pointer so
976: that it points at the next 0x09, 0x0A, 0x0C, 0x0D, 0x20, or
977: 0x2F byte (the one in sequence of characters matched
978: above).</p></li>
979:
980: <li><p><a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">Get
981: an attribute</a> and its value. If no attribute was
982: sniffed, then skip this inner set of steps, and jump to the
983: second step in the overall "two step" algorithm.</p></li>
984:
985: <li><p>If the attribute's name is neither "<code title="">charset</code>" nor "<code title="">content</code>",
986: then return to step 2 in these inner steps.</p></li>
987:
988: <li><p>If the attribute's name is "<code title="">charset</code>", let <var title="">charset</var> be
989: the attribute's value, interpreted as a character
990: encoding.</p></li>
991:
992: <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
993: extracting an encoding from a Content-Type</a>, giving the
994: attribute's value as the string to parse. If an encoding is
995: returned, let <var title="">charset</var> be that
996: encoding. Otherwise, return to step 2 in these inner
997: steps.</p></li>
998:
999: <li><p>If <var title="">charset</var> is a UTF-16 encoding,
1000: change the value of <var title="">charset</var> to
1001: UTF-8.</p></li>
1002:
1003: <li><p>If <var title="">charset</var> is a supported
1004: character encoding, then return the given encoding, with
1005: <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1006: <i>tentative</i>, and abort all these steps.</p></li>
1007:
1008: <li><p>Otherwise, return to step 2 in these inner
1009: steps.</p></li>
1010:
1011: </ol></dd>
1012:
1013: <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>
1014: <dd>
1015:
1016: <ol><li><p>Advance the <var title="">position</var> pointer so
1017: that it points at the next 0x09 (ASCII TAB), 0x0A (ASCII LF),
1018: 0x0C (ASCII FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E
1019: (ASCII '>') byte.</p></li>
1020:
1021: <li><p>Repeatedly <a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
1022: attribute</a> until no further attributes can be found,
1023: then jump to the second step in the overall "two step"
1024: algorithm.</p></li>
1025:
1026: </ol></dd>
1027:
1028: <dt>A sequence of bytes starting with: 0x3C 0x21 (ASCII '<!')</dt>
1029: <dt>A sequence of bytes starting with: 0x3C 0x2F (ASCII '</')</dt>
1030: <dt>A sequence of bytes starting with: 0x3C 0x3F (ASCII '<?')</dt>
1031: <dd>
1032:
1033: <p>Advance the <var title="">position</var> pointer so that it
1034: points at the first 0x3E byte (ASCII '>') that comes after the
1035: 0x3C byte that was found.</p>
1036:
1037: </dd>
1038:
1039: <dt>Any other byte</dt>
1040: <dd>
1041:
1042: <p>Do nothing with that byte.</p>
1043:
1044: </dd>
1045:
1046: </dl></li>
1047:
1048: <li>Move <var title="">position</var> so it points at the next
1049: byte in the input stream, and return to the first step of this
1050: "two step" algorithm.</li>
1051:
1052: </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
1053: attribute</dfn>, it means doing this:</p>
1054:
1055: <ol><li><p>If the byte at <var title="">position</var> is one of 0x09
1056: (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII FF), 0x0D (ASCII CR),
1057: 0x20 (ASCII space), or 0x2F (ASCII '/') then advance <var title="">position</var> to the next byte and redo this
1058: substep.</p></li>
1059:
1060: <li><p>If the byte at <var title="">position</var> is 0x3E (ASCII
1061: '>'), then abort the "get an attribute" algorithm. There isn't
1062: one.</p></li>
1063:
1064: <li><p>Otherwise, the byte at <var title="">position</var> is the
1065: start of the attribute name. Let <var title="">attribute
1066: name</var> and <var title="">attribute value</var> be the empty
1067: string.</p></li>
1068:
1069: <li><p><i>Attribute name</i>: Process the byte at <var title="">position</var> as follows:</p>
1070:
1071: <dl class="switch"><dt>If it is 0x3D (ASCII '='), and the <var title="">attribute
1072: name</var> is longer than the empty string</dt>
1073:
1074: <dd>Advance <var title="">position</var> to the next byte and
1075: jump to the step below labeled <i>value</i>.</dd>
1076:
1077: <dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
1078: FF), 0x0D (ASCII CR), or 0x20 (ASCII space)</dt>
1079:
1080: <dd>Jump to the step below labeled <i>spaces</i>.</dd>
1081:
1082: <dt>If it is 0x2F (ASCII '/') or 0x3E (ASCII '>')</dt>
1083:
1084: <dd>Abort the "get an attribute" algorithm. The attribute's
1085: name is the value of <var title="">attribute name</var>, its
1086: value is the empty string.</dd>
1087:
1088: <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
1089: 'Z')</dt>
1090:
1091: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1092: name</var> (where <var title="">b</var> is the value of the
1093: byte at <var title="">position</var>).</dd>
1094:
1095: <dt>Anything else</dt>
1096:
1097: <dd>Append the Unicode character with the same code point as the
1098: value of the byte at <var title="">position</var>) to <var title="">attribute name</var>. (It doesn't actually matter how
1099: bytes outside the ASCII range are handled here, since only
1100: ASCII characters can contribute to the detection of a character
1101: encoding.)</dd>
1102:
1103: </dl></li>
1104:
1105: <li><p>Advance <var title="">position</var> to the next byte and
1106: return to the previous step.</p></li>
1107:
1108: <li><p><i>Spaces</i>: If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
1109: LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
1110: advance <var title="">position</var> to the next byte, then,
1111: repeat this step.</p></li>
1112:
1113: <li><p>If the byte at <var title="">position</var> is
1114: <em>not</em> 0x3D (ASCII '='), abort the "get an attribute"
1115: algorithm. The attribute's name is the value of <var title="">attribute name</var>, its value is the empty
1116: string.</p></li>
1117:
1118: <li><p>Advance <var title="">position</var> past the 0x3D (ASCII
1119: '=') byte.</p></li>
1120:
1121: <li><p><i>Value:</i> If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
1122: LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
1123: advance <var title="">position</var> to the next byte, then,
1124: repeat this step.</p></li>
1125:
1126: <li><p>Process the byte at <var title="">position</var> as
1127: follows:</p>
1128:
1129: <dl class="switch"><dt>If it is 0x22 (ASCII '"') or 0x27 ("'")</dt>
1130:
1131: <dd>
1132:
1133: <ol><li>Let <var title="">b</var> be the value of the byte at
1134: <var title="">position</var>.</li>
1135:
1136: <li>Advance <var title="">position</var> to the next
1137: byte.</li>
1138:
1139: <li>If the value of the byte at <var title="">position</var>
1140: is the value of <var title="">b</var>, then advance <var title="">position</var> to the next byte and abort the "get
1141: an attribute" algorithm. The attribute's name is the value of
1142: <var title="">attribute name</var>, and its value is the
1143: value of <var title="">attribute value</var>.</li>
1144:
1145: <li>Otherwise, if the value of the byte at <var title="">position</var> is in the range 0x41 (ASCII 'A') to
1146: 0x5A (ASCII 'Z'), then append a Unicode character to <var title="">attribute value</var> whose code point is 0x20 more
1147: than the value of the byte at <var title="">position</var>.</li>
1148:
1149: <li>Otherwise, append a Unicode character to <var title="">attribute value</var> whose code point is the same as
1150: the value of the byte at <var title="">position</var>.</li>
1151:
1152: <li>Return to the second step in these substeps.</li>
1153:
1154: </ol></dd>
1155:
1156: <dt>If it is 0x3E (ASCII '>')</dt>
1157:
1158: <dd>Abort the "get an attribute" algorithm. The attribute's
1159: name is the value of <var title="">attribute name</var>, its
1160: value is the empty string.</dd>
1161:
1162:
1163: <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
1164: 'Z')</dt>
1165:
1166: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1167: value</var> (where <var title="">b</var> is the value of the
1168: byte at <var title="">position</var>). Advance <var title="">position</var> to the next byte.</dd>
1169:
1170: <dt>Anything else</dt>
1171:
1172: <dd>Append the Unicode character with the same code point as the
1173: 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>
1174:
1175: </dl></li>
1176:
1177: <li><p>Process the byte at <var title="">position</var> as
1178: follows:</p>
1179:
1180: <dl class="switch"><dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
1181: FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E (ASCII
1182: '>')</dt>
1183:
1184: <dd>Abort the "get an attribute" algorithm. The attribute's
1185: name is the value of <var title="">attribute name</var> and its
1186: value is the value of <var title="">attribute value</var>.</dd>
1187:
1188: <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
1189: 'Z')</dt>
1190:
1191: <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
1192: value</var> (where <var title="">b</var> is the value of the
1193: byte at <var title="">position</var>).</dd>
1194:
1195: <dt>Anything else</dt>
1196:
1197: <dd>Append the Unicode character with the same code point as the
1198: value of the byte at <var title="">position</var>) to <var title="">attribute value</var>.</dd>
1199:
1200: </dl></li>
1201:
1202: <li><p>Advance <var title="">position</var> to the next byte and
1203: return to the previous step.</p></li>
1204:
1205: </ol><p>For the sake of interoperability, user agents should not use a
1206: pre-scan algorithm that returns different results than the one
1207: described above. (But, if you do, please at least let us know, so
1208: that we can improve this algorithm and benefit everyone...)</p>
1209:
1210: </li>
1211:
1212: <li><p>If the user agent has information on the likely encoding for
1213: this page, e.g. based on the encoding of the page when it was last
1214: visited, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1215: <i>tentative</i>, and abort these steps.</p></li>
1216:
1217: <li><p>The user agent may attempt to autodetect the character
1218: encoding from applying frequency analysis or other algorithms to
1219: the data stream. If autodetection succeeds in determining a
1220: character encoding, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1.104 mike 1221: <i>tentative</i>, and abort these steps. <a href="references.html#refsUNIVCHARDET">[UNIVCHARDET]</a></p></li>
1.1 mike 1222:
1223: <li><p>Otherwise, return an implementation-defined or
1224: user-specified default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1225: <i>tentative</i>. In non-legacy environments, the more
1226: comprehensive <code title="">UTF-8</code> encoding is
1227: recommended. Due to its use in legacy content, <code title="">windows-1252</code> is recommended as a default in
1228: predominantly Western demographics instead. Since these encodings
1229: can in many cases be distinguished by inspection, a user agent may
1230: heuristically decide which to use as a default.</p></li>
1231:
1232: </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
1233: be set to the value returned from this algorithm, at the same time
1234: as the user agent uses the returned value to select the decoder to
1235: use for the input stream.</p>
1236:
1237:
1238:
1239: <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.2 </span>Preprocessing the input stream</h5>
1240:
1241: <p>Given an encoding, the bytes in the input stream must be
1242: converted to Unicode characters for the tokenizer, as described by
1243: the rules for that encoding, except that the leading U+FEFF BYTE
1244: ORDER MARK character, if any, must not be stripped by the encoding
1245: layer (it is stripped by the rule below).</p> <!-- this is to
1246: prevent two leading BOMs from being both stripped, once by the
1247: decoder, and once by the parser -->
1248:
1249: <p>Bytes or sequences of bytes in the original byte stream that
1250: could not be converted to Unicode characters must be converted to
1251: U+FFFD REPLACEMENT CHARACTER code points.</p>
1252:
1253: <p class="note">Bytes or sequences of bytes in the original byte
1254: stream that did not conform to the encoding specification
1255: (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
1256: errors that conformance checkers are expected to report.</p>
1257:
1258: <p>Any byte or sequences of bytes in the original byte stream that
1259: is <a href="infrastructure.html#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
1260: error</a>.</p>
1261:
1262: <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
1263: any are present.</p>
1264:
1265: <p>All U+0000 NULL characters in the input must be replaced by
1266: U+FFFD REPLACEMENT CHARACTERs. Any occurrences of such characters is
1267: a <a href="#parse-error">parse error</a>.</p>
1268:
1269: <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
1270: <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
1271: CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
1272: <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+D800
1273: to U+DFFF<!-- surrogates not allowed -->, U+FDD0 to U+FDEF, and
1274: characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF, U+2FFFE,
1275: U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE, U+5FFFF,
1276: U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF, U+9FFFE,
1277: U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE, U+CFFFF,
1278: U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF, U+10FFFE, and
1279: U+10FFFF are <a href="#parse-error" title="parse error">parse errors</a>. (These
1280: are all control characters or permanently undefined Unicode
1281: characters.)</p>
1282:
1283: <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
1284: characters are treated specially. Any CR characters that are
1285: followed by LF characters must be removed, and any CR characters not
1286: followed by LF characters must be converted to LF characters. Thus,
1287: newlines in HTML DOMs are represented by LF characters, and there
1288: are never any CR characters in the input to the
1289: <a href="#tokenization">tokenization</a> stage.</p>
1290:
1291: <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
1292: input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
1293: the <i><a href="#next-input-character">next input character</a></i> is the first character in the
1294: input. The <dfn id="current-input-character">current input character</dfn> is the last character
1295: to have been <i><a href="#consumed">consumed</a></i>.</p>
1296:
1297: <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
1298: character or just before the end of the input stream) where content
1299: inserted using <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code> is actually
1300: inserted. The insertion point is relative to the position of the
1301: character immediately after it, it is not an absolute offset into
1302: the input stream. Initially, the insertion point is
1.10 mike 1303: undefined.</p>
1.1 mike 1304:
1305: <p>The "EOF" character in the tables below is a conceptual character
1306: representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
1307: is a <a href="dom.html#script-created-parser">script-created parser</a>, then the end of the
1308: <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
1309: character</dfn> (inserted by the <code title="dom-document-close"><a href="dom.html#dom-document-close">document.close()</a></code> method) is
1310: consumed. Otherwise, the "EOF" character is not a real character in
1311: the stream, but rather the lack of any further characters.</p>
1312:
1313:
1314: <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.3 </span>Changing the encoding while parsing</h5>
1315:
1316: <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
1317: encoding</dfn>, it must run the following steps. This might happen
1318: if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
1319: failed to find an encoding, or if it found an encoding that was not
1320: the actual encoding of the file.</p>
1321:
1322: <ol><li>If the new encoding is identical or equivalent to the encoding
1323: that is already being used to interpret the input stream, then set
1324: the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1325: <i>certain</i> and abort these steps. This happens when the
1326: encoding information found in the file matches what the
1327: <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
1328: encoding, and in the second pass through the parser if the first
1329: pass found that the encoding sniffing algorithm described in the
1330: earlier section failed to find the right encoding.</li>
1331:
1332: <li>If the encoding that is already being used to interpret the
1333: input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1334: <i>certain</i> and abort these steps. The new encoding is ignored;
1335: if it was anything but the same encoding, then it would be clearly
1336: incorrect.</li>
1337:
1338: <li>If the new encoding is a UTF-16 encoding, change it to
1339: UTF-8.</li>
1340:
1341: <li>If all the bytes up to the last byte converted by the current
1342: decoder have the same Unicode interpretations in both the current
1343: encoding and the new encoding, and if the user agent supports
1344: changing the converter on the fly, then the user agent may change
1345: to the new converter for the encoding on the fly. Set the
1346: <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
1347: convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1348: <i>certain</i>, and abort these steps.</li>
1349:
1350: <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
1351: <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
1352: browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
1353: sniffing algorithm</a> and instead just set the encoding to the
1354: new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1355: <i>certain</i>. Whenever possible, this should be done without
1356: actually contacting the network layer (the bytes should be
1357: re-parsed from memory), even if, e.g., the document is marked as
1358: not being cacheable. If this is not possible and contacting the
1359: network layer would involve repeating a request that uses a method
1360: other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
1361: equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
1362: <i>certain</i> and ignore the new encoding. The resource will be
1363: misinterpreted. User agents may notify the user of the situation,
1364: to aid in application development.</li>
1365:
1366: </ol><h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4>
1367:
1368: <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5>
1369:
1370: <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
1371: the primary operation of the tree construction stage.</p>
1372:
1373: <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
1374: "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
1375: "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
1376: "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>", "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head noscript</a>",
1.91 mike 1377: "<a href="#the-after-head-insertion-mode" title="insertion mode: after head">after head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>", "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>",
1.1 mike 1378: "<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>",
1379: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
1380: "<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
1381: table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
1382: foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
1383: body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
1384: frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
1385: frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
1386: after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
1387: frameset</a>" during the course of the parsing, as described in
1388: the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
1389: how tokens are processed and whether CDATA sections are
1390: supported.</p>
1391:
1392: <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
1393: head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
1394: body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
1395: table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
1396: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
1397: "<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
1398: that the other modes defer to them at various times. When the
1399: algorithm below says that the user agent is to do something
1400: "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
1401: mode", where <var title="">m</var> is one of these modes, the user
1402: agent must use the rules described under the <var title="">m</var>
1403: <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
1404: <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>
1405: to a new value.</p>
1406:
1407: <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.91 mike 1408: mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>" or "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table text</a>", the
1.1 mike 1409: <dfn id="original-insertion-mode">original insertion mode</dfn> is also set. This is the
1410: insertion mode to which the tree construction stage will return.</p>
1411:
1412: <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
1413: mode: in foreign content">in foreign content</a>", the
1414: <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
1415: is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
1416: foreign content">in foreign content</a>" mode to handle HTML
1417: (i.e. not foreign) content.</p>
1418:
1419: <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
1420: mode appropriately</dfn>, it means the UA must follow these
1421: steps:</p>
1422:
1423: <ol><li>Let <var title="">last</var> be false.</li>
1424:
1425: <li>Let <var title="">node</var> be the last node in the
1426: <a href="#stack-of-open-elements">stack of open elements</a>.</li>
1427:
1428: <li>If <var title="">node</var> is the first node in the stack of
1429: open elements, then set <var title="">last</var> to true and set
1430: <var title="">node</var> to the <var title="">context</var>
1431: element. (<a href="#fragment-case">fragment case</a>)</li>
1432:
1433: <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
1434: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>" and abort these
1435: steps. (<a href="#fragment-case">fragment case</a>)</li>
1436:
1437: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
1438: <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
1439: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
1440: mode: in cell">in cell</a>" and abort these steps.</li>
1441:
1442: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
1443: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
1444: mode: in row">in row</a>" and abort these steps.</li>
1445:
1446: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
1447: <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
1448: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
1449: table body">in table body</a>" and abort these steps.</li>
1450:
1451: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
1452: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>" and abort
1453: these steps.</li>
1454:
1455: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
1456: 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
1457: abort these steps. (<a href="#fragment-case">fragment case</a>)</li>
1458:
1459: <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
1460: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" and abort these
1461: steps.</li>
1462:
1463: <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
1464: namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then switch the
1465: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
1466: foreign content">in foreign content</a>", let the
1467: <a href="#secondary-insertion-mode">secondary insertion mode</a> be "<a href="#parsing-main-inbody" title="insertion
1468: mode: in body">in body</a>", and abort these steps.</li>
1469:
1470: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element">head</a></code> element,
1471: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" ("<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>"! <em> not "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>"</em>!) and abort
1472: these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- This is only
1473: here for now in case people think that the spec accidentally
1474: omitted it and try to "fix" it. Note that noscript-in-head is also
1475: handled this way. This is all intentional. The only thing it
1476: doesn't handle is the scripting-disabled fragment parsing case for
1477: a <head> element containing a <noscript> which itself contains
1478: something other than a <link> or a <style> element; you'd expect
1479: that to break out of the <noscript> but it doesn't. This is an edge
1480: case that doesn't affect the spec, since the algorithm for fragment
1481: parsing is only used for innerHTML/outerHTML/insertAdjacentHTML(),
1482: where we know scripting is enabled. (XXX except maybe if innerHTML
1483: is set from another browsing context on a document with designMode
1484: set?) -->
1485:
1486: <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element">body</a></code> element,
1487: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and abort these
1488: steps.</li>
1489:
1.5 mike 1490: <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.1 mike 1491: then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>" and abort
1492: these steps. (<a href="#fragment-case">fragment case</a>)</li>
1493:
1494: <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element">html</a></code> element,
1495: then: if the <a href="#head-element-pointer"><code title="">head</code> element
1496: pointer</a> is null, switch the <a href="#insertion-mode">insertion mode</a> to
1497: "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
1498: otherwise, 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>". In either
1499: case, abort these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- XXX
1500: can the head element pointer ever be non-null when we're going
1501: through these steps? -->
1502:
1503: <li>If <var title="">last</var> is true, then switch the
1504: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
1505: body">in body</a>" and abort these steps. (<a href="#fragment-case">fragment
1506: case</a>)</li>
1507:
1508: <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
1509: elements</a>.</li>
1510:
1511: <li>Return to step 3.</li>
1512:
1513: </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5>
1514:
1515: <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
1516: stack grows downwards; the topmost node on the stack is the first
1517: one added to the stack, and the bottommost node of the stack is the
1518: most recently added node in the stack (notwithstanding when the
1519: stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
1520:
1521: <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
1522: html</a>" <a href="#insertion-mode">insertion mode</a> creates the
1523: <code><a href="semantics.html#the-html-element">html</a></code> root element node, which is then added to the
1524: stack.</p>
1525:
1526: <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
1527: elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element">html</a></code>
1528: element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
1529: parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
1530: case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
1531: html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
1532:
1533: <p>The <code><a href="semantics.html#the-html-element">html</a></code> node, however it is created, is the topmost
1534: node of the stack. It never gets popped off the stack.</p>
1535:
1536: <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
1537: stack.</p>
1538:
1539: <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
1540: element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
1541: 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
1542: open elements</a> (<a href="#fragment-case">fragment case</a>), then the
1543: <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
1544: of open elements</a> (the <code><a href="semantics.html#the-html-element">html</a></code> element).</p>
1545:
1546: <p>Elements in the stack fall into the following categories:</p>
1547:
1548: <dl><dt><dfn id="special">Special</dfn></dt>
1549:
1550: <dd><p>The following HTML elements have varying levels of special
1551: 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>,
1552: <code><a href="semantics.html#the-article-element">article</a></code>, <code><a href="semantics.html#the-aside-element">aside</a></code>, <code><a href="semantics.html#the-base-element">base</a></code>,
1.5 mike 1553: <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.1 mike 1554: <code><a href="semantics.html#the-blockquote-element">blockquote</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="semantics.html#the-br-element">br</a></code>,
1.5 mike 1555: <code><a href="obsolete.html#center">center</a></code>, <code><a href="tabular-data.html#the-col-element">col</a></code>, <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code>,
1.86 mike 1556: <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
1557: <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="semantics.html#the-dialog-element">dialog</a></code>,
1558: <code><a href="obsolete.html#dir">dir</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, <code><a href="semantics.html#the-dl-element">dl</a></code>,
1559: <code><a href="semantics.html#the-dt-element">dt</a></code>, <code><a href="embedded-content-0.html#the-embed-element">embed</a></code>, <code><a href="forms.html#the-fieldset-element">fieldset</a></code>,
1560: <code><a href="embedded-content-0.html#the-figure-element">figure</a></code>, <code><a href="semantics.html#the-footer-element">footer</a></code>, <code><a href="forms.html#the-form-element">form</a></code>,
1561: <code><a href="obsolete.html#frame">frame</a></code>, <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>,
1562: <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>,
1563: <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h6</a></code>, <code><a href="semantics.html#the-head-element">head</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>,
1564: <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code>, <!--
1565: <code>image</code>, (commented out because this isn't an element
1566: that can end up on the stack, so it doesn't matter) -->
1567: <code><a href="embedded-content-0.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="obsolete.html#isindex-0">isindex</a></code>,
1568: <code><a href="semantics.html#the-li-element">li</a></code>, <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="obsolete.html#listing">listing</a></code>,
1569: <code><a href="interactive-elements.html#menus">menu</a></code>, <code><a href="semantics.html#meta">meta</a></code>, <code><a href="semantics.html#the-nav-element">nav</a></code>,
1570: <code><a href="obsolete.html#noembed">noembed</a></code>, <code><a href="obsolete.html#noframes">noframes</a></code>, <code><a href="semantics.html#the-noscript-element">noscript</a></code>,
1571: <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="embedded-content-0.html#the-param-element">param</a></code>,
1572: <code><a href="obsolete.html#plaintext">plaintext</a></code>, <code><a href="semantics.html#the-pre-element">pre</a></code>, <code><a href="semantics.html#script">script</a></code>,
1573: <code><a href="semantics.html#the-section-element">section</a></code>, <code><a href="forms.html#the-select-element">select</a></code>, <code><a href="obsolete.html#spacer">spacer</a></code>,
1574: <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="forms.html#the-textarea-element">textarea</a></code>,
1575: <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, <code><a href="semantics.html#the-title-element">title</a></code>,
1576: <code><a href="tabular-data.html#the-tr-element">tr</a></code>, <code><a href="semantics.html#the-ul-element">ul</a></code>, and <code>wbr</code>.</p></dd>
1.1 mike 1577:
1578: <dt><dfn id="scoping">Scoping</dfn></dt>
1579: <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
1580: an element in scope">scopes</a> for various parts of the
1.5 mike 1581: parsing: <code><a href="obsolete.html#the-applet-element">applet</a></code>, <code><a href="forms.html#the-button-element">button</a></code>,
1582: <code><a href="tabular-data.html#the-caption-element">caption</a></code>, <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="obsolete.html#the-marquee-element-0">marquee</a></code>,
1.1 mike 1583: <code><a href="embedded-content-0.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>,
1584: <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
1585:
1586: <dt><dfn id="formatting">Formatting</dfn></dt>
1587: <dd><p>The following HTML elements are those that end up in the
1588: <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 1589: <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>,
1590: <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>,
1591: <code>nobr</code>, <code><a href="obsolete.html#s">s</a></code>, <code><a href="text-level-semantics.html#the-small-element">small</a></code>,
1592: <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
1593: <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1 mike 1594:
1595: <dt><dfn id="phrasing">Phrasing</dfn></dt>
1596: <dd><p>All other elements found while parsing an HTML
1597: document.</p></dd>
1598:
1599: </dl><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
1600: the following algorithm terminates in a match state:</p>
1601:
1602: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
1603: node</a> (the bottommost node of the stack).</p></li>
1604:
1605: <li><p>If <var title="">node</var> is the target node, terminate in
1606: a match state.</p></li>
1607:
1608: <li><p>Otherwise, if <var title="">node</var> is one of the
1609: following elements, terminate in a failure state:</p>
1.5 mike 1610: <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
1.1 mike 1611: <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
1612: <li><code><a href="semantics.html#the-html-element">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.) -->
1613: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
1614: <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
1615: <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
1616: <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
1.5 mike 1617: <li><code><a href="obsolete.html#the-marquee-element-0">marquee</a></code> in the HTML namespace</li>
1.1 mike 1618: <li><code><a href="embedded-content-0.html#the-object-element">object</a></code> in the HTML namespace</li>
1619: <li><code title="">foreignObject</code> in the SVG namespace</li>
1620: </ul></li>
1621:
1622: <li><p>Otherwise, set <var title="">node</var> to the previous
1623: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
1624: 2. (This will never fail, since the loop will always terminate in
1625: the previous step if the top of the stack — an
1626: <code><a href="semantics.html#the-html-element">html</a></code> element — is reached.)</p></li>
1627:
1628: </ol><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
1629: scope</em></dfn> when the following algorithm terminates in a match
1630: state:</p>
1631:
1632: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
1633: node</a> (the bottommost node of the stack).</p></li>
1634:
1635: <li><p>If <var title="">node</var> is the target node, terminate in
1636: a match state.</p></li>
1637:
1638: <li><p>Otherwise, if <var title="">node</var> is one of the
1639: following elements, terminate in a failure state:</p>
1640: <ul class="brief"><li><code><a href="semantics.html#the-html-element">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.) -->
1641: <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
1642: </ul></li>
1643:
1644: <li><p>Otherwise, set <var title="">node</var> to the previous
1645: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
1646: 2. (This will never fail, since the loop will always terminate in
1647: the previous step if the top of the stack — an
1648: <code><a href="semantics.html#the-html-element">html</a></code> element — is reached.)</p></li>
1649:
1650: </ol><p>Nothing happens if at any time any of the elements in the
1651: <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
1652: or removed from, the <code>Document</code> tree. In particular, the
1653: stack is not changed in this situation. This can cause, amongst
1654: other strange effects, content to be appended to nodes that are no
1655: longer in the DOM.</p>
1656:
1657: <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
1658: the stack is manipulated in a random-access fashion.</p>
1659:
1660:
1661: <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5>
1662:
1663: <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
1664: empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
1665:
1666: <p>The list contains elements in the <a href="#formatting">formatting</a>
1667: category, and scope markers. The scope markers are inserted when
1.5 mike 1668: entering <code><a href="obsolete.html#the-applet-element">applet</a></code> elements, buttons, <code><a href="embedded-content-0.html#the-object-element">object</a></code>
1.1 mike 1669: elements, marquees, table cells, and table captions, and are used to
1.5 mike 1670: prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.1 mike 1671: elements, buttons, <code><a href="embedded-content-0.html#the-object-element">object</a></code> elements, marquees, and
1672: tables.</p>
1673:
1674: <p class="note">The scope markers are unrelated to the concept of an
1675: element being <a href="#has-an-element-in-scope" title="has an element in scope">in
1676: scope</a>.</p>
1677:
1678: <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
1679: elements</a> is associated with the token for which it was
1680: created, so that further elements can be created for that token if
1681: necessary.</p>
1682:
1683: <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
1684: active formatting elements</dfn>, the UA must perform the following
1685: steps:</p>
1686:
1687: <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
1688: elements</a>, then there is nothing to reconstruct; stop this
1689: algorithm.</li>
1690:
1691: <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
1692: active formatting elements</a> is a marker, or if it is an
1693: element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
1694: there is nothing to reconstruct; stop this algorithm.</li>
1695:
1696: <li>Let <var title="">entry</var> be the last (most recently added)
1697: element in the <a href="#list-of-active-formatting-elements">list of active formatting
1698: elements</a>.</li>
1699:
1700: <li>If there are no entries before <var title="">entry</var> in the
1701: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
1702: 8.</li>
1703:
1704: <li>Let <var title="">entry</var> be the entry one earlier than
1705: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
1706: elements</a>.</li>
1707:
1708: <li>If <var title="">entry</var> is neither a marker nor an element
1709: that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
1710: 4.</li>
1711:
1712: <li>Let <var title="">entry</var> be the element one later than
1713: <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
1714: elements</a>.</li>
1715:
1716: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
1717: element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
1718:
1719: <li>Append <var title="">new element</var> to the <a href="#current-node">current
1720: node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
1721: elements</a> so that it is the new <a href="#current-node">current
1722: node</a>.</li>
1723:
1724: <li>Replace the entry for <var title="">entry</var> in the list
1725: with an entry for <var title="">new element</var>.</li>
1726:
1727: <li>If the entry for <var title="">new element</var> in the
1728: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
1729: entry in the list, return to step 7.</li>
1730:
1731: </ol><p>This has the effect of reopening all the formatting elements that
1732: were opened in the current body, cell, or caption (whichever is
1733: youngest) that haven't been explicitly closed.</p>
1734:
1735: <p class="note">The way this specification is written, the
1736: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
1737: elements in chronological order with the least recently added
1738: element first and the most recently added element last (except for
1739: while steps 8 to 11 of the above algorithm are being executed, of
1740: course).</p>
1741:
1742: <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
1743: active formatting elements up to the last marker</dfn>, the UA must
1744: perform the following steps:</p>
1745:
1746: <ol><li>Let <var title="">entry</var> be the last (most recently added)
1747: entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
1748:
1749: <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
1750: formatting elements</a>.</li>
1751:
1752: <li>If <var title="">entry</var> was a marker, then stop the
1753: algorithm at this point. The list has been cleared up to the last
1754: marker.</li>
1755:
1756: <li>Go to step 1.</li>
1757:
1758: </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5>
1759:
1760: <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
1761: pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
1762: pointer</dfn> are both null.</p>
1763:
1764: <p>Once a <code><a href="semantics.html#the-head-element">head</a></code> element has been parsed (whether
1765: implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
1766: element pointer</a> gets set to point to this node.</p>
1767:
1768: <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
1769: points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
1770: whose end tag has not yet been seen. It is used to make form
1771: controls associate with forms in the face of dramatically bad
1772: markup, for historical reasons.</p>
1773:
1774:
1775: <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5>
1776:
1777: <p>The <dfn id="scripting-flag">scripting flag</dfn> is set to "enabled" if <a href="browsers.html#concept-n-script" title="concept-n-script">scripting was enabled</a> for the
1778: <code>Document</code> with which the parser is associated when the
1779: parser was created, and "disabled" otherwise.</p>
1780:
1781: <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
1782: when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
1783: parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
1784: don't execute in that case.</p>
1785:
1786: <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
1787: created. It is set to "not ok" after certain tokens are seen.</p>
1788:
1789:
1790: <h4 id="tokenization"><span class="secno">9.2.4 </span><dfn>Tokenization</dfn></h4>
1791:
1792: <p>Implementations must act as if they used the following state
1793: machine to tokenize HTML. The state machine must start in the
1794: <a href="#data-state">data state</a>. Most states consume a single character,
1795: which may have various side-effects, and either switches the state
1796: machine to a new state to <em>reconsume</em> the same character, or
1797: switches it to a new state (to consume the next character), or
1798: repeats the same state (to consume the next character). Some states
1799: have more complicated behavior and can consume several characters
1800: before switching to another state.</p>
1801:
1802: <p>The exact behavior of certain states depends on a <dfn id="content-model-flag">content
1803: model flag</dfn> that is set after certain tokens are emitted. The
1.91 mike 1804: flag has several states: <i title="">PCDATA</i>, <i title="">RCDATA</i>, <i title="">RAWTEXT</i>, and <i title="">PLAINTEXT</i>. Initially, it must be in the PCDATA
1805: state. In the RCDATA and RAWTEXT states, a further <dfn id="escape-flag">escape
1.1 mike 1806: flag</dfn> is used to control the behavior of the tokenizer. It is
1807: either true or false, and initially must be set to the false
1808: state. The <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
1809: elements</a> also affects tokenization.</p>
1810:
1811: <p>The output of the tokenization step is a series of zero or more
1812: of the following tokens: DOCTYPE, start tag, end tag, comment,
1813: character, end-of-file. DOCTYPE tokens have a name, a public
1814: identifier, a system identifier, and a <i>force-quirks
1815: flag</i>. When a DOCTYPE token is created, its name, public
1816: identifier, and system identifier must be marked as missing (which
1817: is a distinct state from the empty string), and the <i>force-quirks
1818: flag</i> must be set to <i>off</i> (its other state is
1819: <i>on</i>). Start and end tag tokens have a tag name, a
1820: <i>self-closing flag</i>, and a list of attributes, each of which
1821: has a name and a value. When a start or end tag token is created,
1822: its <i>self-closing flag</i> must be unset (its other state is that
1823: it be set), and its attributes list must be empty. Comment and
1824: character tokens have data.</p>
1825:
1826: <p>When a token is emitted, it must immediately be handled by the
1827: <a href="#tree-construction">tree construction</a> stage. The tree construction stage
1828: can affect the state of the <a href="#content-model-flag">content model flag</a>, and can
1829: insert additional characters into the stream. (For example, the
1830: <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
1831: using the <a href="dom.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
1832: characters into the stream being tokenized.)</p>
1833:
1834: <p>When a start tag token is emitted with its <i>self-closing
1835: flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
1836: self-closing flag">acknowledged</dfn> when it is processed by the
1837: tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
1838:
1839: <p>When an end tag token is emitted, the <a href="#content-model-flag">content model
1840: flag</a> must be switched to the PCDATA state.</p>
1841:
1842: <p>When an end tag token is emitted with attributes, that is a
1843: <a href="#parse-error">parse error</a>.</p>
1844:
1845: <p>When an end tag token is emitted with its <i>self-closing
1846: flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
1847:
1848: <p>Before each step of the tokenizer, the user agent must first
1849: check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
1850: tokenizer must abort the processing of any nested invocations of the
1851: tokenizer, yielding control back to the caller. If it is false, then
1852: the user agent may then check to see if either one of the scripts in
1853: the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will execute as soon as
1854: possible</a> or the first script in the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts
1855: that will execute asynchronously</a>, has <a href="semantics.html#completed-loading">completed
1856: loading</a>. If one has, then it must be <a href="semantics.html#executing-a-script-block" title="executing a
1857: script block">executed</a> and removed from its list.</p>
1858:
1859: <p>The tokenizer state machine consists of the states defined in the
1860: following subsections.</p>
1861:
1862: <!-- XXX should go through these reordering the entries so that
1863: they're in some consistent order, like, by Unicode, errors last, or
1864: something -->
1865:
1866: <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5>
1867:
1868: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1869:
1870: <dl class="switch"><dt>U+0026 AMPERSAND (&)</dt>
1871: <dd>When the <a href="#content-model-flag">content model flag</a> is set to one of the
1872: PCDATA or RCDATA states and the <a href="#escape-flag">escape flag</a> is
1873: false: switch to the <a href="#character-reference-data-state">character reference data
1.56 mike 1874: state</a>.</dd>
1875: <dd>Otherwise: treat it as per the "anything else" entry
1876: below.</dd>
1.1 mike 1877:
1878: <dt>U+002D HYPHEN-MINUS (-)</dt>
1879: <dd>
1880:
1881: <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 1882: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1 mike 1883: is false, and there are at least three characters before this
1884: one in the input stream, and the last four characters in the
1885: input stream, including this one, are U+003C LESS-THAN SIGN,
1886: U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, and U+002D
1887: HYPHEN-MINUS ("<!--"), then set the <a href="#escape-flag">escape flag</a>
1888: to true.</p>
1889:
1890: <p>In any case, emit the input character as a character
1891: token. Stay in the <a href="#data-state">data state</a>.</p>
1892:
1893: </dd>
1894:
1895: <dt>U+003C LESS-THAN SIGN (<)</dt>
1896: <dd>When the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
1897: state: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
1898: <dd>When the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 1899: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1 mike 1900: is false: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
1901: <dd>Otherwise: treat it as per the "anything else" entry
1902: below.</dd>
1903:
1904: <dt>U+003E GREATER-THAN SIGN (>)</dt>
1905: <dd>
1906:
1907: <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91 mike 1908: RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape
1.1 mike 1909: flag</a> is true, and the last three characters in the input
1910: stream including this one are U+002D HYPHEN-MINUS, U+002D
1911: HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("-->"), set the
1912: <a href="#escape-flag">escape flag</a> to false.</p> <!-- no need to check
1913: that there are enough characters, since you can only run into
1914: this if the flag is true in the first place, which requires four
1915: characters. -->
1916:
1917: <p>In any case, emit the input character as a character
1918: token. Stay in the <a href="#data-state">data state</a>.</p>
1919:
1920: </dd>
1921:
1922: <dt>EOF</dt>
1923: <dd>Emit an end-of-file token.</dd>
1924:
1925: <dt>Anything else</dt>
1926: <dd>Emit the input character as a character token. Stay in the
1927: <a href="#data-state">data state</a>.</dd>
1928:
1929: </dl><h5 id="character-reference-data-state"><span class="secno">9.2.4.2 </span><dfn>Character reference data state</dfn></h5>
1930:
1931: <p><i>(This cannot happen if the <a href="#content-model-flag">content model flag</a>
1.91 mike 1932: is set to the RAWTEXT state.)</i></p>
1.1 mike 1933:
1934: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
1935: <a href="#additional-allowed-character">additional allowed character</a>.</p>
1936:
1937: <p>If nothing is returned, emit a U+0026 AMPERSAND character
1938: token.</p>
1939:
1940: <p>Otherwise, emit the character token that was returned.</p>
1941:
1942: <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
1943:
1944:
1945: <h5 id="tag-open-state"><span class="secno">9.2.4.3 </span><dfn>Tag open state</dfn></h5>
1946:
1947: <p>The behavior of this state depends on the <a href="#content-model-flag">content model
1948: flag</a>.</p>
1949:
1950: <dl><dt>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA
1.91 mike 1951: or RAWTEXT states</dt>
1.1 mike 1952:
1953: <dd>
1954:
1955: <p>Consume the <a href="#next-input-character">next input character</a>. If it is a
1956: U+002F SOLIDUS (/) character, switch to the <a href="#close-tag-open-state">close tag open
1957: state</a>. Otherwise, emit a U+003C LESS-THAN SIGN character
1958: token and reconsume the <a href="#current-input-character">current input character</a> in the
1959: <a href="#data-state">data state</a>.</p>
1960:
1961: </dd>
1962:
1963: <dt>If the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
1964: state</dt>
1965:
1966: <dd>
1967:
1968: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
1969:
1970: <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
1971: <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
1972:
1973: <dt>U+002F SOLIDUS (/)</dt>
1974: <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
1975:
1976: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
1977: <dd>Create a new start tag token, set its tag name to the
1978: lowercase version of the input character (add 0x0020 to the
1979: character's code point), then switch to the <a href="#tag-name-state">tag name
1980: state</a>. (Don't emit the token yet; further details will
1981: be filled in before it is emitted.)</dd>
1982:
1983: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
1984: <dd>Create a new start tag token, set its tag name to the input
1985: character, then switch to the <a href="#tag-name-state">tag name
1986: state</a>. (Don't emit the token yet; further details will
1987: be filled in before it is emitted.)</dd>
1988:
1989: <dt>U+003E GREATER-THAN SIGN (>)</dt>
1990: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
1991: character token and a U+003E GREATER-THAN SIGN character
1992: token. Switch to the <a href="#data-state">data state</a>.</dd>
1993:
1994: <dt>U+003F QUESTION MARK (?)</dt>
1995: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
1996: comment state</a>.</dd>
1997:
1998: <dt>Anything else</dt>
1999: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2000: character token and reconsume the <a href="#current-input-character">current input character</a> in the
2001: <a href="#data-state">data state</a>.</dd>
2002:
2003: </dl></dd>
2004:
2005: </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.4 </span><dfn>Close tag open state</dfn></h5>
2006:
2007: <p>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA or
1.91 mike 2008: RAWTEXT states but no start tag token has ever been emitted by this
1.1 mike 2009: instance of the tokenizer (<a href="#fragment-case">fragment case</a>), or, if the
1.91 mike 2010: <a href="#content-model-flag">content model flag</a> is set to the RCDATA or RAWTEXT states
1.1 mike 2011: and the next few characters do not match the tag name of the last
2012: start tag token emitted (compared in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2013: case-insensitive</a> manner), or if they do but they are not
2014: immediately followed by one of the following characters:</p>
2015:
2016: <ul class="brief"><li>U+0009 CHARACTER TABULATION</li>
2017: <li>U+000A LINE FEED (LF)</li>
2018: <li>U+000C FORM FEED (FF)</li>
2019: <!--<li>U+000D CARRIAGE RETURN (CR)</li>-->
2020: <li>U+0020 SPACE</li>
2021: <li>U+003E GREATER-THAN SIGN (>)</li>
2022: <li>U+002F SOLIDUS (/)</li>
2023: <li>EOF</li>
2024: </ul><p>...then emit a U+003C LESS-THAN SIGN character token, a U+002F
2025: SOLIDUS character token, and switch to the <a href="#data-state">data state</a>
2026: to process the <a href="#next-input-character">next input character</a>.</p>
2027:
2028: <p>Otherwise, if the <a href="#content-model-flag">content model flag</a> is set to the
2029: PCDATA state, or if the next few characters <em>do</em> match that tag
2030: name, consume the <a href="#next-input-character">next input character</a>:</p>
2031:
2032: <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2033: <dd>Create a new end tag token, set its tag name to the lowercase
2034: version of the input character (add 0x0020 to the character's
2035: code point), then switch to the <a href="#tag-name-state">tag name
2036: state</a>. (Don't emit the token yet; further details will be
2037: filled in before it is emitted.)</dd>
2038:
2039: <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
2040: <dd>Create a new end tag token, set its tag name to the input
2041: character, then switch to the <a href="#tag-name-state">tag name state</a>. (Don't
2042: emit the token yet; further details will be filled in before it
2043: is emitted.)</dd>
2044:
2045: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2046: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
2047: state</a>.</dd>
2048:
2049: <dt>EOF</dt>
2050: <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
2051: character token and a U+002F SOLIDUS character token. Reconsume
2052: the EOF character in the <a href="#data-state">data state</a>.</dd>
2053:
2054: <dt>Anything else</dt>
2055: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
2056: comment state</a>.</dd>
2057:
2058: </dl><h5 id="tag-name-state"><span class="secno">9.2.4.5 </span><dfn>Tag name state</dfn></h5>
2059:
2060: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2061:
2062: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2063: <dt>U+000A LINE FEED (LF)</dt>
2064: <dt>U+000C FORM FEED (FF)</dt>
2065: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2066: <dt>U+0020 SPACE</dt>
2067: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2068:
2069: <dt>U+002F SOLIDUS (/)</dt>
2070: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2071:
2072: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2073: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2074: state</a>.</dd>
2075:
2076: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2077: <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
2078: (add 0x0020 to the character's code point) to the current tag
2079: token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
2080:
2081: <dt>EOF</dt>
2082: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2083: <a href="#data-state">data state</a>.</dd>
2084:
2085: <dt>Anything else</dt>
2086: <dd>Append the <a href="#current-input-character">current input character</a> to the current tag token's
2087: tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
2088:
2089: </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.6 </span><dfn>Before attribute name state</dfn></h5>
2090:
2091: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2092:
2093: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2094: <dt>U+000A LINE FEED (LF)</dt>
2095: <dt>U+000C FORM FEED (FF)</dt>
2096: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2097: <dt>U+0020 SPACE</dt>
2098: <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2099:
2100: <dt>U+002F SOLIDUS (/)</dt>
2101: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2102:
2103: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2104: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2105: state</a>.</dd>
2106:
2107: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2108: <dd>Start a new attribute in the current tag token. Set that
2109: attribute's name to the lowercase version of the <a href="#current-input-character">current input
2110: character</a> (add 0x0020 to the character's code point), and its
2111: value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
2112: state</a>.</dd>
2113:
2114: <dt>U+0022 QUOTATION MARK (")</dt>
2115: <dt>U+0027 APOSTROPHE (')</dt>
2116: <dt>U+003C LESS-THAN SIGN (<)</dt>
2117: <dt>U+003D EQUALS SIGN (=)</dt>
2118: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2119: entry below.</dd>
2120:
2121: <dt>EOF</dt>
2122: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2123: <a href="#data-state">data state</a>.</dd>
2124:
2125: <dt>Anything else</dt>
2126: <dd>Start a new attribute in the current tag token. Set that
2127: attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
2128: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2129: state</a>.</dd>
2130:
2131: </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.7 </span><dfn>Attribute name state</dfn></h5>
2132:
2133: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2134:
2135: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2136: <dt>U+000A LINE FEED (LF)</dt>
2137: <dt>U+000C FORM FEED (FF)</dt>
2138: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2139: <dt>U+0020 SPACE</dt>
2140: <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
2141:
2142: <dt>U+002F SOLIDUS (/)</dt>
2143: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2144:
2145: <dt>U+003D EQUALS SIGN (=)</dt>
2146: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2147:
2148: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2149: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2150: state</a>.</dd>
2151:
2152: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2153: <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
2154: (add 0x0020 to the character's code point) to the current
2155: attribute's name. Stay in the <a href="#attribute-name-state">attribute name
2156: state</a>.</dd>
2157:
2158: <dt>U+0022 QUOTATION MARK (")</dt>
2159: <dt>U+0027 APOSTROPHE (')</dt>
2160: <dt>U+003C LESS-THAN SIGN (<)</dt>
2161: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2162: entry below.</dd>
2163:
2164: <dt>EOF</dt>
2165: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2166: <a href="#data-state">data state</a>.</dd>
2167:
2168: <dt>Anything else</dt>
2169: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2170: name. Stay in the <a href="#attribute-name-state">attribute name state</a>.</dd>
2171:
2172: </dl><p>When the user agent leaves the attribute name state (and before
2173: emitting the tag token, if appropriate), the complete attribute's
2174: name must be compared to the other attributes on the same token;
2175: if there is already an attribute on the token with the exact same
2176: name, then this is a <a href="#parse-error">parse error</a> and the new
2177: attribute must be dropped, along with the value that gets
2178: associated with it (if any).</p>
2179:
2180:
2181: <h5 id="after-attribute-name-state"><span class="secno">9.2.4.8 </span><dfn>After attribute name state</dfn></h5>
2182:
2183: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2184:
2185: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2186: <dt>U+000A LINE FEED (LF)</dt>
2187: <dt>U+000C FORM FEED (FF)</dt>
2188: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2189: <dt>U+0020 SPACE</dt>
2190: <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
2191:
2192: <dt>U+002F SOLIDUS (/)</dt>
2193: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2194:
2195: <dt>U+003D EQUALS SIGN (=)</dt>
2196: <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2197:
2198: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2199: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2200: state</a>.</dd>
2201:
2202: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2203: <dd>Start a new attribute in the current tag token. Set that
2204: attribute's name to the lowercase version of the <a href="#current-input-character">current input character</a>
2205: (add 0x0020 to the character's code point), and its value to
2206: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2207: state</a>.</dd>
2208:
2209: <dt>U+0022 QUOTATION MARK (")</dt>
2210: <dt>U+0027 APOSTROPHE (')</dt>
2211: <dt>U+003C LESS-THAN SIGN (<)</dt>
2212: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2213: entry below.</dd>
2214:
2215: <dt>EOF</dt>
2216: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2217: <a href="#data-state">data state</a>.</dd>
2218:
2219: <dt>Anything else</dt>
2220: <dd>Start a new attribute in the current tag token. Set that
2221: attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
2222: the empty string. Switch to the <a href="#attribute-name-state">attribute name
2223: state</a>.</dd>
2224:
2225: </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.9 </span><dfn>Before attribute value state</dfn></h5>
2226:
2227: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2228:
2229: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2230: <dt>U+000A LINE FEED (LF)</dt>
2231: <dt>U+000C FORM FEED (FF)</dt>
2232: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2233: <dt>U+0020 SPACE</dt>
2234: <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
2235:
2236: <dt>U+0022 QUOTATION MARK (")</dt>
2237: <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
2238:
2239: <dt>U+0026 AMPERSAND (&)</dt>
2240: <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
2241: and reconsume this input character.</dd>
2242:
2243: <dt>U+0027 APOSTROPHE (')</dt>
2244: <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
2245:
2246: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2247: <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
2248: the <a href="#data-state">data state</a>.</dd>
2249:
2250: <dt>U+003C LESS-THAN SIGN (<)</dt>
2251: <dt>U+003D EQUALS SIGN (=)</dt>
2252: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2253: entry below.</dd>
2254:
2255: <dt>EOF</dt>
2256: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2257: <a href="#data-state">data state</a>.</dd>
2258:
2259: <dt>Anything else</dt>
2260: <dd>Append the <a href="#current-input-character">current input character</a> to the current
2261: attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
2262: state</a>.</dd>
2263:
2264: </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.10 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
2265:
2266: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2267:
2268: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
2269: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
2270: state</a>.</dd>
2271:
2272: <dt>U+0026 AMPERSAND (&)</dt>
2273: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
2274: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2275: being U+0022 QUOTATION MARK (").</dd>
2276:
2277: <dt>EOF</dt>
2278: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2279: <a href="#data-state">data state</a>.</dd>
2280:
2281: <dt>Anything else</dt>
2282: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2283: value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted)
2284: state</a>.</dd>
2285:
2286: </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.11 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
2287:
2288: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2289:
2290: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
2291: <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
2292: state</a>.</dd>
2293:
2294: <dt>U+0026 AMPERSAND (&)</dt>
2295: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
2296: state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
2297: being U+0027 APOSTROPHE (').</dd>
2298:
2299: <dt>EOF</dt>
2300: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2301: <a href="#data-state">data state</a>.</dd>
2302:
2303: <dt>Anything else</dt>
2304: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2305: value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted)
2306: state</a>.</dd>
2307:
2308: </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.12 </span><dfn>Attribute value (unquoted) state</dfn></h5>
2309:
2310: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2311:
2312: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2313: <dt>U+000A LINE FEED (LF)</dt>
2314: <dt>U+000C FORM FEED (FF)</dt>
2315: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2316: <dt>U+0020 SPACE</dt>
2317: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2318:
2319: <dt>U+0026 AMPERSAND (&)</dt>
2320: <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
2321: state</a>, with no <a href="#additional-allowed-character">additional allowed
2322: character</a>.</dd>
2323:
2324: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2325: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2326: state</a>.</dd>
2327:
2328: <dt>U+0022 QUOTATION MARK (")</dt>
2329: <dt>U+0027 APOSTROPHE (')</dt>
2330: <dt>U+003C LESS-THAN SIGN (<)</dt>
2331: <dt>U+003D EQUALS SIGN (=)</dt>
2332: <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
2333: entry below.</dd>
2334:
2335: <dt>EOF</dt>
2336: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2337: <a href="#data-state">data state</a>.</dd>
2338:
2339: <dt>Anything else</dt>
2340: <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
2341: value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
2342: state</a>.</dd>
2343:
2344: </dl><h5 id="character-reference-in-attribute-value-state"><span class="secno">9.2.4.13 </span><dfn>Character reference in attribute value state</dfn></h5>
2345:
2346: <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
2347:
2348: <p>If nothing is returned, append a U+0026 AMPERSAND character to
2349: the current attribute's value.</p>
2350:
2351: <p>Otherwise, append the returned character token to the current
2352: attribute's value.</p>
2353:
2354: <p>Finally, switch back to the attribute value state that you were
2355: in when were switched into this state.</p>
2356:
2357:
2358: <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.14 </span><dfn>After attribute value (quoted) state</dfn></h5>
2359:
2360: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2361:
2362: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2363: <dt>U+000A LINE FEED (LF)</dt>
2364: <dt>U+000C FORM FEED (FF)</dt>
2365: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2366: <dt>U+0020 SPACE</dt>
2367: <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2368:
2369: <dt>U+002F SOLIDUS (/)</dt>
2370: <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
2371:
2372: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2373: <dd>Emit the current tag token. Switch to the <a href="#data-state">data
2374: state</a>.</dd>
2375:
2376: <dt>EOF</dt>
2377: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2378: <a href="#data-state">data state</a>.</dd>
2379:
2380: <dt>Anything else</dt>
2381: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
2382: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2383:
2384: </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.15 </span><dfn>Self-closing start tag state</dfn></h5>
2385:
2386: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2387:
2388: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2389: <dd>Set the <i>self-closing flag</i> of the current tag
2390: token. Emit the current tag token. Switch to the <a href="#data-state">data
2391: state</a>.</dd>
2392:
2393: <dt>EOF</dt>
2394: <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
2395: <a href="#data-state">data state</a>.</dd>
2396:
2397: <dt>Anything else</dt>
2398: <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
2399: the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
2400:
2401: </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.16 </span><dfn>Bogus comment state</dfn></h5>
2402:
2403: <p><i>(This can only happen if the <a href="#content-model-flag">content model
2404: flag</a> is set to the PCDATA state.)</i></p>
2405:
2406: <p>Consume every character up to and including the first U+003E
2407: GREATER-THAN SIGN character (>) or the end of the file (EOF),
2408: whichever comes first. Emit a comment token whose data is the
2409: concatenation of all the characters starting from and including
2410: the character that caused the state machine to switch into the
2411: bogus comment state, up to and including the character immediately
2412: before the last consumed character (i.e. up to the character just
2413: before the U+003E or EOF character). (If the comment was started
2414: by the end of the file (EOF), the token is empty.)</p>
2415:
2416: <p>Switch to the <a href="#data-state">data state</a>.</p>
2417:
2418: <p>If the end of the file was reached, reconsume the EOF
2419: character.</p>
2420:
2421:
2422: <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.17 </span><dfn>Markup declaration open state</dfn></h5>
2423:
2424: <p><i>(This can only happen if the <a href="#content-model-flag">content model
2425: flag</a> is set to the PCDATA state.)</i></p>
2426:
2427: <p>If the next two characters are both U+002D HYPHEN-MINUS (-)
2428: characters, consume those two characters, create a comment token
2429: whose data is the empty string, and switch to the <a href="#comment-start-state">comment
2430: start state</a>.</p>
2431:
2432: <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2433: case-insensitive</a> match for the word "DOCTYPE", then consume
2434: those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
2435:
2436: <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
2437: content</a>" and the <a href="#current-node">current node</a> is not an element
2438: in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
2439: an <span>ASCII case-sensitive</span> match for the string "[CDATA["
2440: (the five uppercase letters "CDATA" with a U+005B LEFT SQUARE
2441: BRACKET character before and after), then consume those characters
1.91 mike 2442: and switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1 mike 2443:
2444: <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
2445: <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
2446: consumed, if any, is the first character that will be in the
2447: comment.</p>
2448:
2449:
2450: <h5 id="comment-start-state"><span class="secno">9.2.4.18 </span><dfn>Comment start state</dfn></h5>
2451:
2452: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2453:
2454: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2455: <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
2456:
2457: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2458: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
2459: <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
2460: -->
2461:
2462: <dt>EOF</dt>
2463: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2464: the EOF character in the <a href="#data-state">data state</a>.</dd>
2465:
2466: <dt>Anything else</dt>
2467: <dd>Append the input character to the comment token's
2468: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
2469:
2470: </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.19 </span><dfn>Comment start dash state</dfn></h5>
2471:
2472: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2473:
2474: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2475: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
2476:
2477: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2478: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
2479: the <a href="#data-state">data state</a>.</dd>
2480:
2481: <dt>EOF</dt>
2482: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2483: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2484: in comment end state -->
2485:
2486: <dt>Anything else</dt>
2487: <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
2488: character to the comment token's data. Switch to the
2489: <a href="#comment-state">comment state</a>.</dd>
2490:
2491: </dl><h5 id="comment-state"><span class="secno">9.2.4.20 </span><dfn id="comment">Comment state</dfn></h5>
2492:
2493: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2494:
2495: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2496: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
2497:
2498: <dt>EOF</dt>
2499: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2500: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2501: in comment end state -->
2502:
2503: <dt>Anything else</dt>
2504: <dd>Append the input character to the comment token's data. Stay
2505: in the <a href="#comment-state">comment state</a>.</dd>
2506:
2507: </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.21 </span><dfn>Comment end dash state</dfn></h5>
2508:
2509: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2510:
2511: <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
2512: <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
2513:
2514: <dt>EOF</dt>
2515: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
2516: EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
2517: in comment end state -->
2518:
2519: <dt>Anything else</dt>
2520: <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
2521: character to the comment token's data. Switch to the
2522: <a href="#comment-state">comment state</a>.</dd>
2523:
2524: </dl><h5 id="comment-end-state"><span class="secno">9.2.4.22 </span><dfn>Comment end state</dfn></h5>
2525:
2526: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2527:
2528: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2529: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2530: state</a>.</dd>
2531:
2532: <dt>U+002D HYPHEN-MINUS (-)</dt>
2533: <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
2534: (-) character to the comment token's data. Stay in the
2535: <a href="#comment-end-state">comment end state</a>.</dd>
2536:
2537: <dt>U+0009 CHARACTER TABULATION</dt>
2538: <dt>U+000A LINE FEED (LF)</dt>
2539: <dt>U+000C FORM FEED (FF)</dt>
2540: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2541: <dt>U+0020 SPACE</dt>
2542: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
2543: characters and the input character to the comment token's
2544: data. Switch to the <a href="#comment-end-space-state">comment end space state</a>.</dd>
2545:
2546: <dt>U+0021 EXCLAMATION MARK (!)</dt>
2547: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
2548: state</a>.</dd>
2549:
2550: <dt>EOF</dt>
2551: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2552: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
2553: security reasons: otherwise, hostile user could put a <script> in
2554: a comment e.g. in a blog comment and then DOS the server so that
2555: the end tag isn't read, and then the commented <script> tag would
2556: be treated as live code -->
2557:
2558: <dt>Anything else</dt>
2559: <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
2560: characters and the input character to the comment token's
2561: data. Switch to the <a href="#comment-state">comment state</a>.</dd>
2562:
2563: </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.23 </span><dfn>Comment end bang state</dfn></h5>
2564:
2565: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2566:
2567: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2568: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2569: state</a>.</dd>
2570:
2571: <dt>U+002D HYPHEN-MINUS (-)</dt>
2572: <dd>Append two U+002D HYPHEN-MINUS (-) characters and a U+0021
2573: EXCLAMATION MARK (!) character to the comment token's data. Switch
2574: to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
2575:
2576: <dt>EOF</dt>
2577: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2578: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
2579: comment in comment end state -->
2580:
2581: <dt>Anything else</dt>
2582: <dd>Append two U+002D HYPHEN-MINUS (-) characters, a U+0021
2583: EXCLAMATION MARK (!) character, and the input character to the
2584: comment token's data. Switch to the <a href="#comment-state">comment
2585: state</a>.</dd>
2586:
2587: </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.24 </span><dfn>Comment end space state</dfn></h5>
2588:
2589: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2590:
2591: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2592: <dd>Emit the comment token. Switch to the <a href="#data-state">data
2593: state</a>.</dd>
2594:
2595: <dt>U+002D HYPHEN-MINUS (-)</dt>
2596: <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
2597:
2598: <dt>U+0009 CHARACTER TABULATION</dt>
2599: <dt>U+000A LINE FEED (LF)</dt>
2600: <dt>U+000C FORM FEED (FF)</dt>
2601: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2602: <dt>U+0020 SPACE</dt>
2603: <dd>Append the input character to the comment token's data. Stay in
2604: the <a href="#comment-end-space-state">comment end space state</a>.</dd>
2605:
2606: <dt>EOF</dt>
2607: <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
2608: the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
2609: comment in comment end state -->
2610:
2611: <dt>Anything else</dt>
2612: <dd>Append the input character to the comment token's data. Switch
2613: to the <a href="#comment-state">comment state</a>.</dd>
2614:
2615: </dl><h5 id="doctype-state"><span class="secno">9.2.4.25 </span><dfn>DOCTYPE state</dfn></h5>
2616:
2617: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2618:
2619: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2620: <dt>U+000A LINE FEED (LF)</dt>
2621: <dt>U+000C FORM FEED (FF)</dt>
2622: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2623: <dt>U+0020 SPACE</dt>
2624: <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2625:
2626: <dt>EOF</dt>
2627: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2628: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
2629: the EOF character in the <a href="#data-state">data state</a>.</dd>
2630:
2631: <dt>Anything else</dt>
2632: <dd><a href="#parse-error">Parse error</a>. Reconsume the current
2633: character in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2634:
2635: </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.26 </span><dfn>Before DOCTYPE name state</dfn></h5>
2636:
2637: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2638:
2639: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2640: <dt>U+000A LINE FEED (LF)</dt>
2641: <dt>U+000C FORM FEED (FF)</dt>
2642: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2643: <dt>U+0020 SPACE</dt>
2644: <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
2645:
2646: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2647: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2648: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
2649: the <a href="#data-state">data state</a>.</dd>
2650:
2651: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2652: <dd>Create a new DOCTYPE token. Set the token's name to the
2653: lowercase version of the input character (add 0x0020 to the
2654: character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
2655: state</a>.</dd>
2656:
2657: <dt>EOF</dt>
2658: <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
2659: <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
2660: the EOF character in the <a href="#data-state">data state</a>.</dd>
2661:
2662: <dt>Anything else</dt>
2663: <dd>Create a new DOCTYPE token. Set the token's name to the
2664: <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
2665: state</a>.</dd>
2666:
2667: </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.27 </span><dfn>DOCTYPE name state</dfn></h5>
2668:
2669: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2670:
2671: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2672: <dt>U+000A LINE FEED (LF)</dt>
2673: <dt>U+000C FORM FEED (FF)</dt>
2674: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2675: <dt>U+0020 SPACE</dt>
2676: <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
2677:
2678: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2679: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
2680: state</a>.</dd>
2681:
2682: <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
2683: <dd>Append the lowercase version of the input character (add 0x0020
2684: to the character's code point) to the current DOCTYPE token's
2685: name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
2686:
2687: <dt>EOF</dt>
2688: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2689: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2690: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2691:
2692: <dt>Anything else</dt>
2693: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
2694: token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
2695:
2696: </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.28 </span><dfn>After DOCTYPE name state</dfn></h5>
2697:
2698: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2699:
2700: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2701: <dt>U+000A LINE FEED (LF)</dt>
2702: <dt>U+000C FORM FEED (FF)</dt>
2703: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2704: <dt>U+0020 SPACE</dt>
2705: <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
2706:
2707: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2708: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
2709: state</a>.</dd>
2710:
2711: <dt>EOF</dt>
2712: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2713: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2714: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2715:
2716: <dt>Anything else</dt>
2717: <dd>
2718:
2719: <p>If the six characters starting from the <a href="#current-input-character">current input
2720: character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
2721: for the word "PUBLIC", then consume those characters and switch to
2722: the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</p>
2723:
2724: <p>Otherwise, if the six characters starting from the
2725: <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
2726: case-insensitive</a> match for the word "SYSTEM", then consume
2727: those characters and switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system
2728: identifier state</a>.</p>
2729:
2730: <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
2731: DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
2732: the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
2733:
2734: </dd>
2735:
2736: </dl><h5 id="before-doctype-public-identifier-state"><span class="secno">9.2.4.29 </span><dfn>Before DOCTYPE public identifier state</dfn></h5>
2737:
2738: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2739:
2740: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2741: <dt>U+000A LINE FEED (LF)</dt>
2742: <dt>U+000C FORM FEED (FF)</dt>
2743: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2744: <dt>U+0020 SPACE</dt>
2745: <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
2746:
2747: <dt>U+0022 QUOTATION MARK (")</dt>
2748: <dd>Set the DOCTYPE token's public identifier to the empty string
2749: (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
2750: (double-quoted) state</a>.</dd>
2751:
2752: <dt>U+0027 APOSTROPHE (')</dt>
2753: <dd>Set the DOCTYPE token's public identifier to the empty string
2754: (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
2755: (single-quoted) state</a>.</dd>
2756:
2757: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2758: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2759: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2760: token. Switch to the <a href="#data-state">data state</a>.</dd>
2761:
2762: <dt>EOF</dt>
2763: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2764: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2765: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2766:
2767: <dt>Anything else</dt>
2768: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2769: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
2770: DOCTYPE state</a>.</dd>
2771:
2772: </dl><h5 id="doctype-public-identifier-double-quoted-state"><span class="secno">9.2.4.30 </span><dfn>DOCTYPE public identifier (double-quoted) state</dfn></h5>
2773:
2774: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2775:
2776: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
2777: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
2778:
2779: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2780: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2781: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2782: token. Switch to the <a href="#data-state">data state</a>.</dd>
2783:
2784: <dt>EOF</dt>
2785: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2786: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2787: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2788:
2789: <dt>Anything else</dt>
2790: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
2791: token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
2792: identifier (double-quoted) state</a>.</dd>
2793:
2794: </dl><h5 id="doctype-public-identifier-single-quoted-state"><span class="secno">9.2.4.31 </span><dfn>DOCTYPE public identifier (single-quoted) state</dfn></h5>
2795:
2796: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2797:
2798: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
2799: <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
2800:
2801: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2802: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2803: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2804: token. Switch to the <a href="#data-state">data state</a>.</dd>
2805:
2806: <dt>EOF</dt>
2807: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2808: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2809: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2810:
2811: <dt>Anything else</dt>
2812: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
2813: token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
2814: identifier (single-quoted) state</a>.</dd>
2815:
2816: </dl><h5 id="after-doctype-public-identifier-state"><span class="secno">9.2.4.32 </span><dfn>After DOCTYPE public identifier state</dfn></h5>
2817:
2818: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2819:
2820: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2821: <dt>U+000A LINE FEED (LF)</dt>
2822: <dt>U+000C FORM FEED (FF)</dt>
2823: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2824: <dt>U+0020 SPACE</dt>
2825: <dd>Stay in the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
2826:
2827: <dt>U+0022 QUOTATION MARK (")</dt>
2828: <dd>Set the DOCTYPE token's system identifier to the empty string
2829: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
2830: (double-quoted) state</a>.</dd>
2831:
2832: <dt>U+0027 APOSTROPHE (')</dt>
2833: <dd>Set the DOCTYPE token's system identifier to the empty string
2834: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
2835: (single-quoted) state</a>.</dd>
2836:
2837: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2838: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
2839: state</a>.</dd>
2840:
2841: <dt>EOF</dt>
2842: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2843: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2844: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2845:
2846: <dt>Anything else</dt>
2847: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2848: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
2849: DOCTYPE state</a>.</dd>
2850:
2851: </dl><h5 id="before-doctype-system-identifier-state"><span class="secno">9.2.4.33 </span><dfn>Before DOCTYPE system identifier state</dfn></h5>
2852:
2853: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2854:
2855: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2856: <dt>U+000A LINE FEED (LF)</dt>
2857: <dt>U+000C FORM FEED (FF)</dt>
2858: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2859: <dt>U+0020 SPACE</dt>
2860: <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
2861:
2862: <dt>U+0022 QUOTATION MARK (")</dt>
2863: <dd>Set the DOCTYPE token's system identifier to the empty string
2864: (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
2865: (double-quoted) state</a>.</dd>
2866:
2867: <dt>U+0027 APOSTROPHE (')</dt>
2868: <dd>Set the DOCTYPE token's system identifier to the empty string
2869: (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
2870: (single-quoted) state</a>.</dd>
2871:
2872: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2873: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2874: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2875: token. Switch to the <a href="#data-state">data state</a>.</dd>
2876:
2877: <dt>EOF</dt>
2878: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2879: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2880: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2881:
2882: <dt>Anything else</dt>
2883: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2884: <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
2885: DOCTYPE state</a>.</dd>
2886:
2887: </dl><h5 id="doctype-system-identifier-double-quoted-state"><span class="secno">9.2.4.34 </span><dfn>DOCTYPE system identifier (double-quoted) state</dfn></h5>
2888:
2889: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2890:
2891: <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
2892: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
2893:
2894: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2895: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2896: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2897: token. Switch to the <a href="#data-state">data state</a>.</dd>
2898:
2899: <dt>EOF</dt>
2900: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2901: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2902: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2903:
2904: <dt>Anything else</dt>
2905: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
2906: token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
2907: identifier (double-quoted) state</a>.</dd>
2908:
2909: </dl><h5 id="doctype-system-identifier-single-quoted-state"><span class="secno">9.2.4.35 </span><dfn>DOCTYPE system identifier (single-quoted) state</dfn></h5>
2910:
2911: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2912:
2913: <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
2914: <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
2915:
2916: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2917: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2918: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
2919: token. Switch to the <a href="#data-state">data state</a>.</dd>
2920:
2921: <dt>EOF</dt>
2922: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2923: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2924: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2925:
2926: <dt>Anything else</dt>
2927: <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
2928: token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
2929: identifier (single-quoted) state</a>.</dd>
2930:
2931: </dl><h5 id="after-doctype-system-identifier-state"><span class="secno">9.2.4.36 </span><dfn>After DOCTYPE system identifier state</dfn></h5>
2932:
2933: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2934:
2935: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
2936: <dt>U+000A LINE FEED (LF)</dt>
2937: <dt>U+000C FORM FEED (FF)</dt>
2938: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
2939: <dt>U+0020 SPACE</dt>
2940: <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
2941:
2942: <dt>U+003E GREATER-THAN SIGN (>)</dt>
2943: <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
2944: state</a>.</dd>
2945:
2946: <dt>EOF</dt>
2947: <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
2948: <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
2949: Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
2950:
2951: <dt>Anything else</dt>
2952: <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
2953: state</a>. (This does <em>not</em> set the DOCTYPE token's
2954: <i>force-quirks flag</i> to <i>on</i>.)</dd>
2955:
2956: </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.37 </span><dfn>Bogus DOCTYPE state</dfn></h5>
2957:
2958: <p>Consume the <a href="#next-input-character">next input character</a>:</p>
2959:
2960: <dl class="switch"><dt>U+003E GREATER-THAN SIGN (>)</dt>
2961: <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
2962: state</a>.</dd>
2963:
2964: <dt>EOF</dt>
2965: <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
2966: <a href="#data-state">data state</a>.</dd>
2967:
2968: <dt>Anything else</dt>
2969: <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
2970:
2971: </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.38 </span><dfn>CDATA section state</dfn></h5>
2972:
2973: <p><i>(This can only happen if the <a href="#content-model-flag">content model
1.91 mike 2974: flag</a> is set to the PCDATA state.)</i></p>
1.1 mike 2975:
2976: <p>Consume every character up to the next occurrence of the three
2977: character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
2978: BRACKET U+003E GREATER-THAN SIGN (<code title="">]]></code>), or the
2979: end of the file (EOF), whichever comes first. Emit a series of
2980: character tokens consisting of all the characters consumed except
2981: the matching three character sequence at the end (if one was found
2982: before the end of the file).</p>
2983:
2984: <p>Switch to the <a href="#data-state">data state</a>.</p>
2985:
2986: <p>If the end of the file was reached, reconsume the EOF
2987: character.</p>
2988:
2989:
2990:
2991: <h5 id="tokenizing-character-references"><span class="secno">9.2.4.39 </span>Tokenizing character references</h5>
2992:
2993: <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
2994: reference</dfn>. This definition is used when parsing character
2995: references <a href="#character-reference-data-state" title="character reference data state">in
2996: text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
2997: state">in attributes</a>.</p>
2998:
2999: <p>The behavior depends on the identity of the next character (the
3000: one immediately after the U+0026 AMPERSAND character):</p>
3001:
3002: <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
3003: <dt>U+000A LINE FEED (LF)</dt>
3004: <dt>U+000C FORM FEED (FF)</dt>
3005: <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
3006: <dt>U+0020 SPACE</dt>
3007: <dt>U+003C LESS-THAN SIGN</dt>
3008: <dt>U+0026 AMPERSAND</dt>
3009: <dt>EOF</dt>
3010: <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
3011:
3012: <dd>Not a character reference. No characters are consumed, and
3013: nothing is returned. (This is not an error, either.)</dd>
3014:
3015:
3016: <dt>U+0023 NUMBER SIGN (#)</dt>
3017:
3018: <dd>
3019:
3020: <p>Consume the U+0023 NUMBER SIGN.</p>
3021:
3022: <p>The behavior further depends on the character after the U+0023
3023: NUMBER SIGN:</p>
3024:
3025: <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
3026: <dt>U+0058 LATIN CAPITAL LETTER X</dt>
3027:
3028: <dd>
3029:
3030: <p>Consume the X.</p>
3031:
3032: <p>Follow the steps below, but using the range of characters
3033: U+0030 DIGIT ZERO through to U+0039 DIGIT NINE, U+0061 LATIN
3034: SMALL LETTER A through to U+0066 LATIN SMALL LETTER F, and
3035: U+0041 LATIN CAPITAL LETTER A, through to U+0046 LATIN CAPITAL
3036: LETTER F (in other words, 0-9, A-F, a-f).</p>
3037:
3038: <p>When it comes to interpreting the number, interpret it as a
3039: hexadecimal number.</p>
3040:
3041: </dd>
3042:
3043:
3044: <dt>Anything else</dt>
3045:
3046: <dd>
3047:
3048: <p>Follow the steps below, but using the range of characters
3049: U+0030 DIGIT ZERO through to U+0039 DIGIT NINE (i.e. just
3050: 0-9).</p>
3051:
3052: <p>When it comes to interpreting the number, interpret it as a
3053: decimal number.</p>
3054:
3055: </dd>
3056:
3057: </dl><p>Consume as many characters as match the range of characters
3058: given above.</p>
3059:
3060: <p>If no characters match the range, then don't consume any
3061: characters (and unconsume the U+0023 NUMBER SIGN character and, if
3062: appropriate, the X character). This is a <a href="#parse-error">parse
3063: error</a>; nothing is returned.</p>
3064:
3065: <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
3066: that too. If it isn't, there is a <a href="#parse-error">parse
3067: error</a>.</p>
3068:
3069: <p>If one or more characters match the range, then take them all
3070: and interpret the string of characters as a number (either
3071: hexadecimal or decimal as appropriate).</p>
3072:
3073: <p>If that number is one of the numbers in the first column of the
3074: following table, then this is a <a href="#parse-error">parse error</a>. Find the
3075: row with that number in the first column, and return a character
3076: token for the Unicode character given in the second column of that
3077: row.</p>
3078:
3079: <table><thead><tr><th>Number </th><th colspan="2">Unicode character
3080: </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
3081: </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
3082: </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN ('€')
3083: </td></tr><tr><td>0x81 </td><td>U+0081 </td><td><control>
3084: </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK ('‚')
3085: </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK ('ƒ')
3086: </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK ('„')
3087: </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS ('…')
3088: </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER ('†')
3089: </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER ('‡')
3090: </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT ('ˆ')
3091: </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN ('‰')
3092: </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON ('Š')
3093: </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK ('‹')
3094: </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE ('Œ')
3095: </td></tr><tr><td>0x8D </td><td>U+008D </td><td><control>
3096: </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON ('Ž')
3097: </td></tr><tr><td>0x8F </td><td>U+008F </td><td><control>
3098: </td></tr><tr><td>0x90 </td><td>U+0090 </td><td><control>
3099: </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK ('‘')
3100: </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK ('’')
3101: </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK ('“')
3102: </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK ('”')
3103: </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET ('•')
3104: </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH ('–')
3105: </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH ('—')
3106: </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE ('˜')
3107: </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN ('™')
3108: </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON ('š')
3109: </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK ('›')
3110: </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE ('œ')
3111: </td></tr><tr><td>0x9D </td><td>U+009D </td><td><control>
3112: </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON ('ž')
3113: </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS ('Ÿ')
1.18 mike 3114: </td></tr></tbody></table><p>Otherwise, if the number is greater than 0x10FFFF, then this is
3115: a <a href="#parse-error">parse error</a>. Return a U+FFFD REPLACEMENT
3116: CHARACTER.</p>
3117:
3118: <p>Otherwise, return a character token for the Unicode character
1.1 mike 3119: whose code point is that number.
3120:
3121: <!-- this is the same as the equivalent list in the input stream
3122: section -->
3123: If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
3124: allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
3125: allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
3126: 0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xD800 to
3127: 0xDFFF<!-- surrogates not allowed -->, 0xFDD0 to 0xFDEF, or is one
3128: of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF,
3129: 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF, 0x6FFFE,
3130: 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE, 0x9FFFF,
3131: 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE,
3132: 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF, 0x10FFFE, or
1.18 mike 3133: 0x10FFFF, then this is a <a href="#parse-error">parse error</a>.</p>
1.1 mike 3134:
3135: </dd>
3136:
3137:
3138: <dt>Anything else</dt>
3139:
3140: <dd>
3141:
3142: <p>Consume the maximum number of characters possible, with the
3143: consumed characters matching one of the identifiers in the first
3144: column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
3145: <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
3146:
3147: <p>If no match can be made, then this is a <a href="#parse-error">parse
3148: error</a>. No characters are consumed, and nothing is
3149: returned.</p>
3150:
3151: <p>If the last character matched is not a U+003B SEMICOLON (<code title="">;</code>), there is a <a href="#parse-error">parse error</a>.</p>
3152:
3153: <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
3154: attribute</a>, and the last character matched is not a U+003B
3155: SEMICOLON (<code title="">;</code>), and the next character is in
3156: the range U+0030 DIGIT ZERO to U+0039 DIGIT NINE, U+0041 LATIN
3157: CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z, or U+0061 LATIN
3158: SMALL LETTER A to U+007A LATIN SMALL LETTER Z, then, for
3159: historical reasons, all the characters that were matched after the
3160: U+0026 AMPERSAND (&) must be unconsumed, and nothing is
3161: returned.</p>
3162:
3163: <p>Otherwise, return a character token for the character
3164: corresponding to the character reference name (as given by the
3165: second column of the <a href="named-character-references.html#named-character-references">named character references</a>
3166: table).</p>
3167:
3168: <div class="example">
3169:
3170: <p>If the markup contains <code title="">I'm &notit; I tell
3171: you</code>, the character reference is parsed as "not", as in,
3172: <code title="">I'm ¬it; I tell you</code>. But if the markup
3173: was <code title="">I'm &notin; I tell you</code>, the
3174: character reference would be parsed as "notin;", resulting in
3175: <code title="">I'm ∉ I tell you</code>.</p>
3176:
3177: </div>
3178:
3179: </dd>
3180:
3181: </dl><h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4>
3182:
3183: <p>The input to the tree construction stage is a sequence of tokens
3184: from the <a href="#tokenization">tokenization</a> stage. The tree construction
3185: stage is associated with a DOM <code>Document</code> object when a
3186: parser is created. The "output" of this stage consists of
3187: dynamically modifying or extending that document's DOM tree.</p>
3188:
3189: <p>This specification does not define when an interactive user agent
3190: has to render the <code>Document</code> so that it is available to
3191: the user, or when it has to begin accepting user input.</p>
3192:
3193: <p>As each token is emitted from the tokenizer, the user agent must
3194: process the token according to the rules given in the section
3195: corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
3196:
3197: <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
3198: character</dfn> into a node, if that node has a child immediately
3199: before where the character is to be inserted, and that child is a
3200: <code>Text</code> node, and that <code>Text</code> node was the last
3201: node that the parser inserted into the document, then the character
3202: must be appended to that <code>Text</code> node; otherwise, a new
3203: <code>Text</code> node whose data is just that character must be
3204: inserted in the appropriate place.</p>
3205:
3206: <div class="example">
3207:
3208: <p>Here are some sample inputs to the parser and the corresponding
3209: number of text nodes that they result in, assuming a user agent
3210: that executes scripts.</p>
3211:
3212: <table><thead><tr><th>Input </th><th>Number of text nodes
3213: </th></tr></thead><tbody><tr><td><pre>A<script>
3214: var script = document.getElementsByTagName('script')[0];
3215: document.body.removeChild(script);
3216: </script>B</pre>
3217: </td><td>Two adjacent text nodes in the document, containing "A" and "B".
3218: </td></tr><tr><td><pre>A<script>
3219: var text = document.createTextNode('B');
3220: document.body.appendChild(text);
3221: </script>C</pre>
3222: </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
3223: </td></tr><tr><td><pre>A<script>
3224: var text = document.getElementsByTagName('script')[0].firstChild;
3225: text.data = 'B';
3226: document.body.appendChild(text);
3227: </script>B</pre>
3228: </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
3229: </td></tr><tr><td><pre>A<table>B<tr>C</tr>C</table></pre>
3230: </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>.)
3231: </td></tr><tr><td><pre>A<table><tr> B</tr> B</table></pre>
3232: </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>.)
3233: </td></tr><tr><td><pre>A<table><tr> B</tr> </em>C</table></pre>
3234: </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.)
3235: </td></tr></tbody></table></div>
3236:
3237: <p id="mutation-during-parsing">DOM mutation events must not fire
3238: for changes caused by the UA parsing the document. (Conceptually,
3239: the parser is not mutating the DOM, it is constructing it.) This
1.104 mike 3240: includes the parsing of any content inserted using <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code> and <code title="dom-document-writeln"><a href="dom.html#dom-document-writeln">document.writeln()</a></code> calls. <a href="references.html#refsDOMEVENTS">[DOMEVENTS]</a></p>
1.1 mike 3241:
3242: <p class="note">Not all of the tag names mentioned below are
3243: conformant tag names in this specification; many are included to
3244: handle legacy content. They still form part of the algorithm that
3245: implementations are required to implement to claim conformance.</p>
3246:
3247: <p class="note">The algorithm described below places no limit on the
3248: depth of the DOM tree generated, or on the length of tag names,
3249: attribute names, attribute values, text nodes, etc. While
3250: implementors are encouraged to avoid arbitrary limits, it is
3251: recognized that <a href="infrastructure.html#hardwareLimitations">practical
3252: concerns</a> will likely force user agents to impose nesting
3253: depths.</p>
3254:
3255:
3256: <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5>
3257:
3258: <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
3259: element for the token">create an element for a token</dfn> in a
3260: particular namespace, the UA must create a node implementing the
3261: interface appropriate for the element type corresponding to the tag
3262: name of the token in the given namespace (as given in the
3263: specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
3264: element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
3265: defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
3266: the tag name being the name of that element, with the node being in
3267: the given namespace, and with the attributes on the node being those
3268: given in the given token.</p>
3269:
3270: <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
3271: namespace</a> that is not defined in this specification is
1.44 mike 3272: <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1 mike 3273: interface is not defined by that namespace's specification must use
3274: the interface <code>Element</code>.</p>
3275:
3276: <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
3277: created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
3278: invoked once the attributes are set. (This initializes the element's
3279: <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
3280: attributes.)</p>
3281:
3282: <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
3283: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
3284: for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
3285: append this node to the <a href="#current-node">current node</a>, and push it onto
3286: the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
3287: <a href="#current-node">current node</a>.</p>
3288:
3289: <p>The steps below may also require that the UA insert an HTML
3290: element in a particular place, in which case the UA must follow the
3291: same steps except that it must insert or append the new node in the
3292: location specified instead of appending it to the <a href="#current-node">current
3293: node</a>. (This happens in particular during the parsing of
3294: tables with invalid content.)</p>
3295:
3296: <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
3297: algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
3298: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
3299: 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
3300: <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
3301: created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
3302: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
3303: inserting it wherever it is to be inserted.</p>
3304:
3305: <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
3306: element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
3307: for the token</a> in the given namespace, and then append this
3308: node to the <a href="#current-node">current node</a>, and push it onto the
3309: <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
3310: <a href="#current-node">current node</a>. If the newly created element has an <code title="">xmlns</code> attribute in the <a href="#xmlns-namespace">XMLNS namespace</a>
3311: whose value is not exactly the same as the element's namespace, that
3312: is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
3313: element has an <code title="">xmlns:xlink</code> attribute in the
3314: <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
3315: Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
3316:
3317: <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
3318: attributes</dfn> for a token, then, if the token has an attribute
3319: named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
3320:
3321: <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
3322: attributes</dfn> for a token, then, for each attribute on the token
3323: whose attribute name is one of the ones in the first column of the
3324: following table, change the attribute's name to the name given in
3325: the corresponding cell in the second column. (This fixes the case of
3326: SVG attributes that are not all lowercase.)</p>
3327:
3328: <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
3329: </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
3330: </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
3331: </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
3332: </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
3333: </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
3334: </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
3335: </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
3336: </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
3337: </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
3338: </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
3339: </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
3340: </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
3341: </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
3342: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
3343: </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
3344: </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
3345: </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
3346: </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
3347: </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
3348: </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
3349: </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
3350: </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
3351: </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
3352: </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
3353: </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
3354: </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
3355: </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
3356: </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
3357: </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
3358: </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
3359: </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
3360: </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
3361: </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
3362: </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
3363: </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
3364: </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
3365: </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
3366: </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
3367: </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
3368: </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
3369: </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
3370: </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
3371: </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
3372: </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
3373: </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
3374: </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
3375: </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
3376: </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
3377: </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
3378: </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
3379: </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
3380: </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
3381: </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
3382: </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
3383: </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
3384: </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
3385: </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
3386: </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
3387: </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
3388: </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
3389: </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
3390: </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
3391: </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
3392: foreign attributes</dfn> for a token, then, if any of the attributes
3393: on the token match the strings given in the first column of the
3394: following table, let the attribute be a namespaced attribute, with
3395: the prefix being the string given in the corresponding cell in the
3396: second column, the local name being the string given in the
3397: corresponding cell in the third column, and the namespace being the
3398: namespace given in the corresponding cell in the fourth
3399: column. (This fixes the use of namespaced attributes, in particular
3400: <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
3401: the <span>XML namespace</span></a>.)</p>
3402:
3403: <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
3404: </th></tr></thead><tbody><tr><td> <code title="">xlink:actuate</code> </td><td> <code title="">xlink</code> </td><td> <code title="">actuate</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3405: </td></tr><tr><td> <code title="">xlink:arcrole</code> </td><td> <code title="">xlink</code> </td><td> <code title="">arcrole</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3406: </td></tr><tr><td> <code title="">xlink:href</code> </td><td> <code title="">xlink</code> </td><td> <code title="">href</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3407: </td></tr><tr><td> <code title="">xlink:role</code> </td><td> <code title="">xlink</code> </td><td> <code title="">role</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3408: </td></tr><tr><td> <code title="">xlink:show</code> </td><td> <code title="">xlink</code> </td><td> <code title="">show</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3409: </td></tr><tr><td> <code title="">xlink:title</code> </td><td> <code title="">xlink</code> </td><td> <code title="">title</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3410: </td></tr><tr><td> <code title="">xlink:type</code> </td><td> <code title="">xlink</code> </td><td> <code title="">type</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
3411: </td></tr><tr><td> <code title="">xml:base</code> </td><td> <code title="">xml</code> </td><td> <code title="">base</code> </td><td> <a href="#xml-namespace">XML namespace</a> <!-- attr-xml-base -->
3412: </td></tr><tr><td> <code title="">xml:lang</code> </td><td> <code title="">xml</code> </td><td> <code title="">lang</code> </td><td> <a href="#xml-namespace">XML namespace</a>
3413: </td></tr><tr><td> <code title="">xml:space</code> </td><td> <code title="">xml</code> </td><td> <code title="">space</code> </td><td> <a href="#xml-namespace">XML namespace</a>
3414: </td></tr><tr><td> <code title="">xmlns</code> </td><td> (none) </td><td> <code title="">xmlns</code> </td><td> <a href="#xmlns-namespace">XMLNS namespace</a>
3415: </td></tr><tr><td> <code title="">xmlns:xlink</code> </td><td> <code title="">xmlns</code> </td><td> <code title="">xlink</code> </td><td> <a href="#xmlns-namespace">XMLNS namespace</a>
1.91 mike 3416: </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 3417: <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
3418: following steps. These algorithms are always invoked in response to
3419: a start tag token.</p>
3420:
3421: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
3422:
1.91 mike 3423: <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
3424: text element parsing algorithm</a>, switch the tokenizer's
3425: <a href="#content-model-flag">content model flag</a> to the RAWTEXT state; otherwise the
1.1 mike 3426: algorithm invoked was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing
3427: algorithm</a>, switch the tokenizer's <a href="#content-model-flag">content model
3428: flag</a> to the RCDATA state.</p></li>
3429:
3430: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
3431: <a href="#insertion-mode">insertion mode</a>.</p>
3432:
1.91 mike 3433: </li><li><p>Then, switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
3434: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 3435:
3436: </ol><h5 id="closing-elements-that-have-implied-end-tags"><span class="secno">9.2.5.2 </span>Closing elements that have implied end tags</h5>
3437:
3438: <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
3439: tags</dfn>, then, while the <a href="#current-node">current node</a> is a
3440: <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
3441: <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
3442: <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
3443: <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
3444: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
3445: elements</a>.</p>
3446:
3447: <p>If a step requires the UA to generate implied end tags but lists
3448: an element to exclude from the process, then the UA must perform the
3449: above steps as if that element was not in the above list.</p>
3450:
3451:
3452: <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5>
3453:
3454: <p>Foster parenting happens when content is misnested in tables.</p>
3455:
3456: <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
3457: parent">foster parented</dfn>, the node <var title="">node</var>
3458: must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
3459:
3460: <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
3461: 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
3462: elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
3463: such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
3464: the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
3465: case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
3466: element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
3467: <code><a href="semantics.html#the-html-element">html</a></code> element). Otherwise, if there is a
3468: <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
3469: elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
3470: <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
3471: node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
3472: the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
3473: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
3474:
3475: <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
3476: 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
3477: elements</a>, then <var title="">node</var> must be inserted
3478: immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
3479: the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
3480: element</a></i>; otherwise, <var title="">node</var> must be
3481: <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
3482:
3483:
3484:
3485: <h5 id="the-initial-insertion-mode"><span class="secno">9.2.5.4 </span>The "<dfn title="insertion mode: initial">initial</dfn>" insertion mode</h5>
3486:
3487: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
3488: mode: initial">initial</a>", tokens must be handled as follows:</p>
3489:
3490: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
3491: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3492: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3493: <dd>
3494: <p>Ignore the token.</p>
3495: </dd>
3496:
3497: <dt>A comment token</dt>
3498: <dd>
3499: <p>Append a <code>Comment</code> node to the <code>Document</code>
3500: object with the <code title="">data</code> attribute set to the
3501: data given in the comment token.</p>
3502: </dd>
3503:
3504: <dt>A DOCTYPE token</dt>
3505: <dd>
3506:
3507: <p>If the DOCTYPE token's name is not a
3508: <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
3509: missing, or the token's system identifier is neither missing nor a
3510: <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
3511: "<code>about:legacy-compat</code>", and none of the sets of
3512: conditions in the following list are matched, then there is a
3513: <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
3514: following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
3515: permitted DOCTYPE</dfn>.</p>
3516:
3517: <ul><!-- only things that trigger no-quirks mode and were valid in
3518: some other spec are allowed in this list --><li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3519: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3520: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD HTML 4.0//EN</code>", and the
3521: token's system identifier is either missing or the
3522: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
3523:
3524: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3525: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3526: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD HTML 4.01//EN</code>", and the
3527: token's system identifier is either missing or the
3528: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
3529:
3530: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3531: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3532: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD XHTML 1.0 Strict//EN</code>",
3533: and the token's system identifier is the
3534: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
3535:
3536: <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98 mike 3537: case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1 mike 3538: <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD XHTML 1.1//EN</code>", and the
3539: token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
3540: string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
3541:
3542: </ul><p>Conformance checkers may, based on the values (including
3543: presence or lack thereof) of the DOCTYPE token's name, public
3544: identifier, or system identifier, switch to a conformance checking
3545: mode for another language (e.g. based on the DOCTYPE token a
3546: conformance checker could recognize that the document is an
3547: HTML 4-era document, and defer to an HTML 4 conformance
3548: checker.)</p>
3549:
3550: <p>Append a <code>DocumentType</code> node to the
3551: <code>Document</code> node, with the <code title="">name</code>
3552: attribute set to the name given in the DOCTYPE token, or the empty
3553: string if the name was missing; the <code title="">publicId</code>
3554: attribute set to the public identifier given in the DOCTYPE token,
3555: or the empty string if the public identifier was missing; the
3556: <code title="">systemId</code> attribute set to the system
3557: identifier given in the DOCTYPE token, or the empty string if the
3558: system identifier was missing; and the other attributes specific
3559: to <code>DocumentType</code> objects set to null and empty lists
3560: as appropriate. Associate the <code>DocumentType</code> node with
3561: the <code>Document</code> object so that it is returned as the
3562: value of the <code title="">doctype</code> attribute of the
3563: <code>Document</code> object.</p>
3564:
3565: <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
3566: one of the conditions in the following list, then set the
3567: <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
3568:
3569: <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
3570: <li> The name is set to anything other than "<code title="">HTML</code>". </li>
3571: <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
3572: <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
3573: <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
3574: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
3575: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
3576: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
3577: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
3578: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
3579: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
3580: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
3581: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
3582: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
3583: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
3584: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
3585: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
3586: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
3587: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
3588: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
3589: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
3590: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
3591: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
3592: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
3593: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
3594: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
3595: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
3596: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
3597: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
3598: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
3599: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
3600: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
3601: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
3602: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
3603: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
3604: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
3605: <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
3606: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
3607: <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
3608: <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
3609: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
3610: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
3611: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
3612: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
3613: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
3614: <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
3615: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
3616: <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
3617: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
3618: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
3619: <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
3620: <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
3621: <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
3622: <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
3623: <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
3624: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
3625: <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
3626: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
3627: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
3628: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
3629: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
3630: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
3631: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
3632: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
3633: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
3634: <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
3635: <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
3636: <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
3637: <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
3638: <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
3639: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
3640: <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
3641: <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
3642: <li> The public identifier is set to: "<code title="">HTML</code>" </li>
3643: <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
3644: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
3645: <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
3646: </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
3647: in the following list, then set the <code>Document</code> to
3648: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
3649:
3650: <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
3651: <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
3652: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
3653: <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
3654: </ul><p>The name, system identifier, and public identifier strings must
3655: be compared to the values given in the lists above in an
3656: <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
3657: whose value is the empty string is not considered missing for the
3658: purposes of the conditions above.</p>
3659:
3660: <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>
3661:
3662: </dd>
3663:
3664: <dt>Anything else</dt>
3665: <dd>
3666:
3667: <p><a href="#parse-error">Parse error</a>.</p>
3668:
3669: <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
3670:
3671: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>", then
3672: reprocess the current token.</p>
3673:
3674: </dd>
3675:
3676: </dl><h5 id="the-before-html-insertion-mode"><span class="secno">9.2.5.5 </span>The "<dfn title="insertion mode: before html">before html</dfn>" insertion mode</h5>
3677:
3678: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
3679: mode: before html">before html</a>", tokens must be handled as follows:</p>
3680:
3681: <dl class="switch"><dt>A DOCTYPE token</dt>
3682: <dd>
3683: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3684: </dd>
3685:
3686: <dt>A comment token</dt>
3687: <dd>
3688: <p>Append a <code>Comment</code> node to the <code>Document</code>
3689: object with the <code title="">data</code> attribute set to the
3690: data given in the comment token.</p>
3691: </dd>
3692:
3693: <dt>A character token that is one of U+0009 CHARACTER
3694: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3695: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3696: <dd>
3697: <p>Ignore the token.</p>
3698: </dd>
3699:
3700: <dt>A start tag whose tag name is "html"</dt>
3701: <dd>
3702:
3703: <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
3704: namespace</a>. Append it to the <code>Document</code>
3705: object. Put this element in the <a href="#stack-of-open-elements">stack of open
3706: elements</a>.</p>
3707:
3708: <p id="parser-appcache">If the <code>Document</code> is being
3709: loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
3710: <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
3711: has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
3712: then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
3713: attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
3714: 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 3715: algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
3716: any <a href="infrastructure.html#url-fragment" title="url-fragment"><fragment></a> component
3717: removed; otherwise, if there is no such attribute or resolving it
3718: fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
3719: cache selection algorithm</a> with no manifest. The algorithm
3720: must be passed the <code>Document</code> object.</p>
1.1 mike 3721:
3722: <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>
3723:
3724: </dd>
3725:
3726: <dt>Anything else</dt>
3727: <dd>
3728:
3729: <p>Create an <code><a href="semantics.html#the-html-element">html</a></code> element. Append it to the
3730: <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
3731: of open elements</a>.</p>
3732:
3733: <p>If the <code>Document</code> is being loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a <a href="browsers.html#browsing-context">browsing
3734: context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
3735: algorithm</a> with no manifest, passing it the
3736: <code>Document</code> object.</p>
3737:
3738: <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
3739: reprocess the current token.</p>
3740:
3741: <p class="XXX">Should probably make end tags be ignored, so
3742: that "</head><!-- --><html>" puts the comment before the
3743: root node (or should we?)</p>
3744:
3745: </dd>
3746:
3747: </dl><p>The root element can end up being removed from the
3748: <code>Document</code> object, e.g. by scripts; nothing in particular
3749: happens in such cases, content continues being appended to the nodes
3750: as described in the next section.</p>
3751:
3752:
3753: <h5 id="the-before-head-insertion-mode"><span class="secno">9.2.5.6 </span>The "<dfn title="insertion mode: before head">before head</dfn>" insertion mode</h5>
3754:
3755: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
3756: mode: before head">before head</a>", tokens must be handled as follows:</p>
3757:
3758: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
3759: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3760: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3761: <dd>
3762: <p>Ignore the token.</p> <!-- :-( -->
3763: </dd>
3764:
3765: <dt>A comment token</dt>
3766: <dd>
3767: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
3768: node</a> with the <code title="">data</code> attribute set to
3769: the data given in the comment token.</p>
3770: </dd>
3771:
3772: <dt>A DOCTYPE token</dt>
3773: <dd>
3774: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3775: </dd>
3776:
3777: <dt>A start tag whose tag name is "html"</dt>
3778: <dd>
3779: <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
3780: mode</a>.</p>
3781: </dd>
3782:
3783: <dt>A start tag whose tag name is "head"</dt>
3784: <dd>
3785:
3786: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
3787:
3788: <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
3789: to the newly created <code><a href="semantics.html#the-head-element">head</a></code> element.</p>
3790:
3791: <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>
3792:
3793: </dd>
3794:
3795: <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
3796: <dd>
3797:
3798: <p>Act as if a start tag token with the tag name "head" and no
3799: attributes had been seen, then reprocess the current token.</p>
3800:
3801: </dd>
3802:
3803: <dt>Any other end tag</dt>
3804: <dd>
3805:
3806: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3807:
3808: </dd>
3809:
3810: <dt>Anything else</dt>
3811: <dd>
3812:
3813: <p>Act as if a start tag token with the tag name "head" and no
3814: attributes had been seen, then reprocess the current
3815: token.</p>
3816:
3817: </dd>
3818:
3819: </dl><h5 id="parsing-main-inhead"><span class="secno">9.2.5.7 </span>The "<dfn title="insertion mode: in head">in head</dfn>" insertion mode</h5>
3820:
3821: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
3822: mode: in head">in head</a>", tokens must be handled as follows:</p>
3823:
3824: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
3825: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
3826: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
3827: <dd>
3828: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
3829: the <a href="#current-node">current node</a>.</p>
3830: </dd>
3831:
3832: <dt>A comment token</dt>
3833: <dd>
3834: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
3835: node</a> with the <code title="">data</code> attribute set to
3836: the data given in the comment token.</p>
3837: </dd>
3838:
3839: <dt>A DOCTYPE token</dt>
3840: <dd>
3841: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3842: </dd>
3843:
3844: <dt>A start tag whose tag name is "html"</dt>
3845: <dd>
3846: <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
3847: mode</a>.</p>
3848: </dd>
3849:
3850: <dt>A start tag whose tag name is one of: "base", "command",
3851: "link"</dt>
3852: <dd>
3853:
3854: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
3855: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
3856: elements</a>.</p>
3857:
3858: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
3859: token's <i>self-closing flag</i></a>, if it is set.</p>
3860:
3861: </dd>
3862:
3863: <dt>A start tag whose tag name is "meta"</dt>
3864: <dd>
3865:
3866: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
3867: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
3868: elements</a>.</p>
3869:
3870: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
3871: token's <i>self-closing flag</i></a>, if it is set.</p>
3872:
3873: <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
3874: value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
3875: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
3876: encoding</a> to the encoding given by the value of the
3877: <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
3878:
3879: <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
3880: applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
3881: Content-Type</a> to its value returns a supported encoding
3882: <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
3883: currently <i>tentative</i>, then <a href="#change-the-encoding">change the
3884: encoding</a> to the encoding <var title="">encoding</var>.</p>
3885:
3886: </dd>
3887:
3888: <dt>A start tag whose tag name is "title"</dt>
3889: <dd>
3890: <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
3891: </dd>
3892:
3893: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
3894: <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
3895: <dd>
1.91 mike 3896: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 3897: </dd>
3898:
3899: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
3900: <dd>
3901:
3902: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
3903:
3904: <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
3905: noscript</a>".</p>
3906:
3907: </dd>
3908:
3909: <dt id="scriptTag">A start tag whose tag name is "script"</dt>
3910: <dd>
3911:
3912: <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
3913: <a href="#html-namespace-0">HTML namespace</a>.</p></li>
3914:
3915: <li>
3916:
3917: <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
3918:
3919: <p class="note">This ensures that, if the script is external,
3920: any <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code>
3921: calls in the script will execute in-line, instead of blowing the
3922: document away, as would happen in most other cases. It also
3923: prevents the script from executing until the end tag is
3924: seen.</p>
3925:
3926: </li>
3927:
3928: <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
3929: fragment parsing algorithm</a>, then mark the
3930: <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
3931: executed"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
3932:
3933: <li><p>Append the new element to the <a href="#current-node">current node</a>
3934: and push it onto the <a href="#stack-of-open-elements">stack of open
3935: elements</a>.</p></li>
3936:
3937: <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
1.91 mike 3938: the RAWTEXT state.</p></li>
1.1 mike 3939:
3940: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
3941: <a href="#insertion-mode">insertion mode</a>.</p>
3942:
1.91 mike 3943: </li><li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
3944: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 3945:
3946: </ol></dd>
3947:
3948: <dt>An end tag whose tag name is "head"</dt>
3949: <dd>
3950:
3951: <p>Pop the <a href="#current-node">current node</a> (which will be the
3952: <code><a href="semantics.html#the-head-element">head</a></code> element) off the <a href="#stack-of-open-elements">stack of open
3953: elements</a>.</p>
3954:
3955: <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>
3956:
3957: </dd>
3958:
3959: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
3960: <dd>
3961: <p>Act as described in the "anything else" entry below.</p>
3962: </dd>
3963:
3964: <dt>A start tag whose tag name is "head"</dt>
3965: <dt>Any other end tag</dt>
3966: <dd>
3967: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3968: </dd>
3969:
3970: <dt>Anything else</dt>
3971: <dd>
3972:
3973: <!-- can't get here with an EOF and a fragment case -->
3974:
3975: <p>Act as if an end tag token with the tag name "head" had
3976: been seen, and reprocess the current token.</p>
3977:
3978: <p class="XXX">In certain UAs, <a href="https://bugzilla.mozilla.org/attachment.cgi?id=180157&action=view">some
3979: elements</a> don't trigger the "in body" mode straight away,
3980: but instead get put into the head. Do we want to copy
3981: that?</p>
3982:
3983: </dd>
3984:
3985: </dl><h5 id="parsing-main-inheadnoscript"><span class="secno">9.2.5.8 </span>The "<dfn title="insertion mode: in head noscript">in head noscript</dfn>" insertion mode</h5>
3986:
3987: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
3988: mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
3989:
3990: <dl class="switch"><dt>A DOCTYPE token</dt>
3991: <dd>
3992: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
3993: </dd>
3994:
3995: <dt>A start tag whose tag name is "html"</dt>
3996: <dd>
3997: <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
3998: mode</a>.</p>
3999: </dd>
4000:
4001: <dt>An end tag whose tag name is "noscript"</dt>
4002: <dd>
4003:
4004: <p>Pop the <a href="#current-node">current node</a> (which will be a
4005: <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
4006: elements</a>; the new <a href="#current-node">current node</a> will be a
4007: <code><a href="semantics.html#the-head-element">head</a></code> element.</p>
4008:
4009: <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>
4010:
4011: </dd>
4012:
4013: <dt>A character token that is one of U+0009 CHARACTER
4014: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4015: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4016: <dt>A comment token</dt>
4017: <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
4018: <dd>
4019: <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
4020: mode</a>.</p>
4021: </dd>
4022:
4023: <dt>An end tag whose tag name is "br"</dt>
4024: <dd>
4025: <p>Act as described in the "anything else" entry below.</p>
4026: </dd>
4027:
4028: <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
4029: <dt>Any other end tag</dt>
4030: <dd>
4031: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4032: </dd>
4033:
4034: <dt>Anything else</dt>
4035: <dd>
4036:
4037: <!-- can't get here with an EOF and a fragment case -->
4038:
4039: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
4040: name "noscript" had been seen and reprocess the current
4041: token.</p>
4042:
4043: </dd>
4044:
4045: </dl><h5 id="the-after-head-insertion-mode"><span class="secno">9.2.5.9 </span>The "<dfn title="insertion mode: after head">after head</dfn>" insertion mode</h5>
4046:
4047: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
4048: mode: after head">after head</a>", tokens must be handled as follows:</p>
4049:
4050: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
4051: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
4052: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
4053: <dd>
4054: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
4055: the <a href="#current-node">current node</a>.</p>
4056: </dd>
4057:
4058: <dt>A comment token</dt>
4059: <dd>
4060: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4061: node</a> with the <code title="">data</code> attribute set to
4062: the data given in the comment token.</p>
4063: </dd>
4064:
4065: <dt>A DOCTYPE token</dt>
4066: <dd>
4067: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4068: </dd>
4069:
4070: <dt>A start tag whose tag name is "html"</dt>
4071: <dd>
4072: <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
4073: mode</a>.</p>
4074: </dd>
4075:
4076: <dt>A start tag whose tag name is "body"</dt>
4077: <dd>
4078:
4079: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4080:
4081: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4082:
4083: <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>
4084:
4085: </dd>
4086:
4087: <dt>A start tag whose tag name is "frameset"</dt>
4088: <dd>
4089:
4090: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4091:
4092: <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>
4093:
4094: </dd>
4095:
4096: <dt>A start tag token whose tag name is one of: "base", "link",
4097: "meta", "noframes", "script", "style", "title"</dt>
4098: <dd>
4099:
4100: <p><a href="#parse-error">Parse error</a>.</p>
4101:
4102: <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
4103: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
4104:
4105: <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
4106: mode</a>.</p>
4107:
4108: <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
4109: of open elements</a>.</p>
4110:
4111: <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
4112: pointer</a> cannot be null at this point.</p>
4113:
4114: </dd>
4115:
4116: <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
4117: <dd>
4118: <p>Act as described in the "anything else" entry below.</p>
4119: </dd>
4120:
4121: <dt>A start tag whose tag name is "head"</dt>
4122: <dt>Any other end tag</dt>
4123: <dd>
4124: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4125: </dd>
4126:
4127: <dt>Anything else</dt>
4128: <dd>
4129: <p>Act as if a start tag token with the tag name "body" and no
4130: attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
4131: flag</a> back to "ok", and then reprocess the current
4132: token.</p>
4133: </dd>
4134:
4135: </dl><h5 id="parsing-main-inbody"><span class="secno">9.2.5.10 </span>The "<dfn title="insertion mode: in body">in body</dfn>" insertion mode</h5>
4136:
4137: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
4138: mode: in body">in body</a>", tokens must be handled as follows:</p>
4139:
4140: <dl class="switch"><dt>A character token</dt>
4141: <dd>
4142:
4143: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4144: any.</p>
4145:
4146: <p><a href="#insert-a-character" title="insert a character">Insert the token's
4147: character</a> into the <a href="#current-node">current node</a>.</p>
4148:
4149: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
4150: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
4151: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
4152: flag</a> to "not ok".</p>
4153:
4154: </dd>
4155:
4156: <dt>A comment token</dt>
4157: <dd>
4158: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
4159: node</a> with the <code title="">data</code> attribute set to
4160: the data given in the comment token.</p>
4161: </dd>
4162:
4163: <dt>A DOCTYPE token</dt>
4164: <dd>
4165: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
4166: </dd>
4167:
4168: <dt>A start tag whose tag name is "html"</dt>
4169: <dd>
4170: <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
4171: check to see if the attribute is already present on the top
4172: element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
4173: add the attribute and its corresponding value to that element.</p>
4174: </dd>
4175:
4176: <dt>A start tag token whose tag name is one of: "base", "command",
4177: "link", "meta", "noframes", "script", "style", "title"</dt>
4178: <dd>
4179: <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
4180: mode</a>.</p>
4181: </dd>
4182:
4183: <dt>A start tag whose tag name is "body"</dt>
4184: <dd>
4185:
4186: <p><a href="#parse-error">Parse error</a>.</p>
4187:
4188: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
4189: elements</a> is not a <code><a href="semantics.html#the-body-element">body</a></code> element, or, if the
4190: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
4191: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
4192:
4193: <p>Otherwise, for each attribute on the token, check to see if
4194: the attribute is already present on the <code><a href="semantics.html#the-body-element">body</a></code>
4195: element (the second element) on the <a href="#stack-of-open-elements">stack of open
4196: elements</a>. If it is not, add the attribute and its
4197: corresponding value to that element.</p>
4198:
4199: </dd>
4200:
4201: <dt>A start tag whose tag name is "frameset"</dt>
4202: <dd>
4203:
4204: <p><a href="#parse-error">Parse error</a>.</p>
4205:
4206: <p>If the second element on the <a href="#stack-of-open-elements">stack of open
4207: elements</a> is not a <code><a href="semantics.html#the-body-element">body</a></code> element, or, if the
4208: <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
4209: then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
4210:
4211: <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
4212: the token.</p>
4213:
4214: <p>Otherwise, run the following steps:</p>
4215:
4216: <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
4217: elements</a> from its parent node, if it has one.</p></li>
4218:
4219: <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
4220: open elements</a>, from the <a href="#current-node">current node</a> up to,
4221: but not including, the root <code><a href="semantics.html#the-html-element">html</a></code> element.</p>
4222:
4223: </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
4224: token.</p></li>
4225:
4226: <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>
4227:
4228: </li></ol></dd>
4229:
4230: <dt>An end-of-file token</dt>
4231: <dd>
4232:
4233: <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
4234: 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>
4235: 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
4236: <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
4237: <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
4238: <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
4239: <code><a href="semantics.html#the-body-element">body</a></code> element, or the <code><a href="semantics.html#the-html-element">html</a></code> element, then
4240: this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
4241: fragment cases) -->
4242:
4243: <p><a href="#stop-parsing">Stop parsing</a>.</p>
4244:
4245: </dd>
4246:
4247: <dt>An end tag whose tag name is "body"</dt>
4248: <dd>
4249:
4250: <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
4251: in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
4252: token.</p>
4253:
4254: <!-- if we get here, the insertion mode here is forcibly "in
4255: body". -->
4256:
4257: <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
4258: elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
4259: <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
4260: <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
4261: <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
4262: <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
4263: <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
4264: <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
4265: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the <code><a href="semantics.html#the-body-element">body</a></code> element, or the
4266: <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
4267: error</a>.</p> <!-- (some of those are fragment cases, e.g. for
4268: <tbody> you'd have hit the first paragraph since the <body>
4269: wouldn't be in scope, unless it was a fragment case) -->
4270:
4271: <!-- If we ever change the frameset-ok flag to an insertion mode,
4272: then we'd have to somehow keep track of its state when we switch
4273: to after-body. -->
4274:
4275: <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>
4276:
4277: </dd>
4278:
4279: <dt>An end tag whose tag name is "html"</dt>
4280: <dd>
4281:
4282: <p>Act as if an end tag with tag name "body" had been seen,
4283: then, if that token wasn't ignored, reprocess the current
4284: token.</p>
4285:
4286: <p class="note">The fake end tag token here can only be
4287: ignored in the <a href="#fragment-case">fragment case</a>.</p>
4288:
4289: </dd>
4290:
4291: <!-- start tags for non-phrasing flow content elements -->
4292:
4293: <!-- the normal ones -->
4294: <dt>A start tag whose tag name is one of: "address", "article",
1.86 mike 4295: "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
4296: "details", "dialog", "dir", "div", "dl", "fieldset", "figure",
4297: "footer", "header", "hgroup", "menu", "nav", "ol", "p", "section",
4298: "ul"</dt>
1.1 mike 4299: <dd>
4300:
4301: <!-- As of May 2008 this doesn't match any browser exactly, but is
4302: as close to what IE does as I can get without doing the non-tree
4303: DOM nonsense, and thus should actually afford better compatibility
4304: when implemented by the other browsers. -->
4305:
4306: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4307: an element in scope">has a <code>p</code> element in
4308: scope</a>, then act as if an end tag with the tag name
4309: "p" had been seen.</p>
4310:
4311: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4312:
4313: </dd>
4314:
4315: <!-- as normal, but close h1-h6 if it's the current node -->
4316: <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
4317: "h5", "h6"</dt>
4318: <dd>
4319:
4320: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4321: an element in scope">has a <code>p</code> element in
4322: scope</a>, then act as if an end tag with the tag name
4323: "p" had been seen.</p>
4324:
4325: <p>If the <a href="#current-node">current node</a> is an element whose tag name
4326: is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
4327: <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
4328: the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
4329: <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
4330:
4331: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4332:
4333: </dd>
4334:
4335: <!-- as normal, but drops leading newline -->
4336: <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
4337: <dd>
4338:
4339: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4340: an element in scope">has a <code>p</code> element in
4341: scope</a>, then act as if an end tag with the tag name
4342: "p" had been seen.</p>
4343:
4344: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4345:
4346: <p>If the next token is a U+000A LINE FEED (LF) character
4347: token, then ignore that token and move on to the next
4348: one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
4349: ignored as an authoring convenience.)</p>
4350:
4351: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4352:
4353: </dd>
4354:
4355: <!-- as normal, but interacts with the form element pointer -->
4356: <dt>A start tag whose tag name is "form"</dt>
4357: <dd>
4358:
4359: <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
4360: pointer</a> is not null, then this is a <a href="#parse-error">parse
4361: error</a>; ignore the token.</p>
4362:
4363: <p>Otherwise:</p>
4364:
4365: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4366: an element in scope">has a <code>p</code> element in
4367: scope</a>, then act as if an end tag with the tag name
4368: "p" had been seen.</p>
4369:
4370: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
4371: <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
4372: point to the element created.</p>
4373:
4374: </dd>
4375:
4376: <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
4377: <dt>A start tag whose tag name is "li"</dt>
4378: <dd>
4379:
4380: <p>Run the following algorithm:</p>
4381:
4382: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
4383:
4384: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
4385: node</a> (the bottommost node of the stack).</p></li>
4386:
4387: <li><p>If <var title="">node</var> is an <code><a href="semantics.html#the-li-element">li</a></code> element,
4388: then act as if an end tag with the tag name "li" had
4389: been seen, then jump to the last step.</p></li>
4390:
4391: <li><p><i>Loop</i>: If <var title="">node</var> is not in the
4392: <a href="#formatting">formatting</a> category, and is not in the
4393: <a href="#phrasing">phrasing</a> category, and is not an
4394: <code><a href="semantics.html#the-address-element">address</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, or <code><a href="semantics.html#the-p-element">p</a></code>
4395: element, then jump to the last step.</p></li> <!-- an element
4396: <foo> is in this list if the following markup:
4397:
4398: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
4399:
4400: ...results in the second <li> not being (in any way) a descendant
4401: of the first <li>, or if <foo> is a formatting element that gets
4402: reopened later. -->
4403:
4404: <li><p>Otherwise, set <var title="">node</var> to the previous
4405: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
4406: the step labeled <i>loop</i>.</p></li>
4407:
4408: <li>
4409:
4410: <p>This is the last step.</p>
4411:
4412: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4413: an element in scope">has a <code>p</code> element in
4414: scope</a>, then act as if an end tag with the tag name
4415: "p" had been seen.</p>
4416:
4417: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
4418: token.</p>
4419:
4420: </li>
4421:
4422: </ol></dd>
4423:
4424: <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases -->
4425: <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
4426: <dd>
4427:
4428: <p>Run the following algorithm:</p>
4429:
4430: <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
4431:
4432: <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
4433: node</a> (the bottommost node of the stack).</p></li>
4434:
4435: <li><p><i>Loop</i>: If <var title="">node</var> is a
4436: <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
4437: tag with the same tag name as <var title="">node</var> had been
4438: seen, then jump to the last step.</p></li>
4439:
4440: <li><p>If <var title="">node</var> is not in the
4441: <a href="#formatting">formatting</a> category, and is not in the
4442: <a href="#phrasing">phrasing</a> category, and is not an
4443: <code><a href="semantics.html#the-address-element">address</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, or <code><a href="semantics.html#the-p-element">p</a></code>
4444: element, then jump to the last step.</p></li> <!-- an element
4445: <foo> is in this list if the following markup:
4446:
4447: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
4448:
4449: ...results in the second <dt> not being (in any way) a descendant
4450: of the first <dt>, or if <foo> is a formatting element that gets
4451: reopened later. -->
4452:
4453: <li><p>Otherwise, set <var title="">node</var> to the previous
4454: entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
4455: the step labeled <i>loop</i>.</p></li>
4456:
4457: <li>
4458:
4459: <p>This is the last step.</p>
4460:
4461: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4462: an element in scope">has a <code>p</code> element in
4463: scope</a>, then act as if an end tag with the tag name
4464: "p" had been seen.</p>
4465:
4466: <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
4467: token.</p>
4468:
4469: </li>
4470:
4471: </ol></dd>
4472:
4473: <!-- same as normal, but effectively ends parsing -->
4474: <dt>A start tag whose tag name is "plaintext"</dt>
4475: <dd>
4476:
4477: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4478: an element in scope">has a <code>p</code> element in
4479: scope</a>, then act as if an end tag with the tag name
4480: "p" had been seen.</p>
4481:
4482: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4483:
4484: <p>Switch the <a href="#content-model-flag">content model flag</a> to the PLAINTEXT
4485: state.</p>
4486:
4487: <p class="note">Once a start tag with the tag name "plaintext"
4488: has been seen, that will be the last token ever seen other
4489: than character tokens (and the end-of-file token), because
4490: there is no way to switch the <a href="#content-model-flag">content model flag</a>
4491: out of the PLAINTEXT state.</p>
4492:
4493: </dd>
4494:
4495: <!-- end tags for non-phrasing flow content elements -->
4496:
4497: <!-- the normal ones -->
4498: <dt>An end tag whose tag name is one of: "address", "article",
1.86 mike 4499: "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
4500: "details", "dialog", "dir", "div", "dl", "fieldset", "figure",
4501: "footer", "header", "hgroup", "listing", "menu", "nav", "ol",
4502: "pre", "section", "ul"</dt>
1.1 mike 4503: <dd>
4504:
4505: <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>
4506: with the same tag name as that of the token, then this is a
4507: <a href="#parse-error">parse error</a>; ignore the token.</p>
4508:
4509: <p>Otherwise, run these steps:</p>
4510:
4511: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4512:
4513: <li><p>If the <a href="#current-node">current node</a> is not an element with
4514: the same tag name as that of the token, then this is a
4515: <a href="#parse-error">parse error</a>.</p></li>
4516:
4517: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4518: until an element with the same tag name as the token has been
4519: popped from the stack.</p></li>
4520:
4521: </ol></dd>
4522:
4523: <!-- removes the form element pointer instead of the matching node -->
4524: <dt>An end tag whose tag name is "form"</dt>
4525: <dd>
4526:
4527: <p>Let <var title="">node</var> be the element that the
4528: <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
4529: to.</p>
4530:
4531: <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
4532: to null.</p>
4533:
4534: <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
4535: elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
4536: scope">have <var title="">node</var> in scope</a>, then this is
4537: a <a href="#parse-error">parse error</a>; ignore the token.</p>
4538:
4539: <p>Otherwise, run these steps:</p>
4540:
4541: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4542:
4543: <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
4544: error</a>.</p></li>
4545:
4546: <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
4547: open elements</a>.</p></li>
4548:
4549: </ol></dd>
4550:
4551: <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
4552: <dt>An end tag whose tag name is "p"</dt>
4553: <dd>
4554:
4555: <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>
4556: with the same tag name as that of the token, then this is a
4557: <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
4558: "p" had been seen, then reprocess the current token.</p>
4559:
4560: <p>Otherwise, run these steps:</p>
4561:
4562: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
4563: for elements with the same tag name as the token.</p></li>
4564:
4565: <li><p>If the <a href="#current-node">current node</a> is not an element with
4566: the same tag name as that of the token, then this is a
4567: <a href="#parse-error">parse error</a>.</p></li>
4568:
4569: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4570: until an element with the same tag name as the token has been
4571: popped from the stack.</p></li>
4572:
4573: </ol></dd>
4574:
4575: <!-- as normal, but needs care as the elements have optional tags -->
4576: <dt>An end tag whose tag name is one of: "dd", "dt", "li"</dt>
4577: <dd>
4578:
4579: <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>
4580: with the same tag name as that of the token, then this is a
4581: <a href="#parse-error">parse error</a>; ignore the token.</p>
4582:
4583: <p>Otherwise, run these steps:</p>
4584:
4585: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
4586: for elements with the same tag name as the token.</p></li>
4587:
4588: <li><p>If the <a href="#current-node">current node</a> is not an element with
4589: the same tag name as that of the token, then this is a
4590: <a href="#parse-error">parse error</a>.</p></li>
4591:
4592: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4593: until an element with the same tag name as the token has been
4594: popped from the stack.</p></li>
4595:
4596: </ol></dd>
4597:
4598: <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
4599: <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
4600: <dd>
4601:
4602: <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>
4603: whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
4604: then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
4605:
4606: <p>Otherwise, run these steps:</p>
4607:
4608: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4609:
4610: <li><p>If the <a href="#current-node">current node</a> is not an element with
4611: the same tag name as that of the token, then this is a
4612: <a href="#parse-error">parse error</a>.</p></li>
4613:
4614: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4615: until an element whose tag name is one of "h1", "h2", "h3", "h4",
4616: "h5", or "h6" has been popped from the stack.</p></li>
4617:
4618: </ol></dd>
4619:
4620: <dt>An end tag whose tag name is "sarcasm"</dt>
4621: <dd>
4622: <p>Take a deep breath, then act as described in the "any other end
4623: tag" entry below.</p>
4624: </dd>
4625:
4626: <!-- ADOPTION AGENCY ELEMENTS
4627: Mozilla-only: bdo blink del ins sub sup q
4628: Safari-only: code dfn kbd nobr samp var wbr
4629: Both: a b big em font i s small strike strong tt u -->
4630:
4631: <dt>A start tag whose tag name is "a"</dt>
4632: <dd>
4633:
4634: <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
4635: contains an element whose tag name is "a" between the end of
4636: the list and the last marker on the list (or the start of the
4637: list if there is no marker on the list), then this is a
4638: <a href="#parse-error">parse error</a>; act as if an end tag with the tag
4639: name "a" had been seen, then remove that element from the
4640: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
4641: <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
4642: already remove it (it might not have if the element is not
4643: <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
4644: scope</a>).</p>
4645:
4646: <p class="example">In the non-conforming stream
4647: <code><a href="a">a<table><a href="b">b</table>x</code>,
4648: the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
4649: the second one, and the "x" character would be inside a link
4650: to "b", not to "a". This is despite the fact that the outer
4651: <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
4652: regular <code></a></code> end tag at the start of the table
4653: wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
4654:
4655: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4656: any.</p>
4657:
4658: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
4659: element to the <a href="#list-of-active-formatting-elements">list of active formatting
4660: elements</a>.</p>
4661:
4662: </dd>
4663:
4664: <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
4665: "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
4666: <dd>
4667:
4668: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4669: any.</p>
4670:
4671: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
4672: element to the <a href="#list-of-active-formatting-elements">list of active formatting
4673: elements</a>.</p>
4674:
4675: </dd>
4676:
4677: <dt>A start tag whose tag name is "nobr"</dt>
4678: <dd>
4679:
4680: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4681: any.</p>
4682:
4683: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
4684: element in scope">has a <code>nobr</code> element in scope</a>,
4685: then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
4686: the tag name "nobr" had been seen, then once again
4687: <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
4688: any.</p>
4689:
4690: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
4691: element to the <a href="#list-of-active-formatting-elements">list of active formatting
4692: elements</a>.</p>
4693:
4694: </dd>
4695:
4696: <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
4697: "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
4698: "strike", "strong", "tt", "u"</dt>
4699: <dd>
4700:
4701: <p>Follow these steps:</p>
4702:
4703: <ol><li>
4704:
4705: <p>Let the <var title="">formatting element</var> be the
4706: last element in the <a href="#list-of-active-formatting-elements">list of active formatting
4707: elements</a> that:</p>
4708:
4709: <ul><li>is between the end of the list and the last scope
4710: marker in the list, if any, or the start of the list
4711: otherwise, and</li>
4712:
4713: <li>has the same tag name as the token.</li>
4714:
4715: </ul><p>If there is no such node, or, if that node is also in the
4716: <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
4717: <a href="#parse-error">parse error</a>; ignore the token, and abort these
4718: steps.</p>
4719:
4720: <p>Otherwise, if there is such a node, but that node is not
4721: in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
4722: <a href="#parse-error">parse error</a>; remove the element from the list,
4723: and abort these steps.</p>
4724:
4725: <p>Otherwise, there is a <var title="">formatting
4726: element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
4727: open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
4728: element in scope">in scope</a>. If the element is not the
4729: <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
4730: error</a>. In any case, proceed with the algorithm as
4731: written in the following steps.</p>
4732:
4733: </li>
4734:
4735: <li><p>Let the <var title="">furthest block</var> be the
4736: topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
4737: is lower in the stack than the <var title="">formatting
4738: element</var>, and is not an element in the
4739: <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
4740: categories. There might not be one.</p></li>
4741:
4742: <li><p>If there is no <var title="">furthest block</var>,
4743: then the UA must skip the subsequent steps and instead just
4744: pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
4745: elements</a>, from the <a href="#current-node">current node</a> up to and
4746: including the <var title="">formatting element</var>, and
4747: remove the <var title="">formatting element</var> from the
4748: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
4749:
4750: <li><p>Let the <var title="">common ancestor</var> be the element
4751: immediately above the <var title="">formatting element</var> in the
4752: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
4753:
4754: <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
4755: formatting elements</a> relative to the elements on either
4756: side of it in the list.</p></li>
4757:
4758: <li>
4759:
4760: <p>Let <var title="">node</var> and <var title="">last node</var> be the
4761: <var title="">furthest block</var>. Follow these steps:</p>
4762:
4763: <ol><li>Let <var title="">node</var> be the element immediately
4764: above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
4765: elements</a>.</li>
4766:
4767: <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
4768: active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
4769: elements</a> and then go back to step 1.</li>
4770:
4771: <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
4772: in the overall algorithm.</li>
4773:
4774: <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
4775: bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
4776: elements</a>.</li>
4777:
4778: <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
4779: element <var title="">node</var> was created, replace the entry
4780: for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
4781: formatting elements</a> with an entry for the new element,
4782: replace the entry for <var title="">node</var> in the
4783: <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
4784: element, and let <var title="">node</var> be the new
4785: element.</li>
4786:
4787: <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
4788: parent node if any.</li>
4789:
4790: <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
4791:
4792: <li>Return to step 1 of this inner set of steps.</li>
4793:
4794: </ol></li>
4795:
4796: <li>
4797:
4798: <p>If the <var title="">common ancestor</var> node is a
4799: <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>,
4800: <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,
4801: <a href="#foster-parent">foster parent</a> whatever <var title="">last
4802: node</var> ended up being in the previous step, first removing
4803: it from its previous parent node if any.</p>
4804:
4805: <p>Otherwise, append whatever <var title="">last node</var>
4806: ended up being in the previous step to the <var title="">common
4807: ancestor</var> node, first removing it from its previous parent
4808: node if any.</p>
4809:
4810: </li>
4811:
4812: <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
4813: <var title="">formatting element</var> was created.</p></li>
4814:
4815: <li><p>Take all of the child nodes of the <var title="">furthest
4816: block</var> and append them to the element created in the last
4817: step.</p></li>
4818:
4819: <li><p>Append that new element to the <var title="">furthest
4820: block</var>.</p></li>
4821:
4822: <li><p>Remove the <var title="">formatting element</var> from the
4823: <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
4824: new element into the <a href="#list-of-active-formatting-elements">list of active formatting
4825: elements</a> at the position of the aforementioned
4826: bookmark.</p></li>
4827:
4828: <li><p>Remove the <var title="">formatting element</var> from the
4829: <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
4830: into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
4831: the position of the <var title="">furthest block</var> in that
4832: stack.</p></li>
4833:
4834: <li><p>Jump back to step 1 in this series of steps.</p></li>
4835:
4836: </ol><!--XXX
4837: <div class="example">
4838: <p class="XXX">Need an example.</p>
4839: </div>
4840: --><p class="note">Because of the way this algorithm causes elements to
4841: change parents, it has been dubbed the "adoption agency algorithm"
4842: (in contrast with other possibly algorithms for dealing with
4843: misnested content, which included the "incest algorithm", the
4844: "secret affair algorithm", and the "Heisenberg algorithm").</p>
4845:
4846: </dd>
4847:
4848: <dt>A start tag whose tag name is "button"</dt>
4849: <dd>
4850:
4851: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4852: an element in scope">has a <code>button</code> element in
4853: scope</a>, then this is a <a href="#parse-error">parse error</a>;
4854: act as if an end tag with the tag name "button" had been seen,
4855: then reprocess the token.</p>
4856:
4857: <p>Otherwise:</p>
4858:
4859: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4860: any.</p>
4861:
4862: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4863:
4864: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
4865: formatting elements</a>.</p>
4866:
4867: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4868:
4869: </dd>
4870:
4871: <dt>A start tag token whose tag name is one of: "applet",
4872: "marquee", "object"</dt>
4873: <dd>
4874:
4875: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4876: any.</p>
4877:
4878: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4879:
4880: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
4881: formatting elements</a>.</p>
4882:
4883: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4884:
4885: </dd>
4886:
4887: <dt>An end tag token whose tag name is one of: "applet", "button",
4888: "marquee", "object"</dt>
4889: <dd>
4890:
4891: <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>
4892: with the same tag name as that of the token, then this is a
4893: <a href="#parse-error">parse error</a>; ignore the token.</p>
4894:
4895: <p>Otherwise, run these steps:</p>
4896:
4897: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
4898:
4899: <li><p>If the <a href="#current-node">current node</a> is not an element with
4900: the same tag name as that of the token, then this is a
4901: <a href="#parse-error">parse error</a>.</p></li>
4902:
4903: <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
4904: until an element with the same tag name as the token has been
4905: popped from the stack.</p></li>
4906:
4907: <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
4908: last marker</a>.</li>
4909:
4910: </ol></dd>
4911:
4912: <dt>A start tag whose tag name is "table"</dt>
4913: <dd>
4914:
4915: <p>If the <code>Document</code> is <em>not</em> set to
4916: <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
4917: elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
4918: <code>p</code> element in scope</a>, then act as if an end tag
4919: with the tag name "p" had been seen.</p> <!-- i hate myself (this
4920: quirk was basically caused by acid2; if i'd realised we could
4921: change the specs when i wrote acid2, we could have avoided having
4922: any parsing-mode quirks) -Hixie -->
4923:
4924: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
4925:
4926: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4927:
4928: <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>
4929:
4930: </dd>
4931:
4932: <dt>A start tag whose tag name is one of: "area", "basefont",
4933: "bgsound", "br", "embed", "img", "input", "keygen", "spacer",
4934: "wbr"</dt>
4935: <dd>
4936:
4937: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
4938: any.</p>
4939:
4940: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4941: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4942: elements</a>.</p>
4943:
4944: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4945: token's <i>self-closing flag</i></a>, if it is set.</p>
4946:
4947: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
4948: shouldn't really do it for <area>, <basefont>, <bgsound>, and
4949: <spacer> -->
4950:
4951: </dd>
4952:
4953: <dt>A start tag whose tag name is one of: "param", "source"</dt>
4954: <dd>
4955:
4956: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4957: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4958: elements</a>.</p>
4959:
4960: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4961: token's <i>self-closing flag</i></a>, if it is set.</p>
4962:
4963: </dd>
4964:
4965: <dt>A start tag whose tag name is "hr"</dt>
4966: <dd>
4967:
4968: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
4969: an element in scope">has a <code>p</code> element in
4970: scope</a>, then act as if an end tag with the tag name
4971: "p" had been seen.</p>
4972:
4973: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
4974: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
4975: elements</a>.</p>
4976:
4977: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
4978: token's <i>self-closing flag</i></a>, if it is set.</p>
4979:
4980: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
4981:
4982: </dd>
4983:
4984: <dt>A start tag whose tag name is "image"</dt>
4985: <dd>
4986: <p><a href="#parse-error">Parse error</a>. Change the token's tag name
4987: to "img" and reprocess it. (Don't ask.)</p> <!-- As of
4988: 2005-12, studies showed that around 0.2% of pages used the
4989: <image> element. -->
4990: </dd>
4991:
4992: <dt id="isindex">A start tag whose tag name is "isindex"</dt>
4993: <dd>
4994:
4995: <p><a href="#parse-error">Parse error</a>.</p>
4996:
4997: <p>If the <a href="#form-element-pointer"><code title="">form</code> element
4998: pointer</a> is not null, then ignore the token.</p>
4999:
5000: <p>Otherwise:</p>
5001:
5002: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5003: token's <i>self-closing flag</i></a>, if it is set.</p> <!--
5004: purely to reduce the number of errors (we don't care if they
5005: included the /, they're not supposed to be including the tag at
5006: all! -->
5007:
5008: <p>Act as if a start tag token with the tag name "form" had been seen.</p>
5009:
5010: <p>If the token has an attribute called "action", set the
5011: <code title="attr-form-action">action</code> attribute on the
5012: resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
5013: "action" attribute of the token.</p>
5014:
5015: <p>Act as if a start tag token with the tag name "hr" had been
5016: seen.</p>
5017:
5018: <p>Act as if a start tag token with the tag name "label" had been
5019: seen.</p>
5020:
5021: <p>Act as if a stream of character tokens had been seen (see below
5022: for what they should say).</p>
5023:
5024: <p>Act as if a start tag token with the tag name "input" had been
5025: seen, with all the attributes from the "isindex" token except
5026: "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
5027: <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
5028:
5029: <p>Act as if a stream of character tokens had been seen (see
5030: below for what they should say).</p>
5031:
5032: <p>Act as if an end tag token with the tag name "label" had been
5033: seen.</p>
5034:
5035: <p>Act as if a start tag token with the tag name "hr" had been
5036: seen.</p>
5037:
5038: <p>Act as if an end tag token with the tag name "form" had been
5039: seen.</p>
5040:
5041: <p>If the token has an attribute with the name "prompt", then the
5042: first stream of characters must be the same string as given in
5043: that attribute, and the second stream of characters must be
5044: empty. Otherwise, the two streams of character tokens together
5045: should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
5046: equivalent of "This is a searchable index. Insert your search
5047: keywords here: (input field)" in the user's preferred
5048: language.</p>
5049:
5050: </dd>
5051:
5052: <dt>A start tag whose tag name is "textarea"</dt>
5053: <dd>
5054:
5055: <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
5056: token.</p></li>
5057:
5058: <li><p>If the next token is a U+000A LINE FEED (LF) character
5059: token, then ignore that token and move on to the next
5060: one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
5061: ignored as an authoring convenience.)</p></li>
5062:
5063: <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
5064: the RCDATA state.</p></li>
5065:
5066: <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
5067: current <a href="#insertion-mode">insertion mode</a>.</p>
5068:
5069: </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
5070: ok".</p></li>
5071:
1.91 mike 5072: <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
5073: RAWTEXT/RCDATA</a>".</p></li>
1.1 mike 5074:
5075: </ol></dd>
5076:
5077: <dt>A start tag whose tag name is "xmp"</dt>
5078: <dd>
5079:
5080: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5081: any.</p>
5082:
5083: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5084:
1.91 mike 5085: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5086:
5087: </dd>
5088:
5089: <dt>A start tag whose tag name is "iframe"</dt>
5090: <dd>
5091:
5092: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5093:
1.91 mike 5094: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5095:
5096: </dd>
5097:
5098: <dt>A start tag whose tag name is "noembed"</dt>
5099: <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
5100: <dd>
5101:
1.91 mike 5102: <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1 mike 5103:
5104: </dd>
5105:
5106: <dt>A start tag whose tag name is "select"</dt>
5107: <dd>
5108:
5109: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5110: any.</p>
5111:
5112: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5113:
5114: <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
5115:
5116: <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>",
5117: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
5118: body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
5119: row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
5120: cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
5121: "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
5122: table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
5123: to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
5124:
5125: </dd>
5126:
5127: <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
5128: <dd>
5129:
5130: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5131: element in scope">has an <code>option</code> element in
5132: scope</a>, then act as if an end tag with the tag name "option"
5133: had been seen.</p>
5134:
5135: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5136: any.</p>
5137:
5138: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5139:
5140: </dd>
5141:
5142: <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
5143: <dd>
5144:
5145: <!-- the parsing rules for ruby really don't match IE much at all,
5146: but in practice the markup used is very simple and so strict
5147: compatibility with IE isn't required. For example, as defined
5148: here we get very, very different behaviour than IE for
5149: pathological cases like:
5150:
5151: <ruby><ol><li><p>a<rt>b
5152: <ruby>a<rt>b<p>c
5153:
5154: But in practice most ruby markup falls into these cases:
5155:
5156: <ruby>a<rt>b</ruby>
5157: <ruby>a<rp>b<rt>c<rp>d</ruby>
5158: <ruby>a<rt>b</rt></ruby>
5159: <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
5160:
5161: -->
5162:
5163: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
5164: element in scope">has a <code>ruby</code> element in scope</a>,
5165: then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
5166: node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
5167: <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
5168: node</a> up to the node immediately before the bottommost
5169: <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
5170: elements</a>.</p>
5171:
5172: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5173:
5174: </dd>
5175:
5176: <dt>An end tag whose tag name is "br"</dt>
5177: <dd>
5178: <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
5179: the tag name "br" had been seen. Ignore the end tag token.</p>
5180: </dd>
5181:
5182: <dt>A start tag whose tag name is "math"</dt>
5183: <dd>
5184:
5185: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5186: any.</p>
5187:
5188: <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
5189: fixes the case of MathML attributes that are not all
5190: lowercase.)</p>
5191:
5192: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
5193: fixes the use of namespaced attributes, in particular XLink.)</p>
5194:
5195: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
5196: <a href="#mathml-namespace">MathML namespace</a>.</p>
5197:
5198: <!-- If we ever change the frameset-ok flag to an insertion mode,
5199: the following change would be implied, except we'd have to do it
5200: even in the face of a self-closed tag:
5201: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
5202: -->
5203:
5204: <p>If the token has its <i>self-closing flag</i> set, pop the
5205: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5206: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
5207: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
5208:
5209: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
5210: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
5211: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
5212: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
5213: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
5214: foreign content">in foreign content</a>".</p>
5215:
5216: </dd>
5217:
5218: <dt>A start tag whose tag name is "svg"</dt>
5219: <dd>
5220:
5221: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5222: any.</p>
5223:
5224: <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
5225: the case of SVG attributes that are not all lowercase.)</p>
5226:
5227: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
5228: fixes the use of namespaced attributes, in particular XLink in
5229: SVG.)</p>
5230:
5231: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
5232: <a href="#svg-namespace">SVG namespace</a>.</p>
5233:
5234: <!-- If we ever change the frameset-ok flag to an insertion mode,
5235: the following change would be implied, except we'd have to do it
5236: even in the face of a self-closed tag:
5237: <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
5238: -->
5239:
5240: <p>If the token has its <i>self-closing flag</i> set, pop the
5241: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5242: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
5243: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
5244:
5245: <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
5246: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
5247: content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
5248: the current <a href="#insertion-mode">insertion mode</a>, and then switch the
5249: <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
5250: foreign content">in foreign content</a>".</p>
5251:
5252: </dd>
5253:
5254: <dt>A start <!--or end--> tag whose tag name is one of: "caption",
5255: "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
5256: "thead", "tr"</dt>
5257: <!--<dt>An end tag whose tag name is one of: "area", "base",
5258: "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
5259: "img", "input", "isindex", "keygen", "link", "meta", "noembed",
5260: "noframes", "param", "script", "select", "source", "spacer",
5261: "style", "table", "textarea", "title", "wbr"</dt>-->
5262: <!--<dt>An end tag whose tag name is "noscript", if the
5263: <span>scripting flag</span> is enabled</dt>-->
5264: <dd>
5265: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5266: <!-- end tags are commented out because since they can never end
5267: up on the stack anyway, the default end tag clause will
5268: automatically handle them. we don't want to have text in the spec
5269: that is just an optimisation, as that detracts from the spec
5270: itself -->
5271: </dd>
5272:
5273: <dt>Any other start tag</dt>
5274: <dd>
5275:
5276: <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
5277: any.</p>
5278:
5279: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5280:
5281: <p class="note">This element will be a <a href="#phrasing">phrasing</a>
5282: element.</p>
5283:
5284: </dd>
5285:
5286: <dt>Any other end tag</dt>
5287: <dd>
5288:
5289: <p>Run the following steps:</p>
5290:
5291: <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
5292: node</a> (the bottommost node of the stack).</p></li>
5293:
5294: <li><p>If <var title="">node</var> has the same tag name as
5295: the end tag token, then:</p>
5296:
5297: <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
5298:
5299: <li><p>If the tag name of the end tag token does not match
5300: the tag name of the <a href="#current-node">current node</a>, this is a
5301: <a href="#parse-error">parse error</a>.</p></li>
5302:
5303: <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
5304: to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
5305:
5306: </ol></li>
5307:
5308: <li><p>Otherwise, if <var title="">node</var> is in neither the
5309: <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
5310: category, then this is a <a href="#parse-error">parse error</a>; ignore the
5311: token, and abort these steps.</p></li>
5312:
5313: <li><p>Set <var title="">node</var> to the previous entry in the
5314: <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
5315:
5316: <li><p>Return to step 2.</p></li>
5317:
5318: </ol></dd>
5319:
1.91 mike 5320: </dl><h5 id="parsing-main-incdata"><span class="secno">9.2.5.11 </span>The "<dfn title="insertion mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</dfn>" insertion mode</h5>
1.1 mike 5321:
5322: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.91 mike 5323: mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>", tokens must be
1.1 mike 5324: handled as follows:</p>
5325:
5326: <dl class="switch"><dt>A character token</dt>
5327: <dd>
5328:
5329: <p><a href="#insert-a-character" title="insert a character">Insert the token's
5330: character</a> into the <a href="#current-node">current node</a>.</p>
5331:
5332: </dd>
5333:
5334: <dt>An end-of-file token</dt>
5335: <dd>
5336:
5337: <!-- can't be the fragment case -->
5338: <p><a href="#parse-error">Parse error</a>.</p>
5339:
5340: <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
5341: element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
5342: executed"</a>.</p>
5343:
5344: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5345: elements</a>.</p>
5346:
5347: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5348: insertion mode</a> and reprocess the current token.</p>
5349:
5350: </dd>
5351:
5352: <dt>An end tag whose tag name is "script"</dt>
5353: <dd>
5354:
5355: <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
5356: (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
5357:
5358: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5359: elements</a>.</p>
5360:
5361: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5362: insertion mode</a>.</p>
5363:
5364: <p>Let the <var title="">old insertion point</var> have the
5365: same value as the current <a href="#insertion-point">insertion point</a>. Let
5366: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
5367: input character</a>.</p>
5368:
5369: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
5370: one.</p>
5371:
5372: <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,
5373: which might cause <a href="dom.html#dom-document-write" title="dom-document-write">new characters
5374: to be inserted into the tokenizer</a>, and might cause the
5375: tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
5376:
5377: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
5378: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
5379: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
5380:
5381: <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
5382: <a href="#insertion-point">insertion point</a> to its previous value. This value
5383: might be the "undefined" value.)</p>
5384:
5385: <p id="scriptTagParserResumes">At this stage, if there is a
5386: <a href="semantics.html#pending-external-script">pending external script</a>, then:</p>
5387:
5388: <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
5389:
5390: <dd>
5391:
5392: <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
5393: processing of any nested invocations of the tokenizer, yielding
5394: control back to the caller. (Tokenization will resume when the
5395: caller returns to the "outer" tree construction stage.)</p>
5396:
5397: <p class="note">The tree construction stage of this particular
5398: parser is <a href="#nestedParsing">being called reentrantly</a>,
5399: say from a call to <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code>.</p>
5400:
5401: </dd>
5402:
5403:
5404: <dt>Otherwise:</dt>
5405:
5406: <dd>
5407:
5408: <p>Follow these steps:</p>
5409:
5410: <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-external-script">pending
5411: external script</a>. There is no longer a <a href="semantics.html#pending-external-script">pending
5412: external script</a>.</p></li>
5413:
5414: <li><p><a href="browsers.html#pause">Pause</a> until the script has <a href="semantics.html#completed-loading">completed
5415: loading</a>.</p></li>
5416:
5417: <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
5418: <a href="#next-input-character">next input character</a>.</p></li>
5419:
5420: <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
5421: by one (it should be zero before this step, so this sets it to
5422: one).</p></li>
5423:
5424: <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute the
5425: script</a>.</p></li>
5426:
5427: <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
5428: by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
5429: zero (which it always should be at this point), then set the
5430: <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
5431:
5432: </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
5433: again.</p></li>
5434:
5435: <li><p>If there is once again a <a href="semantics.html#pending-external-script">pending external
5436: script</a>, then repeat these steps from step 1.</p></li>
5437:
5438: </ol></dd>
5439:
5440: </dl></dd>
5441:
5442: <dt>Any other end tag</dt>
5443: <dd>
5444:
5445: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5446: elements</a>.</p>
5447:
5448: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5449: insertion mode</a>.</p>
5450:
5451: </dd>
5452:
5453: </dl><h5 id="parsing-main-intable"><span class="secno">9.2.5.12 </span>The "<dfn title="insertion mode: in table">in table</dfn>" insertion mode</h5>
5454:
5455: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
5456: mode: in table">in table</a>", tokens must be handled as follows:</p>
5457:
5458: <dl class="switch"><dt>A character token</dt>
5459: <dd>
5460:
5461: <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
5462: be an empty list of tokens.</p>
5463:
5464: <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
5465: <a href="#insertion-mode">insertion mode</a>.</p>
5466:
5467: <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
5468: reprocess the token.</p>
5469:
5470: </dd>
5471:
5472: <dt>A comment token</dt>
5473: <dd>
5474: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
5475: node</a> with the <code title="">data</code> attribute set to
5476: the data given in the comment token.</p>
5477: </dd>
5478:
5479: <dt>A DOCTYPE token</dt>
5480: <dd>
5481: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5482: </dd>
5483:
5484: <dt>A start tag whose tag name is "caption"</dt>
5485: <dd>
5486:
5487: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5488: below.)</p>
5489:
5490: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5491: formatting elements</a>.</p>
5492:
5493: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5494: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
5495:
5496: </dd>
5497:
5498: <dt>A start tag whose tag name is "colgroup"</dt>
5499: <dd>
5500:
5501: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5502: below.)</p>
5503:
5504: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5505: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
5506: group</a>".</p>
5507:
5508: </dd>
5509:
5510: <dt>A start tag whose tag name is "col"</dt>
5511: <dd>
5512: <p>Act as if a start tag token with the tag name "colgroup"
5513: had been seen, then reprocess the current token.</p>
5514: </dd>
5515:
5516: <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
5517: <dd>
5518:
5519: <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
5520: below.)</p>
5521:
5522: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
5523: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
5524: body</a>".</p>
5525:
5526: </dd>
5527:
5528: <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
5529: <dd>
5530: <p>Act as if a start tag token with the tag name "tbody" had
5531: been seen, then reprocess the current token.</p>
5532: </dd>
5533:
5534: <dt>A start tag whose tag name is "table"</dt>
5535: <dd>
5536:
5537: <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
5538: the tag name "table" had been seen, then, if that token wasn't
5539: ignored, reprocess the current token.</p>
5540:
5541: <p class="note">The fake end tag token here can only be
5542: ignored in the <a href="#fragment-case">fragment case</a>.</p>
5543:
5544: </dd>
5545:
5546: <dt>An end tag whose tag name is "table"</dt>
5547: <dd>
5548:
5549: <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
5550: scope</a> with the same tag name as the token, this is a
5551: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
5552: case</a>)</p>
5553:
5554: <p>Otherwise:</p>
5555:
5556: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
5557: element has been popped from the stack.</p>
5558:
5559: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
5560:
5561: </dd>
5562:
5563: <dt>An end tag whose tag name is one of: "body", "caption",
5564: "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
5565: "thead", "tr"</dt>
5566: <dd>
5567: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5568: </dd>
5569:
5570: <dt>A start tag whose tag name is one of: "style", "script"</dt>
5571: <dd>
5572:
5573: <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
5574: mode</a>.</p>
5575:
5576: </dd>
5577:
5578: <dt>A start tag whose tag name is "input"</dt>
5579: <dd>
5580:
5581: <p>If the token does not have an attribute with the name "type",
5582: or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
5583: case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
5584: else" entry below.</p>
5585:
5586: <p>Otherwise:</p>
5587:
5588: <p><a href="#parse-error">Parse error</a>.</p>
5589:
5590: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
5591:
5592: <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
5593: open elements</a>.</p>
5594:
5595: </dd>
5596:
5597: <dt>An end-of-file token</dt>
5598: <dd>
5599:
5600: <p>If the <a href="#current-node">current node</a> is not the root
5601: <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
5602: error</a>.</p>
5603:
5604: <p class="note">It can only be the <a href="#current-node">current node</a> in
5605: the <a href="#fragment-case">fragment case</a>.</p>
5606:
5607: <p><a href="#stop-parsing">Stop parsing</a>.</p>
5608:
5609: </dd>
5610:
5611: <dt>Anything else</dt>
5612: <dd>
5613:
5614: <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
5615: rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
5616: body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
5617: <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
5618: <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
5619: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
5620: into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
5621:
5622: </dd>
5623:
5624: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
5625: back to a table context</dfn>, it means that the UA must, while
5626: the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-table-element">table</a></code>
5627: element or an <code><a href="semantics.html#the-html-element">html</a></code> element, pop elements from the
5628: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
5629:
5630: <p class="note">The <a href="#current-node">current node</a> being an
5631: <code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="#fragment-case">fragment
5632: case</a>.</p>
5633:
5634:
5635:
5636: <h5 id="parsing-main-intabletext"><span class="secno">9.2.5.13 </span>The "<dfn title="insertion mode: in table text">in table text</dfn>" insertion mode</h5>
5637:
5638: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
5639: mode: in table text">in table text</a>", tokens must be handled
5640: as follows:</p>
5641:
5642: <dl class="switch"><dt>A character token</dt>
5643: <dd>
5644:
5645: <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
5646: tokens</a></var> list.</p>
5647:
5648: </dd>
5649:
5650:
5651: <dt>Anything else</dt>
5652: <dd>
5653:
5654: <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
5655: tokens</a></var> list are character tokens that are not one of U+0009
5656: CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
5657: (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
5658: reprocess those character tokens using the rules given in the
5659: "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
5660: table">in table</a>" insertion mode.</p>
5661:
5662: <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
5663: characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
5664: tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
5665:
5666: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
5667: insertion mode</a> and reprocess the token.</p>
5668:
5669: </dd>
5670:
5671: </dl><h5 id="parsing-main-incaption"><span class="secno">9.2.5.14 </span>The "<dfn title="insertion mode: in caption">in caption</dfn>" insertion mode</h5>
5672:
5673: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
5674: mode: in caption">in caption</a>", tokens must be handled as follows:</p>
5675:
5676: <dl class="switch"><dt>An end tag whose tag name is "caption"</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-table-scope" title="has an element in table scope">have an element in table
5680: scope</a> with the same tag name as the token, this is a
5681: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
5682: case</a>)</p>
5683:
5684: <p>Otherwise:</p>
5685:
5686: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
5687:
5688: <p>Now, if the <a href="#current-node">current node</a> is not a
5689: <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
5690: error</a>.</p>
5691:
5692: <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
5693: element has been popped from the stack.</p>
5694:
5695: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
5696: the last marker</a>.</p>
5697:
5698: <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>
5699:
5700: </dd>
5701:
5702: <dt>A start tag whose tag name is one of: "caption", "col",
5703: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
5704: <dt>An end tag whose tag name is "table"</dt>
5705: <dd>
5706:
5707: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
5708: name "caption" had been seen, then, if that token wasn't
5709: ignored, reprocess the current token.</p>
5710:
5711: <p class="note">The fake end tag token here can only be
5712: ignored in the <a href="#fragment-case">fragment case</a>.</p>
5713:
5714: </dd>
5715:
5716: <dt>An end tag whose tag name is one of: "body", "col",
5717: "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
5718: "tr"</dt>
5719: <dd>
5720: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5721: </dd>
5722:
5723: <dt>Anything else</dt>
5724: <dd>
5725: <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
5726: mode</a>.</p>
5727: </dd>
5728:
5729: </dl><h5 id="parsing-main-incolgroup"><span class="secno">9.2.5.15 </span>The "<dfn title="insertion mode: in column group">in column group</dfn>" insertion mode</h5>
5730:
5731: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
5732: mode: in column group">in column group</a>", tokens must be handled as follows:</p>
5733:
5734: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
5735: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
5736: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
5737: <dd>
5738: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
5739: the <a href="#current-node">current node</a>.</p>
5740: </dd>
5741:
5742: <dt>A comment token</dt>
5743: <dd>
5744: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
5745: node</a> with the <code title="">data</code> attribute set to
5746: the data given in the comment token.</p>
5747: </dd>
5748:
5749: <dt>A DOCTYPE token</dt>
5750: <dd>
5751: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5752: </dd>
5753:
5754: <dt>A start tag whose tag name is "html"</dt>
5755: <dd>
5756: <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
5757: mode</a>.</p>
5758: </dd>
5759:
5760: <dt>A start tag whose tag name is "col"</dt>
5761: <dd>
5762:
5763: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
5764: pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
5765: elements</a>.</p>
5766:
5767: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
5768: token's <i>self-closing flag</i></a>, if it is set.</p>
5769:
5770: </dd>
5771:
5772: <dt>An end tag whose tag name is "colgroup"</dt>
5773: <dd>
5774:
5775: <p>If the <a href="#current-node">current node</a> is the root
5776: <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
5777: error</a>; ignore the token. (<a href="#fragment-case">fragment
5778: case</a>)</p>
5779:
5780: <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
5781: 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
5782: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
5783: "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
5784:
5785: </dd>
5786:
5787: <dt>An end tag whose tag name is "col"</dt>
5788: <dd>
5789: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5790: </dd>
5791:
5792: <dt>An end-of-file token</dt>
5793: <dd>
5794:
5795: <p>If the <a href="#current-node">current node</a> is the root <code><a href="semantics.html#the-html-element">html</a></code>
5796: element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
5797: case</a>)</p>
5798:
5799: <p>Otherwise, act as described in the "anything else" entry
5800: below.</p>
5801:
5802: </dd>
5803:
5804: <dt>Anything else</dt>
5805: <dd>
5806:
5807: <p>Act as if an end tag with the tag name "colgroup" had been
5808: seen, and then, if that token wasn't ignored, reprocess the
5809: current token.</p>
5810:
5811: <p class="note">The fake end tag token here can only be
5812: ignored in the <a href="#fragment-case">fragment case</a>.</p>
5813:
5814: </dd>
5815:
5816: </dl><h5 id="parsing-main-intbody"><span class="secno">9.2.5.16 </span>The "<dfn title="insertion mode: in table body">in table body</dfn>" insertion mode</h5>
5817:
5818: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
5819: mode: in table body">in table body</a>", tokens must be handled as follows:</p>
5820:
5821: <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
5822: <dd>
5823:
5824: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
5825: context</a>. (See below.)</p>
5826:
5827: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
5828: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
5829: in row">in row</a>".</p>
5830:
5831: </dd>
5832:
5833: <dt>A start tag whose tag name is one of: "th", "td"</dt>
5834: <dd>
5835: <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
5836: the tag name "tr" had been seen, then reprocess the current
5837: token.</p>
5838: </dd>
5839:
5840: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
5841: "thead"</dt>
5842: <dd>
5843:
5844: <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
5845: scope</a> with the same tag name as the token, this is a
5846: <a href="#parse-error">parse error</a>. Ignore the token.</p>
5847:
5848: <p>Otherwise:</p>
5849:
5850: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
5851: context</a>. (See below.)</p>
5852:
5853: <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
5854: open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
5855: to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
5856:
5857: </dd>
5858:
5859: <dt>A start tag whose tag name is one of: "caption", "col",
5860: "colgroup", "tbody", "tfoot", "thead"</dt>
5861: <dt>An end tag whose tag name is "table"</dt>
5862: <dd>
5863:
5864: <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
5865: <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
5866: element in table scope</a>, this is a <a href="#parse-error">parse
5867: error</a>. Ignore the token. (<a href="#fragment-case">fragment
5868: case</a>)</p>
5869:
5870: <p>Otherwise:</p>
5871:
5872: <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
5873: context</a>. (See below.)</p>
5874:
5875: <p>Act as if an end tag with the same tag name as the
5876: <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
5877: been seen, then reprocess the current token.</p>
5878:
5879: </dd>
5880:
5881: <dt>An end tag whose tag name is one of: "body", "caption",
5882: "col", "colgroup", "html", "td", "th", "tr"</dt>
5883: <dd>
5884: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5885: </dd>
5886:
5887: <dt>Anything else</dt>
5888: <dd>
5889: <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
5890: mode</a>.</p>
5891: </dd>
5892:
5893: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
5894: back to a table body context</dfn>, it means that the UA must,
5895: while the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
5896: <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">html</a></code>
5897: element, pop elements from the <a href="#stack-of-open-elements">stack of open
5898: elements</a>.</p>
5899:
5900: <p class="note">The <a href="#current-node">current node</a> being an
5901: <code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="#fragment-case">fragment
5902: case</a>.</p>
5903:
5904:
5905: <h5 id="parsing-main-intr"><span class="secno">9.2.5.17 </span>The "<dfn title="insertion mode: in row">in row</dfn>" insertion mode</h5>
5906:
5907: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
5908: mode: in row">in row</a>", tokens must be handled as follows:</p>
5909:
5910: <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
5911: <dd>
5912:
5913: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
5914: context</a>. (See below.)</p>
5915:
5916: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
5917: the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
5918: in cell">in cell</a>".</p>
5919:
5920: <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
5921: formatting elements</a>.</p>
5922:
5923: </dd>
5924:
5925: <dt>An end tag whose tag name is "tr"</dt>
5926: <dd>
5927:
5928: <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
5929: scope</a> with the same tag name as the token, this is a
5930: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
5931: case</a>)</p>
5932:
5933: <p>Otherwise:</p>
5934:
5935: <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
5936: context</a>. (See below.)</p>
5937:
5938: <p>Pop the <a href="#current-node">current node</a> (which will be a
5939: <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
5940: elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
5941: "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
5942: body</a>".</p>
5943:
5944: </dd>
5945:
5946: <dt>A start tag whose tag name is one of: "caption", "col",
5947: "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
5948: <dt>An end tag whose tag name is "table"</dt>
5949: <dd>
5950:
5951: <p>Act as if an end tag with the tag name "tr" had been seen,
5952: then, if that token wasn't ignored, reprocess the current
5953: token.</p>
5954:
5955: <p class="note">The fake end tag token here can only be
5956: ignored in the <a href="#fragment-case">fragment case</a>.</p>
5957:
5958: </dd>
5959:
5960: <dt>An end tag whose tag name is one of: "tbody", "tfoot",
5961: "thead"</dt>
5962: <dd>
5963:
5964: <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
5965: scope</a> with the same tag name as the token, this is a
5966: <a href="#parse-error">parse error</a>. Ignore the token.</p>
5967:
5968: <p>Otherwise, act as if an end tag with the tag name "tr" had
5969: been seen, then reprocess the current token.</p>
5970:
5971: </dd>
5972:
5973: <dt>An end tag whose tag name is one of: "body", "caption",
5974: "col", "colgroup", "html", "td", "th"</dt>
5975: <dd>
5976: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
5977: </dd>
5978:
5979: <dt>Anything else</dt>
5980: <dd>
5981: <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
5982: mode</a>.</p>
5983: </dd>
5984:
5985: </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
5986: back to a table row context</dfn>, it means that the UA must,
5987: while the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tr-element">tr</a></code>
5988: element or an <code><a href="semantics.html#the-html-element">html</a></code> element, pop elements from the
5989: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
5990:
5991: <p class="note">The <a href="#current-node">current node</a> being an
5992: <code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="#fragment-case">fragment
5993: case</a>.</p>
5994:
5995:
5996: <h5 id="parsing-main-intd"><span class="secno">9.2.5.18 </span>The "<dfn title="insertion mode: in cell">in cell</dfn>" insertion mode</h5>
5997:
5998: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
5999: mode: in cell">in cell</a>", tokens must be handled as follows:</p>
6000:
6001: <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
6002: <dd>
6003:
6004: <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
6005: scope</a> with the same tag name as that of the token, then
6006: this is a <a href="#parse-error">parse error</a> and the token must be
6007: ignored.</p>
6008:
6009: <p>Otherwise:</p>
6010:
6011: <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
6012:
6013: <p>Now, if the <a href="#current-node">current node</a> is not an element
6014: with the same tag name as the token, then this is a
6015: <a href="#parse-error">parse error</a>.</p>
6016:
6017: <p>Pop elements from this stack until an element with the same
6018: tag name as the token has been popped from the stack.</p>
6019:
6020: <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
6021: the last marker</a>.</p>
6022:
6023: <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
6024: <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
6025: this point.)</p>
6026:
6027: </dd>
6028:
6029: <dt>A start tag whose tag name is one of: "caption", "col",
6030: "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
6031: <dd>
6032:
6033: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
6034: <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
6035: a <code>td</code> or <code>th</code> element in table
6036: scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
6037: the token. (<a href="#fragment-case">fragment case</a>)</p>
6038:
6039: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
6040: reprocess the current token.</p>
6041:
6042: </dd>
6043:
6044: <dt>An end tag whose tag name is one of: "body", "caption",
6045: "col", "colgroup", "html"</dt>
6046: <dd>
6047: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6048: </dd>
6049:
6050: <dt>An end tag whose tag name is one of: "table", "tbody",
6051: "tfoot", "thead", "tr"</dt>
6052: <dd>
6053:
6054: <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
6055: scope</a> with the same tag name as that of the token
6056: (which can only happen for "tbody", "tfoot" and "thead", or,
6057: in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
6058: error</a> and the token must be ignored.</p>
6059:
6060: <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
6061: reprocess the current token.</p>
6062:
6063: </dd>
6064:
6065: <dt>Anything else</dt>
6066: <dd>
6067: <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
6068: mode</a>.</p>
6069: </dd>
6070:
6071: </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
6072: mean to run the following algorithm:</p>
6073:
6074: <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>
6075: element in table scope</a>, then act as if an end tag token
6076: with the tag name "td" had been seen.</p></li>
6077:
6078: <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
6079: <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
6080: <code>th</code> element in table scope</a>; act as if an end
6081: tag token with the tag name "th" had been seen.</p></li>
6082:
6083: </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
6084: 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
6085: the same time, nor can it have neither when the <a href="#insertion-mode">insertion
6086: mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
6087: cell</a>".</p>
6088:
6089:
6090: <h5 id="parsing-main-inselect"><span class="secno">9.2.5.19 </span>The "<dfn title="insertion mode: in select">in select</dfn>" insertion mode</h5>
6091:
6092: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
6093: mode: in select">in select</a>", tokens must be handled as follows:</p>
6094:
6095: <dl class="switch"><dt>A character token</dt>
6096: <dd>
6097: <p><a href="#insert-a-character" title="insert a character">Insert the token's
6098: character</a> into the <a href="#current-node">current node</a>.</p>
6099: </dd>
6100:
6101: <dt>A comment token</dt>
6102: <dd>
6103: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6104: node</a> with the <code title="">data</code> attribute set to
6105: the data given in the comment token.</p>
6106: </dd>
6107:
6108: <dt>A DOCTYPE token</dt>
6109: <dd>
6110: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6111: </dd>
6112:
6113: <dt>A start tag whose tag name is "html"</dt>
6114: <dd>
6115: <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
6116: mode</a>.</p>
6117: </dd>
6118:
6119: <dt>A start tag whose tag name is "option"</dt>
6120: <dd>
6121:
6122: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6123: element, act as if an end tag with the tag name "option" had
6124: been seen.</p>
6125:
6126: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6127:
6128: </dd>
6129:
6130: <dt>A start tag whose tag name is "optgroup"</dt>
6131: <dd>
6132:
6133: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6134: element, act as if an end tag with the tag name "option" had
6135: been seen.</p>
6136:
6137: <p>If the <a href="#current-node">current node</a> is an
6138: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
6139: tag name "optgroup" had been seen.</p>
6140:
6141: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6142:
6143: </dd>
6144:
6145: <dt>An end tag whose tag name is "optgroup"</dt>
6146: <dd>
6147:
6148: <p>First, if the <a href="#current-node">current node</a> is an
6149: <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
6150: it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
6151: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
6152: the tag name "option" had been seen.</p>
6153:
6154: <p>If the <a href="#current-node">current node</a> is an
6155: <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
6156: <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
6157: <a href="#parse-error">parse error</a>; ignore the token.</p>
6158:
6159: </dd>
6160:
6161: <dt>An end tag whose tag name is "option"</dt>
6162: <dd>
6163:
6164: <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
6165: element, then pop that node from the <a href="#stack-of-open-elements">stack of open
6166: elements</a>. Otherwise, this is a <a href="#parse-error">parse
6167: error</a>; ignore the token.</p>
6168:
6169: </dd>
6170:
6171: <dt>An end tag whose tag name is "select"</dt>
6172: <dd>
6173:
6174: <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
6175: scope</a> with the same tag name as the token, this is a
6176: <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
6177: case</a>)</p>
6178:
6179: <p>Otherwise:</p>
6180:
6181: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
6182: until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
6183: stack.</p>
6184:
6185: <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
6186:
6187: </dd>
6188:
6189: <dt>A start tag whose tag name is "select"</dt>
6190: <dd>
6191:
6192: <p><a href="#parse-error">Parse error</a>. Act as if the token had been
6193: an end tag with the tag name "select" instead.</p>
6194:
6195: </dd>
6196:
6197: <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
6198: <dd>
1.73 mike 6199:
6200: <p><a href="#parse-error">Parse error</a>.</p>
6201:
1.124 mike 6202: <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>
6203: element in table scope</a>, ignore the token. (<a href="#fragment-case">fragment
6204: case</a>)</p>
1.73 mike 6205:
6206: <p>Otherwise, act as if an end tag with the tag name "select" had
6207: been seen, and reprocess the token.</p>
6208:
1.1 mike 6209: </dd>
6210:
6211: <dt>A start tag token whose tag name is "script"</dt>
6212: <dd>
6213: <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
6214: mode</a>.</p>
6215: </dd>
6216:
6217: <dt>An end-of-file token</dt>
6218: <dd>
6219:
6220: <p>If the <a href="#current-node">current node</a> is not the root
6221: <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
6222: error</a>.</p>
6223:
6224: <p class="note">It can only be the <a href="#current-node">current node</a> in
6225: the <a href="#fragment-case">fragment case</a>.</p>
6226:
6227: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6228:
6229: </dd>
6230:
6231: <dt>Anything else</dt>
6232: <dd>
6233: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6234: </dd>
6235:
6236: </dl><h5 id="parsing-main-inselectintable"><span class="secno">9.2.5.20 </span>The "<dfn title="insertion mode: in select in table">in select in table</dfn>" insertion mode</h5>
6237:
6238: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
6239: mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
6240:
6241: <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
6242: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
6243: <dd>
6244: <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
6245: name "select" had been seen, and reprocess the token.</p>
6246: </dd>
6247:
6248: <dt>An end tag whose tag name is one of: "caption", "table",
6249: "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
6250: <dd>
6251:
6252: <p><a href="#parse-error">Parse error</a>.</p>
6253:
6254: <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
6255: element in table scope</a> with the same tag name as that
6256: of the token, then act as if an end tag with the tag name
6257: "select" had been seen, and reprocess the token. Otherwise,
6258: ignore the token.</p>
6259:
6260: </dd>
6261:
6262: <dt>Anything else</dt>
6263: <dd>
6264: <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
6265: mode</a>.</p>
6266: </dd>
6267:
6268: </dl><h5 id="parsing-main-inforeign"><span class="secno">9.2.5.21 </span>The "<dfn title="insertion mode: in foreign content">in foreign content</dfn>" insertion mode</h5>
6269:
6270: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
6271: mode: in foreign content">in foreign content</a>", tokens must be
6272: handled as follows:</p>
6273:
6274: <dl class="switch"><dt>A character token</dt>
6275: <dd>
6276:
6277: <p><a href="#insert-a-character" title="insert a character">Insert the token's
6278: character</a> into the <a href="#current-node">current node</a>.</p>
6279:
6280: <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
6281: LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
6282: (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
6283: flag</a> to "not ok".</p>
6284:
6285: </dd>
6286:
6287: <dt>A comment token</dt>
6288: <dd>
6289: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6290: node</a> with the <code title="">data</code> attribute set to
6291: the data given in the comment token.</p>
6292: </dd>
6293:
6294: <dt>A DOCTYPE token</dt>
6295: <dd>
6296: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6297: </dd>
6298:
6299: <dt>An end tag whose tag name is "script", if the <a href="#current-node">current node</a> is a <code title="">script</code> element in the <a href="#svg-namespace">SVG namespace</a>.</dt>
6300: <dd>
6301:
6302: <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6303: elements</a>.</p>
6304:
6305: <p>Let the <var title="">old insertion point</var> have the
6306: same value as the current <a href="#insertion-point">insertion point</a>. Let
6307: the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
6308: input character</a>.</p>
6309:
6310: <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
6311: one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
6312:
6313: <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
6314: the <code title="">script</code> element</a> according to the SVG
1.104 mike 6315: rules. <a href="references.html#refsSVG">[SVG]</a></p>
1.1 mike 6316:
6317: <p class="note">Even if this causes <a href="dom.html#dom-document-write" title="dom-document-write">new characters to be inserted into the
6318: tokenizer</a>, the parser will not be executed reentrantly,
6319: since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
6320:
6321: <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
6322: one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
6323: then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
6324:
6325: <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
6326: <a href="#insertion-point">insertion point</a> to its previous value. This value
6327: might be the "undefined" value.)</p>
6328:
6329: </dd>
6330:
6331: <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">mi</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
6332: <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">mo</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
6333: <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">mn</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
6334: <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">ms</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
6335: <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">mtext</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
6336: <dt>A start tag whose tag name is "svg", if the <a href="#current-node">current node</a> is an <code title="">annotation-xml</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
6337: <dt>A start tag, if the <a href="#current-node">current node</a> is a <code title="">foreignObject</code> element in the <a href="#svg-namespace">SVG namespace</a>.</dt>
6338: <dt>A start tag, if the <a href="#current-node">current node</a> is a <code title="">desc</code> element in the <a href="#svg-namespace">SVG namespace</a>.</dt>
6339: <dt>A start tag, if the <a href="#current-node">current node</a> is a <code title="">title</code> element in the <a href="#svg-namespace">SVG namespace</a>.</dt>
6340: <dt>A start tag, if the <a href="#current-node">current node</a> is an element in the <a href="#html-namespace-0">HTML namespace</a>.</dt>
6341: <dt>An end tag</dt>
6342: <dd>
6343:
6344: <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
6345: <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
6346:
6347: <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
6348: "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
6349: content</a>", but there is no element in scope that has a
6350: namespace other than the <a href="#html-namespace-0">HTML namespace</a><!-- XXX this
6351: isn't well-defined; it means check to see if the bottom-most HTML
6352: element on the stack is in scope -->, switch the <a href="#insertion-mode">insertion
6353: mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
6354:
6355: </dd>
6356:
6357: <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
6358: "blockquote", "body"<!--by inspection-->, "br", "center", "code",
6359: "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
6360: uniformly throughout the parser -->, "em", "embed", "h1", "h2",
6361: "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
6362: completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
6363: "li", "listing"<!-- so that pre and listing can be handled
6364: uniformly throughout the parser -->, "menu", "meta", "nobr",
6365: "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
6366: the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
6367: "span", "strong", "strike"<!-- so that s and strike can be handled
6368: uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
6369: "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt>
6370: <!-- this list was determined empirically by studying over
6371: 6,000,000,000 pages that were specifically not XML pages -->
6372: <dt>A start tag whose tag name is "font", if the token has
6373: any attributes named "color", "face", or "size"</dt>
6374: <!-- the attributes here are required so that SVG <font> will go
6375: through as SVG but legacy <font>s won't -->
6376: <dt>An end-of-file token</dt>
6377: <dd>
6378:
6379: <p><a href="#parse-error">Parse error</a>.</p>
6380:
6381: <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
6382: the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
6383: namespace</a>.</p>
6384:
6385: <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
6386: insertion mode</a>, and reprocess the token.</p>
6387:
6388: </dd>
6389:
6390: <dt>Any other start tag</dt>
6391: <dd>
6392:
6393: <p>If the <a href="#current-node">current node</a> is an element in the
6394: <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
6395: attributes</a> for the token. (This fixes the case of MathML
6396: attributes that are not all lowercase.)</p>
6397:
6398: <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
6399: namespace</a>, and the token's tag name is one of the ones in
6400: the first column of the following table, change the tag name to
6401: the name given in the corresponding cell in the second
6402: column. (This fixes the case of SVG elements that are not all
6403: lowercase.)</p>
6404:
6405: <table><thead><tr><th> Tag name </th><th> Element name
6406: </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
6407: </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
6408: </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
6409: </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
6410: </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
6411: </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
6412: </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
6413: </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
6414: </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
6415: </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
6416: </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
6417: </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
6418: </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
6419: </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
6420: </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
6421: </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
6422: </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
6423: </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
6424: </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
6425: </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
6426: </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
6427: </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
6428: </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
6429: </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
6430: </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
6431: </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
6432: </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
6433: </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
6434: </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
6435: </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
6436: </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
6437: </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
6438: </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
6439: </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
6440: </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
6441: <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
6442: </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
6443: </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
6444: namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
6445: token. (This fixes the case of SVG attributes that are not all
6446: lowercase.)</p>
6447:
6448: <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
6449: fixes the use of namespaced attributes, in particular XLink in
6450: SVG.)</p>
6451:
6452: <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
6453: same namespace as the <a href="#current-node">current node</a>.</p>
6454:
6455: <p>If the token has its <i>self-closing flag</i> set, pop the
6456: <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
6457: elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
6458: flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
6459:
6460: </dd>
6461:
6462: </dl><h5 id="parsing-main-afterbody"><span class="secno">9.2.5.22 </span>The "<dfn title="insertion mode: after body">after body</dfn>" insertion mode</h5>
6463:
6464: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
6465: mode: after body">after body</a>", tokens must be handled as follows:</p>
6466:
6467: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6468: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6469: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6470: <dd>
6471: <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
6472: mode</a>.</p>
6473: </dd>
6474:
6475: <dt>A comment token</dt>
6476: <dd>
6477: <p>Append a <code>Comment</code> node to the first element in
6478: the <a href="#stack-of-open-elements">stack of open elements</a> (the <code><a href="semantics.html#the-html-element">html</a></code>
6479: element), with the <code title="">data</code> attribute set to
6480: the data given in the comment token.</p>
6481: </dd>
6482:
6483: <dt>A DOCTYPE token</dt>
6484: <dd>
6485: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6486: </dd>
6487:
6488: <dt>A start tag whose tag name is "html"</dt>
6489: <dd>
6490: <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
6491: mode</a>.</p>
6492: </dd>
6493:
6494: <dt>An end tag whose tag name is "html"</dt>
6495: <dd>
6496:
6497: <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
6498: fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
6499: error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
6500:
6501: <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
6502: body</a>".</p>
6503:
6504: </dd>
6505:
6506: <dt>An end-of-file token</dt>
6507: <dd>
6508: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6509: </dd>
6510:
6511: <dt>Anything else</dt>
6512: <dd>
6513:
6514: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
6515: mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
6516: body</a>" and reprocess the token.</p>
6517:
6518: </dd>
6519:
6520: </dl><h5 id="parsing-main-inframeset"><span class="secno">9.2.5.23 </span>The "<dfn title="insertion mode: in frameset">in frameset</dfn>" insertion mode</h5>
6521:
6522: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
6523: mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
6524:
6525: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6526: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6527: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6528: <dd>
6529: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6530: the <a href="#current-node">current node</a>.</p>
6531: </dd>
6532:
6533: <dt>A comment token</dt>
6534: <dd>
6535: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6536: node</a> with the <code title="">data</code> attribute set to
6537: the data given in the comment token.</p>
6538: </dd>
6539:
6540: <dt>A DOCTYPE token</dt>
6541: <dd>
6542: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6543: </dd>
6544:
6545: <dt>A start tag whose tag name is "html"</dt>
6546: <dd>
6547: <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
6548: mode</a>.</p>
6549: </dd>
6550:
6551: <dt>A start tag whose tag name is "frameset"</dt>
6552: <dd>
6553: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
6554: </dd>
6555:
6556: <dt>An end tag whose tag name is "frameset"</dt>
6557: <dd>
6558:
6559: <p>If the <a href="#current-node">current node</a> is the root
6560: <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
6561: error</a>; ignore the token. (<a href="#fragment-case">fragment
6562: case</a>)</p>
6563:
6564: <p>Otherwise, pop the <a href="#current-node">current node</a> from the
6565: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6566:
6567: <p>If the parser was <em>not</em> originally created as part
6568: of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
6569: (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5 mike 6570: node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1 mike 6571: switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
6572: frameset</a>".</p>
6573:
6574: </dd>
6575:
6576: <dt>A start tag whose tag name is "frame"</dt>
6577: <dd>
6578:
6579: <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
6580: Immediately pop the <a href="#current-node">current node</a> off the
6581: <a href="#stack-of-open-elements">stack of open elements</a>.</p>
6582:
6583: <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
6584: token's <i>self-closing flag</i></a>, if it is set.</p>
6585:
6586: </dd>
6587:
6588: <dt>A start tag whose tag name is "noframes"</dt>
6589: <dd>
6590: <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
6591: mode</a>.</p>
6592: </dd>
6593:
6594: <dt>An end-of-file token</dt>
6595: <dd>
6596:
6597: <p>If the <a href="#current-node">current node</a> is not the root
6598: <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
6599: error</a>.</p>
6600:
6601: <p class="note">It can only be the <a href="#current-node">current node</a> in
6602: the <a href="#fragment-case">fragment case</a>.</p>
6603:
6604: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6605:
6606: </dd>
6607:
6608: <dt>Anything else</dt>
6609: <dd>
6610: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6611: </dd>
6612:
6613: </dl><h5 id="parsing-main-afterframeset"><span class="secno">9.2.5.24 </span>The "<dfn title="insertion mode: after frameset">after frameset</dfn>" insertion mode</h5>
6614:
6615: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
6616: mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
6617:
6618: <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
6619: <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
6620: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6621: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6622: <dd>
6623: <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
6624: the <a href="#current-node">current node</a>.</p>
6625: </dd>
6626:
6627: <dt>A comment token</dt>
6628: <dd>
6629: <p>Append a <code>Comment</code> node to the <a href="#current-node">current
6630: node</a> with the <code title="">data</code> attribute set to
6631: the data given in the comment token.</p>
6632: </dd>
6633:
6634: <dt>A DOCTYPE token</dt>
6635: <dd>
6636: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6637: </dd>
6638:
6639: <dt>A start tag whose tag name is "html"</dt>
6640: <dd>
6641: <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
6642: mode</a>.</p>
6643: </dd>
6644:
6645: <dt>An end tag whose tag name is "html"</dt>
6646: <dd>
6647: <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
6648: frameset</a>".</p>
6649: </dd>
6650:
6651: <dt>A start tag whose tag name is "noframes"</dt>
6652: <dd>
6653: <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
6654: mode</a>.</p>
6655: </dd>
6656:
6657: <dt>An end-of-file token</dt>
6658: <dd>
6659: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6660: </dd>
6661:
6662: <dt>Anything else</dt>
6663: <dd>
6664: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6665: </dd>
6666:
6667: </dl><p class="XXX">This doesn't handle UAs that don't support
6668: frames, or that do support frames but want to show the NOFRAMES
6669: content. Supporting the former is easy; supporting the latter is
6670: harder.</p>
6671:
6672:
6673: <h5 id="the-after-after-body-insertion-mode"><span class="secno">9.2.5.25 </span>The "<dfn title="insertion mode: after after body">after after body</dfn>" insertion mode</h5>
6674:
6675: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
6676: mode: after after body">after after body</a>", tokens must be handled as follows:</p>
6677:
6678: <dl class="switch"><dt>A comment token</dt>
6679: <dd>
6680: <p>Append a <code>Comment</code> node to the <code>Document</code>
6681: object with the <code title="">data</code> attribute set to the
6682: data given in the comment token.</p>
6683: </dd>
6684:
6685: <dt>A DOCTYPE token</dt>
6686: <dt>A character token that is one of U+0009 CHARACTER
6687: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6688: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6689: <dt>A start tag whose tag name is "html"</dt>
6690: <dd>
6691: <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
6692: mode</a>.</p>
6693: </dd>
6694:
6695: <dt>An end-of-file token</dt>
6696: <dd>
6697: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6698: </dd>
6699:
6700: <dt>Anything else</dt>
6701: <dd>
6702: <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
6703: to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
6704: reprocess the token.</p>
6705: </dd>
6706:
6707: </dl><h5 id="the-after-after-frameset-insertion-mode"><span class="secno">9.2.5.26 </span>The "<dfn title="insertion mode: after after frameset">after after frameset</dfn>" insertion mode</h5>
6708:
6709: <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
6710: mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
6711:
6712: <dl class="switch"><dt>A comment token</dt>
6713: <dd>
6714: <p>Append a <code>Comment</code> node to the <code>Document</code>
6715: object with the <code title="">data</code> attribute set to the
6716: data given in the comment token.</p>
6717: </dd>
6718:
6719: <dt>A DOCTYPE token</dt>
6720: <dt>A character token that is one of U+0009 CHARACTER
6721: TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
6722: <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
6723: <dt>A start tag whose tag name is "html"</dt>
6724: <dd>
6725: <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
6726: mode</a>.</p>
6727: </dd>
6728:
6729: <dt>An end-of-file token</dt>
6730: <dd>
6731: <p><a href="#stop-parsing">Stop parsing</a>.</p>
6732: </dd>
6733:
6734: <dt>A start tag whose tag name is "noframes"</dt>
6735: <dd>
6736: <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
6737: mode</a>.</p>
6738: </dd>
6739:
6740: <dt>Anything else</dt>
6741: <dd>
6742: <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
6743: </dd>
6744:
6745: </dl><h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4>
6746:
6747: <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
6748: the document, the user agent must follow the steps in this
6749: section.</p>
6750:
1.10 mike 6751: <!-- this happens as part of one of the tasks that runs the parser -->
1.1 mike 6752:
1.10 mike 6753: <p>First, the user agent must set the <a href="dom.html#current-document-readiness">current document
6754: readiness</a> to "interactive" and the <a href="#insertion-point">insertion
6755: point</a> to undefined.</p>
6756:
6757: <p>Then, the user agent must then make a list of all the scripts
6758: that are in the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the
6759: document has finished parsing</a>, the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that
6760: will execute asynchronously</a>, and the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts
6761: that will execute as soon as possible</a>. This is the <dfn id="list-of-scripts-pending-after-the-parser-stopped">list
6762: of scripts pending after the parser stopped</dfn>.</p>
6763:
6764: <p>The rules for <a href="semantics.html#when-a-script-completes-loading">when a script completes loading</a> start
6765: applying (script execution is no longer managed by the parser).</p>
1.1 mike 6766:
6767: <p>If any of the scripts in the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will
6768: execute as soon as possible</a> have <a href="semantics.html#completed-loading">completed
6769: loading</a>, or if the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that will execute
6770: asynchronously</a> is not empty and the first script in that list
6771: has <a href="semantics.html#completed-loading">completed loading</a>, then the user agent must act as
6772: if those scripts just completed loading, following the rules given
6773: for that in the <code><a href="semantics.html#script">script</a></code> element definition.</p>
6774:
1.10 mike 6775: <p>If the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the document
6776: has finished parsing</a> is not empty, and the first item in this
6777: list has already <a href="semantics.html#completed-loading">completed loading</a>, then the user agent
6778: must act as if that script just finished loading.</p>
6779:
6780: <p class="note">By this point, there will be no scripts that have
6781: loaded but have not yet been executed.</p>
6782:
6783: <hr><!-- async --><p>Once all the scripts on the <a href="#list-of-scripts-pending-after-the-parser-stopped">list of scripts pending after
6784: the parser stopped</a> have <a href="semantics.html#completed-loading">completed loading</a> and
6785: been <a href="semantics.html#executing-a-script-block" title="executing a script block">executed</a>, the
6786: user agent must <a href="browsers.html#queue-a-task">queue a task</a> to <a href="browsers.html#fire-a-simple-event">fire a simple
6787: event</a> called <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
6788: <code>Document</code>. (If the list is empty, this happens
6789: immediately.)</p>
1.1 mike 6790:
1.10 mike 6791: <hr><!-- async --><p>Once everything that <dfn id="delay-the-load-event" title="delay the load event">delays the
1.1 mike 6792: load event</dfn> of the document has completed, the user agent must
6793: run the following steps:</p>
6794:
6795: <ol><li><a href="browsers.html#queue-a-task">Queue a task</a> to set the <a href="dom.html#current-document-readiness">current document
6796: readiness</a> to "complete".</li>
6797:
6798: <li>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
6799: context</a>, then <a href="browsers.html#queue-a-task">queue a task</a> to <a href="browsers.html#fire-a-simple-event">fire a
6800: simple event</a> called <code title="event-load"><a href="video.html#event-load">load</a></code> at
6801: the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
6802: its <code title="dom-event-target">target</code> set to the
6803: <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
6804: <code><a href="browsers.html#window">Window</a></code> object).</li>
6805:
6806: <li>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
6807: object</a>, then <a href="browsers.html#queue-a-task">queue a task</a> to fire a <code title="event-popstate"><a href="history.html#event-popstate">popstate</a></code> event in no namespace on the
6808: <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
6809: <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
6810: current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
6811: must bubble but not be cancelable and has no default action.</li>
6812:
6813: </ol><p>The <a href="browsers.html#task-source">task source</a> for these tasks is the <a href="browsers.html#dom-manipulation-task-source">DOM
6814: manipulation task source</a>.</p>
6815:
6816: <!-- XXX make sure things "delay the load event", e.g. applet and
6817: object element's frame contents -->
6818:
6819: <p class="XXX">delaying the load event for things like image
6820: loads allows for intranet port scans (even without
6821: javascript!). Should we really encode that into the spec?</p>
6822:
6823:
6824: <!--XXX need to handle
6825: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#2354
6826: 2354 // Don't open transient styles if it makes the stack deep, bug 58917.
6827: -->
6828:
6829: <!--XXX
6830: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/nsHTMLTokenizer.cpp#749
6831: -->
6832:
6833: <!--
6834: see also CTextToken::ConsumeCharacterData() for CDATA parsing?
6835:
6836: 1212 1 Here's a tricky case from bug 22596: <h5><li><h5>
6837: 1213 How do we know that the 2nd <h5> should close the <LI> rather than nest inside the <LI>?
6838: 1214 (Afterall, the <h5> is a legal child of the <LI>).
6839: 1215
6840: 1216 The way you know is that there is no root between the two, so the <h5> binds more
6841: 1217 tightly to the 1st <h5> than to the <LI>.
6842: 1218 2. Also, bug 6148 shows this case: <SPAN><DIV><SPAN>
6843: 1219 From this case we learned not to execute this logic if the parent is a block.
6844: 1220
6845: 1221 3. Fix for 26583
6846: 1222 Ex. <A href=foo.html><B>foo<A href-bar.html>bar</A></B></A> <- A legal HTML
6847: 1223 In the above example clicking on "foo" or "bar" should link to
6848: 1224 foo.html or bar.html respectively. That is, the inner <A> should be informed
6849: 1225 about the presence of an open <A> above <B>..so that the inner <A> can close out
6850: 1226 the outer <A>. The following code does it for us.
6851: 1227
6852: 1228 4. Fix for 27865 [ similer to 22596 ]. Ex: <DL><DD><LI>one<DD><LI>two
6853: - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1211
6854:
6855: 815 // Here's a problem. If theTag is legal in here, we don't move it
6856: 816 // out. So if we're moving stuff out of here, the parent of theTag
6857: 817 // gets closed at this point. But some things are legal
6858: 818 // _everywhere_ and hence would effectively close out misplaced
6859: 819 // content in tables. This is undesirable, so treat them as
6860: 820 // illegal here so they'll be shipped out with their parents and
6861: 821 // siblings. See bug 40855 for an explanation (that bug was for
6862: 822 // comments, but the same issues arise with whitespace, newlines,
6863: 823 // noscript, etc). Script is special, though. Shipping it out
6864: 824 // breaks document.write stuff. See bug 243064.
6865: - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#825
6866:
6867:
6868: 1326 /**************************************************************************************
6869: 1327 *
6870: 1328 * Now a little code to deal with bug #49687 (crash when layout stack gets too deep)
6871: 1329 * I've also opened this up to any container (not just inlines): re bug 55095
6872: 1330 * Improved to handle bug 55980 (infinite loop caused when DEPTH is exceeded and
6873: 1331 * </P> is encountered by itself (<P>) is continuously produced.
6874: 1332 *
6875: 1333 **************************************************************************************/
6876:
6877: 1912 // Oh boy!! we found a "stray" tag. Nav4.x and IE introduce line break in
6878: 1913 // such cases. So, let's simulate that effect for compatibility.
6879: 1914 // Ex. <html><body>Hello</P>There</body></html>
6880: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1912
6881:
6882: http://lxr.mozilla.org/seamonkey/search?string=nested
6883: /parser/htmlparser/src/CNavDTD.cpp, line 791 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
6884: /parser/htmlparser/src/CNavDTD.cpp, line 792 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
6885: /parser/htmlparser/src/CNavDTD.cpp, line 2562 - // Discard nested forms - bug 72639
6886: /parser/htmlparser/src/nsElementTable.cpp, line 1453 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
6887: /parser/htmlparser/src/nsElementTable.cpp, line 1454 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
6888: /parser/htmlparser/src/nsElementTable.cpp, line 1901 - // Ex: <H1><LI><H1><LI>. Inner LI has the potential of getting nested
6889: -->
6890:
6891:
6892: <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4>
6893:
6894: <p>When an application uses an <a href="#html-parser">HTML parser</a> in
6895: conjunction with an XML pipeline, it is possible that the
6896: constructed DOM is not compatible with the XML tool chain in certain
6897: subtle ways. For example, an XML toolchain might not be able to
6898: represent attributes with the name <code title="">xmlns</code>,
6899: since they conflict with the Namespaces in XML syntax. There is also
6900: some data that the <a href="#html-parser">HTML parser</a> generates that isn't
6901: included in the DOM itself. This section specifies some rules for
6902: handling these issues.</p>
6903:
6904: <p>If the XML API being used doesn't support DOCTYPEs, the tool may
6905: drop DOCTYPEs altogether.</p>
6906:
6907: <p>If the XML API doesn't support attributes in no namespace that
6908: are named "<code title="">xmlns</code>", attributes whose names
6909: start with "<code title="">xmlns:</code>", or attributes in the
6910: <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
6911: attributes.</p>
6912:
6913: <p>The tool may annotate the output with any namespace declarations
6914: required for proper operation.</p>
6915:
6916: <p>If the XML API being used restricts the allowable characters in
6917: the local names of elements and attributes, then the tool may map
6918: all element and attribute local names that the API wouldn't support
6919: to a set of names that <em>are</em> allowed, by replacing any
6920: character that isn't supported with the uppercase letter U and the
6921: six digits of the character's Unicode code point when expressed in
6922: hexadecimal, using digits 0-9 and capital letters A-F as the
6923: symbols, in increasing numeric order.</p>
6924:
6925: <p class="example">For example, the element name <code title="">foo<bar</code>, which can be output by the <a href="#html-parser">HTML
6926: parser</a>, though it is neither a legal HTML element name nor a
6927: well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
6928: element name (though it's still not legal in HTML by any means).</p>
6929:
6930: <p class="example">As another example, consider the attribute
6931: <code>xlink:href</code>. Used on a MathML element, it becomes, after
6932: being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
6933: attribute with a prefix "<code title="">xlink</code>" and a local
6934: name "<code title="">href</code>". However, used on an HTML element,
6935: it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
6936: might not be accepted by an XML API. It could thus get converted,
6937: becoming "<code title="">xlinkU00003Ahref</code>".</p>
6938:
6939: <p class="note">The resulting names from this conversion
6940: conveniently can't clash with any attribute generated by the
6941: <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
6942: those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
6943: algorithm's table.</p>
6944:
6945: <p>If the XML API restricts comments from having two consecutive
6946: U+002D HYPHEN-MINUS characters (--), the tool may insert a single
6947: U+0020 SPACE character between any such offending characters.</p>
6948:
6949: <p>If the XML API restricts comments from ending in a
6950: U+002D HYPHEN-MINUS character (-), the tool may insert a single
6951: U+0020 SPACE character at the end of such comments.</p>
6952:
6953: <p>If the XML API restricts allowed characters in character data,
6954: the tool may replace any U+000C FORM FEED (FF) character with a
6955: U+0020 SPACE character, and any other literal non-XML character with
6956: a U+FFFD REPLACEMENT CHARACTER.</p>
6957:
6958: <p>If the tool has no way to convey out-of-band information, then
6959: the tool may drop the following information:</p>
6960:
6961: <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
6962: <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>
6963:
6964: <li>The association between form controls and forms that aren't
6965: their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
6966: <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
6967:
6968: </ul><p class="note">The mutations allowed by this section apply
6969: <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
6970: applied. For example, a <code title=""><a::></code> start tag
6971: will be closed by a <code title=""></a::></code> end tag, and
6972: never by a <code title=""></aU00003AU00003A></code> end tag, even
6973: if the user agent is using the rules above to then generate an
6974: actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
6975:
6976:
6977:
1.35 mike 6978: <h4 id="an-introduction-to-error-handling-and-strange-cases-in-the-parser"><span class="secno">9.2.8 </span>An introduction to error handling and strange cases in the parser</h4>
1.1 mike 6979:
6980: <p><i>This section is non-normative.</i></p>
6981:
6982: <p>This section examines some erroneous markup and discusses how
6983: the <a href="#html-parser">HTML parser</a> handles these cases.</p>
6984:
6985:
6986: <h5 id="misnested-tags:-b-i-b-i"><span class="secno">9.2.8.1 </span>Misnested tags: <b><i></b></i></h5>
6987:
6988: <p><i>This section is non-normative.</i></p>
6989:
6990: <p>The most-often discussed example of erroneous markup is as
6991: follows:</p>
6992:
6993: <pre><p>1<b>2<i>3</b>4</i>5</p></pre>
6994:
6995: <p>The parsing of this markup is straightforward up to the "3". At
6996: this point, the DOM looks like this:</p>
6997:
6998: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">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
6999: on it: <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>,
7000: <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
7001: formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
7002: <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>
7003:
7004: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
7005: invoked. This is a simple case, in that the <var title="">formatting
7006: element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
7007: <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
7008: elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element">html</a></code>,
7009: <code><a href="semantics.html#the-body-element">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
7010: active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
7011: DOM tree is unmodified at this point.</p>
7012:
7013: <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
7014: the active formatting elements</a>, in this case just the
7015: <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
7016: for the "4" text node. After the end tag token for the "i" is also
7017: received, and the "5" text node is inserted, the DOM looks as
7018: follows:</p>
7019:
7020: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">4</span></li></ul></li><li class="t3"><code>#text</code>: <span title="">5</span></li></ul></li></ul></li></ul></li></ul><h5 id="misnested-tags:-b-p-b-p"><span class="secno">9.2.8.2 </span>Misnested tags: <b><p></b></p></h5>
7021:
7022: <p><i>This section is non-normative.</i></p>
7023:
7024: <p>A case similar to the previous one is the following:</p>
7025:
7026: <pre><b>1<p>2</b>3</p></pre>
7027:
7028: <p>Up to the "2" the parsing here is straightforward:</p>
7029:
7030: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">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
7031: "b" is parsed.</p>
7032:
7033: <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
7034: elements</a> has four elements on it: <code><a href="semantics.html#the-html-element">html</a></code>,
7035: <code><a href="semantics.html#the-body-element">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
7036: <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
7037: <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>
7038:
7039: <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
7040: in the previous example. However, in this case, there <em>is</em> a
7041: <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
7042: this time the adoption agency algorithm isn't skipped over.</p>
7043:
7044: <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element">body</a></code>
7045: element. A conceptual "bookmark" marks the position of the
7046: <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
7047: elements</a>, but since that list has only one element in it,
7048: it won't have much effect.</p>
7049:
7050: <p>As the algorithm progresses, <var title="">node</var> ends up set
7051: to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
7052: node</var> ends up set to the <var title="">furthest block</var>
7053: (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
7054:
7055: <p>The <var title="">last node</var> gets appended (moved) to the
7056: <var title="">common ancestor</var>, so that the DOM looks like:</p>
7057:
7058: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">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
7059: <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
7060:
7061: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">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
7062: <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
7063:
7064: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">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
7065: active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
7066: elements</a>, so that when the "3" is parsed, it is appended to
7067: the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
7068:
7069: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li></ul></li></ul><h5 id="unexpected-markup-in-tables"><span class="secno">9.2.8.3 </span>Unexpected markup in tables</h5>
7070:
7071: <p><i>This section is non-normative.</i></p>
7072:
7073: <p>Error handling in tables is, for historical reasons, especially
7074: strange. For example, consider the following markup:</p>
7075:
7076: <pre><table><strong><b></strong><tr><td>aaa</td></tr><strong>bbb</strong></table>ccc</pre>
7077:
7078: <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
7079: directly inside a table like that, and the parser handles this case
7080: 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
7081: examining the DOM tree as it stands just after the
7082: <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
7083:
7084: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">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
7085: tag has been seen:</p>
7086:
7087: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">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
7088: the elements <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>,
7089: <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
7090: resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
7091: elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
7092: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
7093: table">in table</a>".</p>
7094:
7095: <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
7096: to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
7097: 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
7098: then handled in a rather straight-forward manner, taking the parser
7099: through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
7100: body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
7101: row</a>" insertion modes, after which the DOM looks as
7102: follows:</p>
7103:
7104: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">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
7105: elements <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
7106: <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
7107: formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
7108: it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
7109: mode: in row">in row</a>".</p>
7110:
7111: <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
7112: <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
7113: 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
7114: mode</a>).</p>
7115:
7116: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">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,
7117: no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
7118: node:</p>
7119:
7120: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">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
7121: handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
7122: elements <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
7123: 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
7124: elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
7125: marker having been removed by the "td" end tag token); and the
7126: <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
7127: table body">in table body</a>".</p>
7128:
7129: <p>Thus it is that the "bbb" character tokens are found. These
7130: trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
7131: text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
7132: insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
7133: body">in table body</a>"). The character tokens are collected,
7134: and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
7135: seen, they are processed as a group. Since they are not all spaces,
7136: 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,
7137: which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
7138: body</a>" insertion mode but with <a href="#foster-parent" title="foster
7139: parent">foster parenting</a>.</p>
7140:
7141: <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
7142: active formatting elements are reconstructed</a>, a
7143: <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
7144: parent">foster parented</a>, and then the "bbb" text node is
7145: appended to it:</p>
7146:
7147: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">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
7148: <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
7149: <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
7150: this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
7151: formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
7152: and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
7153: mode: in table body">in table body</a>".</p>
7154:
7155: <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
7156: character">space characters</a> instead of "bbb", then those
7157: <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
7158: appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
7159:
7160: <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
7161: tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
7162: elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
7163: but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
7164: elements</a>, so the "ccc" character tokens after the table
7165: result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
7166: time after the table:</p>
7167:
7168: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">bbb</span></li></ul></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">ccc</span></li></ul></li></ul></li></ul></li></ul><h5 id="scripts-that-modify-the-page-as-it-is-being-parsed"><span class="secno">9.2.8.4 </span>Scripts that modify the page as it is being parsed</h5>
7169:
7170: <p><i>This section is non-normative.</i></p>
7171:
7172: <p>Consider the following markup, which for this example we will
7173: assume is the document with <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/inner</code>, being rendered as the
7174: content of an <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code> in another document with the
7175: <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
7176:
7177: <pre><div id=a>
7178: <script>
7179: var div = document.getElementById('a');
7180: parent.document.body.appendChild(div);
7181: </script>
7182: <script>
7183: alert(document.URL);
7184: </script>
7185: </div>
7186: <script>
7187: alert(document.URL);
7188: </script></pre>
7189:
7190: <p>Up to the first "script" end tag, before the script is parsed,
7191: the result is relatively straightforward:</p>
7192:
7193: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="interactive-elements.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="">
7194: </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="interactive-elements.html#the-div-element">div</a></code> element
7195: and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
7196:
7197: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code></li></ul></li></ul><p>They are, at this point, in the <code>Document</code> of the
7198: aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
7199: <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
7200: <code><a href="interactive-elements.html#the-div-element">div</a></code> element</em>.</p>
7201:
7202: <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
7203: is inserted <em>into the outer <code>Document</code>
7204: object</em>.</p>
7205:
7206: <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
7207: the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
7208: object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
7209: <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code>.</p>
7210:
7211: <p class="note">This isn't a security problem since the script that
7212: moves the <code><a href="interactive-elements.html#the-div-element">div</a></code> into the outer <code>Document</code> can
7213: only do so because they have the two <code>Document</code> object
7214: have the same <a href="browsers.html#origin-0">origin</a>.</p>
7215:
7216: <p>Thus, the first alert says "http://example.com/outer".</p>
7217:
7218: <p>Once the <code><a href="interactive-elements.html#the-div-element">div</a></code> element's end tag is parsed, the
7219: <code><a href="interactive-elements.html#the-div-element">div</a></code> element is popped off the stack, and so the next
7220: <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
7221:
7222: <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">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>
7223:
7224:
7225:
7226: <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3>
7227:
7228: <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
7229:
7230: <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
7231:
7232: <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
7233:
7234: <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
7235:
7236: <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
7237:
7238: <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
7239:
7240: <hr><p>Data mining tools and other user agents that perform operations
1.83 mike 7241: on <code><a href="iana-considerations.html#text-html">text/html</a></code> content without running scripts,
1.1 mike 7242: evaluating CSS or XPath expressions, or otherwise exposing the
7243: resulting DOM to arbitrary content, may "support namespaces" by just
7244: asserting that their DOM node analogues are in certain namespaces,
7245: without actually exposing the above strings.</p>
7246:
7247:
7248:
7249:
7250: <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3>
7251:
7252: <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
7253: algorithm</dfn>. The algorithm takes as input a DOM
7254: <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
7255: exception.</p>
7256:
7257: <p class="note">This algorithm serializes the <em>children</em> of
7258: the node being serialized, not the node itself.</p>
7259:
7260: <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
7261: the empty string.</p></li>
7262:
7263: <li>
7264:
7265: <p>For each child node of <var title="">the node</var>, in
7266: <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
7267:
7268: </p><ol><li><p>Let <var title="">current node</var> be the child node
7269: being processed.</p></li>
7270:
7271: <li>
7272:
7273: <p>Append the appropriate string from the following list to
7274: <var title="">s</var>:</p>
7275:
7276: <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
7277:
7278: <dd>
7279:
7280: <p>Append a U+003C LESS-THAN SIGN (<code title=""><</code>)
7281: character, followed by the element's tag name. (For nodes
7282: created by the <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
7283: lowercase.)</p>
7284:
7285: <p>For each attribute that the element has, append a U+0020
7286: SPACE character, the attribute's name (which, for attributes
7287: 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
7288: U+003D EQUALS SIGN (<code title="">=</code>) character, a
7289: U+0022 QUOTATION MARK (<code title="">"</code>)
7290: character, the attribute's value, <a href="#escapingString" title="escaping a
7291: string">escaped as described below</a> in <i>attribute
7292: mode</i>, and a second U+0022 QUOTATION MARK (<code title="">"</code>) character.</p>
7293:
7294: <p>While the exact order of attributes is UA-defined, and may
7295: depend on factors such as the order that the attributes were
7296: given in the original markup, the sort order must be stable,
7297: such that consecutive invocations of this algorithm serialize an
7298: element's attributes in the same order.</p>
7299:
7300: <p>Append a U+003E GREATER-THAN SIGN (<code title="">></code>)
7301: character.</p>
7302:
7303: <p>If <var title="">current node</var> is an
1.5 mike 7304: <code><a href="the-canvas-element.html#the-area-element">area</a></code>, <code><a href="semantics.html#the-base-element">base</a></code>, <code><a href="obsolete.html#basefont">basefont</a></code>,
1.1 mike 7305: <code>bgsound</code>, <code><a href="semantics.html#the-br-element">br</a></code>, <code><a href="tabular-data.html#the-col-element">col</a></code>,
1.5 mike 7306: <code><a href="embedded-content-0.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>,
1.1 mike 7307: <code><a href="embedded-content-0.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>,
7308: <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#meta">meta</a></code>, <code><a href="embedded-content-0.html#the-param-element">param</a></code>,
1.5 mike 7309: <code><a href="obsolete.html#spacer">spacer</a></code>, or <code>wbr</code> element, then
1.1 mike 7310: continue on to the next child node at this point.</p> <!--
7311: also, i guess: image and isindex, but we don't list those
7312: because we don't consider those "elements", more "macros", and
7313: thus we should never serialize them -->
7314:
7315: <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42 mike 7316: <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 7317: a U+000A LINE FEED (LF) character.</p>
7318:
7319: <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
7320: serialization algorithm</a> on the <var title="">current
7321: node</var> element (thus recursing into this algorithm for
7322: that element), followed by a U+003C LESS-THAN SIGN (<code title=""><</code>) character, a U+002F SOLIDUS (<code title="">/</code>) character, the element's tag name again,
7323: and finally a U+003E GREATER-THAN SIGN (<code title="">></code>) character.</p>
7324:
7325: </dd>
7326:
7327:
7328: <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
7329: node</dt>
7330:
7331: <dd>
7332:
1.19 mike 7333: <p>If the parent of <var title="">current node</var> is a
1.42 mike 7334: <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.19 mike 7335: <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>,
1.5 mike 7336: <code><a href="obsolete.html#noframes">noframes</a></code>, <code><a href="semantics.html#the-noscript-element">noscript</a></code>, or
1.42 mike 7337: <code><a href="obsolete.html#plaintext">plaintext</a></code> element, then append the value of <var title="">current node</var>'s <code title="">data</code> DOM
1.1 mike 7338: attribute literally.</p> <!-- note about noscript: we're
7339: assuming here that scripting is enabled. If this algorithm is
1.19 mike 7340: used with scripting disabled, this won't work
7341: right. (e.g. This might affect calling innerHTML on nodes in a
7342: document that is being designMode'd) -->
1.1 mike 7343:
7344: <p>Otherwise, append the value of <var title="">current
7345: node</var>'s <code title="">data</code> DOM attribute, <a href="#escapingString" title="escaping a string">escaped as described
7346: below</a>.</p>
7347:
7348: </dd>
7349:
7350:
7351: <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
7352:
7353: <dd>
7354:
7355: <p>Append the literal string <code><!--</code> (U+003C
7356: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
7357: U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> DOM
7358: attribute, followed by the literal string <code>--></code>
7359: (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
7360: SIGN).</p>
7361:
7362: </dd>
7363:
7364:
7365: <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
7366:
7367: <dd>
7368:
7369: <p>Append the literal string <code><?</code> (U+003C
7370: LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
7371: of <var title="">current node</var>'s <code title="">target</code> DOM attribute, followed by a single
7372: U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> DOM
7373: attribute, followed by a single U+003E GREATER-THAN SIGN
7374: character ('>').</p>
7375:
7376: </dd>
7377:
7378:
7379: <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
7380:
7381: <dd>
7382:
7383: <p>Append the literal string <code><!DOCTYPE</code> (U+003C
7384: LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
7385: LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
7386: LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
7387: LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
7388: LETTER E), followed by a space (U+0020 SPACE), followed by the
7389: value of <var title="">current node</var>'s <code title="">name</code> DOM attribute, followed by the literal
7390: string <code>></code> (U+003E GREATER-THAN SIGN).</p>
7391:
7392: </dd>
7393:
7394:
7395: </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
7396: occur as children of elements. If, despite this, they somehow do
7397: occur, this algorithm must raise an
7398: <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
7399:
7400: </li>
7401:
7402: </ol></li>
7403:
7404: <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
7405:
7406: </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
7407: purposes of the algorithm above) consists of replacing any
7408: occurrences of the "<code title="">&</code>" character by the
7409: string "<code title="">&amp;</code>", any occurrences of the
7410: U+00A0 NO-BREAK SPACE character by the string "<code title="">&nbsp;</code>", and, if the algorithm was invoked in
7411: 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
7412: 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>
7413:
7414: <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
7415: agent, and are therefore not covered in the algorithm above.</p>
7416:
7417: <p class="note">It is possible that the output of this algorithm, if
7418: parsed with an <a href="#html-parser">HTML parser</a>, will not return the
7419: original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
7420: element to which a <code title="">Comment</code> node has been
7421: appended is serialized and the output is then reparsed, the comment
7422: will end up being displayed in the text field. Similarly, if, as a
7423: result of DOM manipulation, an element contains a comment that
7424: contains the literal string "<code title="">--></code>", then
7425: when the result of serializing the element is parsed, the comment
7426: will be truncated at that point and the rest of the comment will be
7427: interpreted as markup. More examples would be making a
7428: <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
7429: "<code></script></code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
7430: 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
7431: <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
7432: tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
7433:
7434:
7435: <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3>
7436:
7437: <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
7438: algorithm</dfn>. The algorithm optionally takes as input an
7439: <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
7440: parser, as well as <var title="">input</var>, a string to parse, and
7441: returns a list of zero or more nodes.</p>
7442:
7443: <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
7444: in the parser section are parts that only occur if the parser was
7445: created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
7446: with such markings for informational purposes only; such markings
7447: have no normative weight. If it is possible for a condition
7448: described as a <a href="#fragment-case">fragment case</a> to occur even when the
7449: parser wasn't created for the purposes of handling this algorithm,
7450: then that is an error in the specification.</p>
7451:
7452: <ol><li>
7453:
7454: <p>Create a new <code>Document</code> node, and mark it as being
7455: an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
7456:
7457: </li>
7458:
7459: <li>
7460:
7461: <p>If there is a <var title="">context</var> element, and the
7462: <code>Document</code> of the <var title="">context</var> element
7463: is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
7464: be in <a href="dom.html#quirks-mode">quirks mode</a>. Otherwise, if there is a <var title="">context</var> element, and the <code>Document</code> of
7465: the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
7466: mode</a>, then let the <code>Document</code> be in
7467: <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
7468: <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
7469:
7470: </li>
7471:
7472: <li>
7473:
7474: <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
7475: the just created <code>Document</code> node.</p>
7476:
7477: </li>
7478:
7479: <li>
7480:
7481: <p>If there is a <var title="">context</var> element, run these
7482: substeps:</p>
7483:
7484: <ol><li>
7485:
7486: <p>Set the <a href="#html-parser">HTML parser</a>'s <a href="#tokenization">tokenization</a>
7487: stage's <a href="#content-model-flag">content model flag</a> according to the <var title="">context</var> element, as follows:</p>
7488:
7489: <dl class="switch"><dt>If it is a <code><a href="semantics.html#the-title-element">title</a></code> or <code><a href="forms.html#the-textarea-element">textarea</a></code>
7490: element</dt>
7491:
7492: <dd>Set the <a href="#content-model-flag">content model flag</a> to
7493: the RCDATA state.</dd>
7494:
7495:
7496: <dt>If it is a <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="semantics.html#script">script</a></code>,
1.42 mike 7497: <code><a href="obsolete.html#xmp">xmp</a></code>, <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>, or
1.5 mike 7498: <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1 mike 7499:
7500: <dd>Set the <a href="#content-model-flag">content model flag</a> to
1.91 mike 7501: the RAWTEXT state.</dd>
1.1 mike 7502:
7503:
7504: <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
7505:
7506: <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, set the
1.91 mike 7507: <a href="#content-model-flag">content model flag</a> to the RAWTEXT
1.1 mike 7508: state. Otherwise, set the <a href="#content-model-flag">content model flag</a> to the
7509: PCDATA state.</dd>
7510:
7511:
1.42 mike 7512: <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1 mike 7513:
7514: <dd>Set the <a href="#content-model-flag">content model flag</a> to
7515: PLAINTEXT.</dd>
7516:
7517:
7518: <dt>Otherwise</dt>
7519:
7520: <dd>Leave the <a href="#content-model-flag">content model flag</a> in the PCDATA
7521: state.</dd>
7522:
7523: </dl></li>
7524:
7525: <li>
7526:
7527: <p>Let <var title="">root</var> be a new <code><a href="semantics.html#the-html-element">html</a></code> element
7528: with no attributes.</p>
7529:
7530: </li>
7531:
7532: <li>
7533:
7534: <p>Append the element <var title="">root</var> to the
7535: <code>Document</code> node created above.</p>
7536:
7537: </li>
7538:
7539: <li>
7540:
7541: <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
7542: it contains just the single element <var title="">root</var>.</p>
7543:
7544: </li>
7545:
7546: <li>
7547:
7548: <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
7549: parser's insertion mode appropriately</a>.</p>
7550:
7551: <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
7552:
7553: </li>
7554:
7555: <li>
7556:
7557: <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
7558: to the nearest node to the <var title="">context</var> element
7559: that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
7560: ancestor chain, and including the element itself, if it is a
7561: <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
7562: <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
7563:
7564: </li>
7565:
7566: </ol></li>
7567:
7568: <li>
7569:
7570: <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
7571: parser</a> just created the <var title="">input</var>. The
7572: encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
7573: <i>irrelevant</i>.</p>
7574:
7575: </li>
7576:
7577: <li>
7578:
7579: <p>Start the parser and let it run until it has consumed all the
7580: characters just inserted into the input stream.</p>
7581:
7582: </li>
7583:
7584: <li>
7585:
7586: <p>If there is a <var title="">context</var> element, return the
7587: child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
7588: order</a>.</p>
7589:
7590: <p>Otherwise, return the children of the <code>Document</code>
7591: object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
7592:
7593: </li>
7594:
1.123 mike 7595: </ol></div></body></html>
Webmaster