Annotation of html5/spec/syntax.html, revision 1.259

1.2       mike        1: <!DOCTYPE HTML>
1.258     mike        2: <!-- when publishing, change bits marked ZZZ --><html lang="en-US-x-Hixie"><head><title>9 The HTML syntax &#8212; 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; }
1.159     mike      100:    .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
                    101:    .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
                    102:    .annotation :link, .annotation :visited { color: inherit; }
                    103:    .annotation :link:hover, .annotation :visited:hover { background: transparent; }
                    104:    .annotation span { border: none ! important; }
1.1       mike      105:    .note { color: green; background: transparent; font-family: sans-serif; }
                    106:    .warning { color: red; background: transparent; }
                    107:    .note, .warning { font-weight: bolder; font-style: italic; }
                    108:    p.note, div.note { padding: 0.5em 2em; }
                    109:    span.note { padding: 0 2em; }
                    110:    .note p:first-child, .warning p:first-child { margin-top: 0; }
                    111:    .note p:last-child, .warning p:last-child { margin-bottom: 0; }
                    112:    .warning:before { font-style: normal; }
                    113:    p.note:before { content: 'Note: '; }
                    114:    p.warning:before { content: '\26A0 Warning! '; }
                    115: 
                    116:    .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
                    117:    .bookkeeping { font-size: 0.8em; margin: 2em 0; }
                    118:    .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
                    119: 
                    120:    h4 { position: relative; z-index: 3; }
                    121:    h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
                    122:    .element {
                    123:      background: #EEEEFF;
                    124:      color: black;
                    125:      margin: 0 0 1em 0.15em;
                    126:      padding: 0 1em 0.25em 0.75em;
                    127:      border-left: solid #9999FF 0.25em;
                    128:      position: relative;
                    129:      z-index: 1;
                    130:    }
                    131:    .element:before {
                    132:      position: absolute;
                    133:      z-index: 2;
                    134:      top: 0;
                    135:      left: -1.15em;
                    136:      height: 2em;
                    137:      width: 0.9em;
                    138:      background: #EEEEFF;
                    139:      content: ' ';
                    140:      border-style: none none solid solid;
                    141:      border-color: #9999FF;
                    142:      border-width: 0.25em;
                    143:    }
                    144: 
1.149     mike      145:    .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
                    146:    td > .example:only-child { margin: 0 0 0 0.1em; }
1.1       mike      147: 
                    148:    .tall-and-narrow {
                    149:      font-size: 0.6em;
                    150:      column-width: 25em;
                    151:      column-gap: 1em;
                    152:      -moz-column-width: 25em;
                    153:      -moz-column-gap: 1em;
                    154:      -webkit-column-width: 25em;
                    155:      -webkit-column-gap: 1em;
                    156:    }
                    157: 
                    158:    ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
                    159:    ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
                    160:    ul.domTree li li { list-style: none; }
                    161:    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; }
                    162:    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; }
                    163:    ul.domTree span { font-style: italic; font-family: serif; }
                    164:    ul.domTree .t1 code { color: purple; font-weight: bold; }
                    165:    ul.domTree .t2 { font-style: normal; font-family: monospace; }
                    166:    ul.domTree .t2 .name { color: black; font-weight: bold; }
                    167:    ul.domTree .t2 .value { color: blue; font-weight: normal; }
                    168:    ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
                    169:    ul.domTree .t7 code, .domTree .t8 code { color: green; }
                    170:    ul.domTree .t10 code { color: teal; }
                    171: 
1.235     mike      172:   </style><link href="data:text/css," rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D" rel="alternate stylesheet" title="Highlight implementation requirements"><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css"><!-- ZZZ ED vs WD -->
1.2       mike      173:   <script src="link-fixup.js"></script>
                    174:   <link href="comms.html" title="8 Communication" rel="prev">
                    175:   <link href="spec.html#contents" title="Table of contents" rel="index">
1.1       mike      176:   <link href="named-character-references.html" title="9.6 Named character references" rel="next">
1.16      mike      177:   </head><body onload="fixBrokenLink(); fixBrokenLink()"><div class="head">
1.1       mike      178:    <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
1.183     mike      179:    <h1>HTML5</h1>
1.1       mike      180:    <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      181:    </div><nav>
1.1       mike      182:    <a href="comms.html">&#8592; 8 Communication</a> &#8211;
1.2       mike      183:    <a href="spec.html#contents">Table of contents</a> &#8211;
1.1       mike      184:    <a href="named-character-references.html">9.6 Named character references &#8594;</a>
1.259   ! mike      185:   </nav><p>This is revision 1.2971.</p>
1.11      mike      186: 
1.1       mike      187: 
1.123     mike      188:   <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      189:   <code><a href="iana-considerations.html#text-html">text/html</a></code> resources. Rules for XML resources are
1.1       mike      190:   discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.159     mike      191:   syntax</a>".</p><h3 id="writing"><span class="secno">9.1 </span>Writing HTML documents</h3><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p><div class="impl">
1.1       mike      192: 
                    193:   <p><i>This section only applies to documents, authoring tools, and
                    194:   markup generators. In particular, it does not apply to conformance
                    195:   checkers; conformance checkers must use the requirements given in
                    196:   the next section ("parsing HTML documents").</i></p>
                    197: 
1.123     mike      198:   </div><p>Documents must consist of the following parts, in the given
                    199:   order:</p><ol><li>Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.</li>
1.1       mike      200: 
                    201:    <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    202:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    203: 
                    204:    <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
                    205: 
                    206:    </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    207:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    208: 
1.159     mike      209:    <li>The root element, in the form of an <code><a href="semantics.html#the-html-element-0">html</a></code> <a href="#syntax-elements" title="syntax-elements">element</a>.</li>
1.1       mike      210: 
                    211:    <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    212:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    213: 
                    214:   </ol><p>The various types of content mentioned above are described in the
1.123     mike      215:   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      216:   declarations</a> are to be serialized, as discussed in the
1.123     mike      217:   section on that topic.</p><div class="note">
1.1       mike      218: 
1.159     mike      219:    <p>Space characters before the root <code><a href="semantics.html#the-html-element-0">html</a></code> element, and
                    220:    space characters at the start of the <code><a href="semantics.html#the-html-element-0">html</a></code> element and
                    221:    before the <code><a href="semantics.html#the-head-element-0">head</a></code> element, will be dropped when the
1.1       mike      222:    document is parsed; space characters <em>after</em> the root
1.159     mike      223:    <code><a href="semantics.html#the-html-element-0">html</a></code> element will be parsed as if they were at the end
                    224:    of the <code><a href="semantics.html#the-body-element-0">body</a></code> element. Thus, space characters around the
1.1       mike      225:    root element do not round-trip.</p>
                    226: 
                    227:    <p>It is suggested that newlines be inserted after the DOCTYPE,
                    228:    after any comments that are before the root element, after the
1.159     mike      229:    <code><a href="semantics.html#the-html-element-0">html</a></code> element's start tag (if it is not <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>), and after any comments
                    230:    that are inside the <code><a href="semantics.html#the-html-element-0">html</a></code> element but before the
                    231:    <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike      232: 
1.123     mike      233:   </div><p>Many strings in the HTML syntax (e.g. the names of elements and
1.1       mike      234:   their attributes) are case-insensitive, but only for characters in
                    235:   the ranges U+0041 .. U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
                    236:   LETTER Z) and U+0061 .. U+007A (LATIN SMALL LETTER A to LATIN SMALL
                    237:   LETTER Z). For convenience, in this section this is just referred to
1.168     mike      238:   as "case-insensitive".</p><h4 id="the-doctype"><span class="secno">9.1.1 </span>The DOCTYPE</h4><p class="XXX annotation"><span><a href="http://www.w3.org/html/wg/tracker/issues/4">ISSUE-4</a> (html-versioning) blocks progress to Last Call</span></p><p>A <dfn id="syntax-doctype" title="syntax-doctype">DOCTYPE</dfn> is a mostly useless,
1.123     mike      239:   but required, header.</p><p class="note">DOCTYPEs are required for legacy reasons. When
1.1       mike      240:   omitted, browsers tend to use a different rendering mode that is
                    241:   incompatible with some specifications. Including the DOCTYPE in a
                    242:   document ensures that the browser makes a best-effort attempt at
1.123     mike      243:   following the relevant specifications.</p><p>A DOCTYPE must consist of the following characters, in this
                    244:   order:</p><ol class="brief"><li>A U+003C LESS-THAN SIGN (<code>&lt;</code>) character.</li>
1.1       mike      245:    <li>A U+0021 EXCLAMATION MARK (<code>!</code>) character.</li>
                    246:    <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>
                    247:    <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    248:    <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>
                    249:    <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> (defined below).</li>
                    250:    <li>Zero or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    251:    <li>A U+003E GREATER-THAN SIGN (<code>&gt;</code>) character.</li>
                    252:   </ol><p class="note">In other words, <code>&lt;!DOCTYPE HTML&gt;</code>,
1.123     mike      253:   case-insensitively.</p><p>For the purposes of HTML generators that cannot output HTML
1.1       mike      254:   markup with the short DOCTYPE "<code title="">&lt;!DOCTYPE
                    255:   HTML&gt;</code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
                    256:   into the DOCTYPE (in the position defined above). This string must
1.123     mike      257:   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      258:    <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>
                    259:    <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    260:    <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
                    261:    <li>The literal string "<code title="">about:legacy-compat</code>".</li>
                    262:    <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>
                    263:   </ol><p class="note">In other words, <code>&lt;!DOCTYPE HTML SYSTEM
                    264:   "about:legacy-compat"&gt;</code> or <code>&lt;!DOCTYPE HTML SYSTEM
                    265:   'about:legacy-compat'&gt;</code>, case-insensitively except for the bit
1.123     mike      266:   in quotes.</p><p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1       mike      267:   the document is generated from a system that cannot output the
1.123     mike      268:   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      269:   elements, RCDATA elements, foreign elements, and normal
1.123     mike      270:   elements.</p><dl><dt><dfn id="void-elements">Void elements</dfn></dt>
1.1       mike      271: 
                    272:    <dd><code><a href="the-canvas-element.html#the-area-element">area</a></code>, <code><a href="semantics.html#the-base-element">base</a></code>, <code><a href="semantics.html#the-br-element">br</a></code>,
1.159     mike      273:    <code><a href="tabular-data.html#the-col-element">col</a></code>, <code><a href="interactive-elements.html#the-command">command</a></code>, <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>,
                    274:    <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="text-level-semantics.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>,
1.1       mike      275:    <code><a href="forms.html#the-keygen-element">keygen</a></code>, <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#meta">meta</a></code>,
1.159     mike      276:    <code><a href="text-level-semantics.html#the-param-element">param</a></code>, <code><a href="video.html#the-source-element">source</a></code></dd>
1.1       mike      277: 
1.91      mike      278:    <dt>Raw text elements</dt>
1.1       mike      279: 
                    280:    <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      281:    noscript don't count as raw text for syntax purposes -->
1.1       mike      282: 
                    283:    <dt>RCDATA elements</dt>
                    284: 
1.159     mike      285:    <dd><code><a href="forms.html#the-textarea-element">textarea</a></code>, <code><a href="semantics.html#the-title-element-0">title</a></code></dd>
1.1       mike      286: 
                    287:    <dt>Foreign elements</dt>
                    288: 
                    289:    <dd>Elements from the <a href="#mathml-namespace">MathML namespace</a>
                    290:    and the <a href="#svg-namespace">SVG namespace</a>.</dd>
                    291: 
                    292:    <dt>Normal elements</dt>
                    293: 
                    294:    <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
                    295:    elements.</dd>
                    296: 
                    297:   </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.91      mike      298:   and end of elements in the markup. Raw text, RCDATA, and normal
1.1       mike      299:   elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to
                    300:   indicate where they begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end
                    301:   tag</a> to indicate where they end. The start and end tags of
                    302:   certain normal elements can be <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>, as described
                    303:   later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
                    304:   elements</a> only have a start tag; end tags must not be
                    305:   specified for void elements. Foreign elements must either have a
                    306:   start tag and an end tag, or a start tag that is marked as
1.123     mike      307:   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      308:   start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
                    309:   in certain cases</a>) and just before the end tag (which again,
                    310:   <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
                    311:   cases</a>). The exact allowed contents of each individual element
                    312:   depends on the content model of that element, as described earlier
                    313:   in this specification. Elements must not contain content that their
                    314:   content model disallows. In addition to the restrictions placed on
                    315:   the contents by those content models, however, the five types of
1.123     mike      316:   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      317:   no end tag, no content can be put between the start tag and the end
1.123     mike      318:   tag).</p><p>Raw text elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1       mike      319:   though it has <a href="#cdata-rcdata-restrictions">restrictions</a>
1.123     mike      320:   described below.</p><p>RCDATA elements can have <a href="#syntax-text" title="syntax-text">text</a>
1.1       mike      321:   and <a href="#syntax-charref" title="syntax-charref">character references</a>, but
                    322:   the text must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
                    323:   There are also <a href="#cdata-rcdata-restrictions">further
1.123     mike      324:   restrictions</a> described below.</p><p>Foreign elements whose start tag is marked as self-closing can't
1.1       mike      325:   have any contents (since, again, as there's no end tag, no content
                    326:   can be put between the start tag and the end tag). Foreign elements
                    327:   whose start tag is <em>not</em> marked as self-closing can have
                    328:   <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
                    329:   contain the character U+003C LESS-THAN SIGN (<code>&lt;</code>) or
                    330:   an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.123     mike      331:   ampersand</a>.</p><p>Normal elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1       mike      332:   <a href="#syntax-charref" title="syntax-charref">character references</a>, other
                    333:   <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
                    334:   contain the character U+003C LESS-THAN SIGN (<code>&lt;</code>) or
                    335:   an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
                    336:   ampersand</a>. Some normal elements also have <a href="#element-restrictions">yet more restrictions</a> on what
                    337:   content they are allowed to hold, beyond the restrictions imposed by
                    338:   the content model and those described in this paragraph. Those
1.123     mike      339:   restrictions are described below.</p><p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1       mike      340:   giving the element's name. HTML elements all have names that only
                    341:   use characters in the range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE,
1.202     mike      342:   U+0061 LATIN SMALL LETTER A .. U+007A LATIN SMALL LETTER Z, and
                    343:   U+0041 LATIN CAPITAL LETTER A .. U+005A LATIN CAPITAL LETTER Z. In
                    344:   the HTML syntax, tag names may be written with any mix of lower- and
                    345:   uppercase letters that, when converted to all-lowercase, matches the
                    346:   element's tag name; tag names are case-insensitive.</p><h5 id="start-tags"><span class="secno">9.1.2.1 </span>Start tags</h5><p><dfn id="syntax-start-tag" title="syntax-start-tag">Start tags</dfn> must have the
1.123     mike      347:   following format:</p><ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.1       mike      348:    SIGN (<code>&lt;</code>).</li>
                    349: 
                    350:    <li>The next few characters of a start tag must be the element's
                    351:    <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
                    352: 
                    353:    <li>If there are to be any attributes in the next step, there must
                    354:    first be one or more <a href="infrastructure.html#space-character" title="space character">space
                    355:    characters</a>.</li>
                    356: 
                    357:    <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
                    358:    below. Attributes may be separated from each other by one or more
                    359:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    360: 
                    361:    <li>After the attributes, there may be one or more <a href="infrastructure.html#space-character" title="space character">space characters</a>. (Some attributes
                    362:    are required to be followed by a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes section</a> below.)</li>
                    363: 
                    364:    <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
                    365:    or if the element is a foreign element, then there may be a single
                    366:    U+002F SOLIDUS (<code>/</code>) character. This character has no
                    367:    effect on void elements, but on foreign elements it marks the start
                    368:    tag as self-closing.</li>
                    369: 
                    370:    <li>Finally, start tags must be closed by a U+003E GREATER-THAN
                    371:    SIGN (<code>&gt;</code>) character.</li>
                    372: 
1.123     mike      373:   </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
                    374:   following format:</p><ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.1       mike      375:    SIGN (<code>&lt;</code>).</li>
                    376: 
                    377:    <li>The second character of an end tag must be a U+002F SOLIDUS
                    378:    (<code>/</code>).</li>
                    379: 
                    380:    <li>The next few characters of an end tag must be the element's
                    381:    <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
                    382: 
                    383:    <li>After the tag name, there may be one or more <a href="infrastructure.html#space-character" title="space
                    384:    character">space characters</a>.</li>
                    385: 
                    386:    <li>Finally, end tags must be closed by a U+003E GREATER-THAN
                    387:    SIGN (<code>&gt;</code>) character.</li>
                    388: 
1.123     mike      389:   </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
                    390:   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      391:   one or more characters other than the <a href="infrastructure.html#space-character" title="space
                    392:   character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
                    393:   MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
                    394:   (&gt;), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters,
                    395:   the control characters, and any characters that are not defined by
                    396:   Unicode. In the HTML syntax, attribute names may be written with any
                    397:   mix of lower- and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.123     mike      398:   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      399:   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      400:   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      401: 
                    402:    <dd>
                    403: 
                    404:     <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
                    405:     name</a>.</p>
                    406: 
                    407:     <div class="example">
                    408: 
                    409:      <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
                    410:      the empty attribute syntax:</p>
                    411: 
                    412:      <pre>&lt;input <em>disabled</em>&gt;</pre>
                    413: 
                    414:     </div>
                    415: 
                    416:     <p>If an attribute using the empty attribute syntax is to be
                    417:     followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    418:     character</a> separating the two.</p>
                    419: 
                    420:    </dd>
                    421: 
1.2       mike      422:    <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1       mike      423: 
                    424:    <dd>
                    425: 
                    426:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    427:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    428:     characters</a>, followed by a single U+003D EQUALS SIGN
                    429:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    430:     character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    431:     addition to the requirements given above for attribute values,
                    432:     must not contain any literal <a href="infrastructure.html#space-character" title="space character">space
                    433:     characters</a>, any U+0022 QUOTATION MARK (<code>"</code>)
                    434:     characters, U+0027 APOSTROPHE (<code>'</code>) characters,
                    435:     U+003D EQUALS SIGN (<code>=</code>) characters, U+003C LESS-THAN
                    436:     SIGN (<code>&lt;</code>) characters, or U+003E GREATER-THAN SIGN
                    437:     (<code>&gt;</code>) characters, and must not be the empty
                    438:     string.</p>
                    439: 
                    440:     <div class="example">
                    441: 
                    442:      <p>In the following example, the <code title="attr-input-value"><a href="forms.html#attr-input-value">value</a></code> attribute is given
                    443:      with the unquoted attribute value syntax:</p>
                    444: 
                    445:      <pre>&lt;input <em>value=yes</em>&gt;</pre>
                    446: 
                    447:     </div>
                    448: 
                    449:     <p>If an attribute using the unquoted attribute syntax is to be
1.101     mike      450:     followed by another attribute or by the optional U+002F SOLIDUS
                    451:     (<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      452:     must be a <a href="infrastructure.html#space-character">space character</a> separating the two.</p>
                    453: 
                    454:    </dd>
                    455: 
                    456:    <dt>Single-quoted attribute value syntax</dt>
                    457: 
                    458:    <dd>
                    459: 
                    460:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    461:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    462:     characters</a>, followed by a single U+003D EQUALS SIGN
                    463:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    464:     character">space characters</a>, followed by a single U+0027
                    465:     APOSTROPHE (<code>'</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    466:     addition to the requirements given above for attribute values,
                    467:     must not contain any literal U+0027 APOSTROPHE (<code>'</code>)
                    468:     characters, and finally followed by a second single U+0027
                    469:     APOSTROPHE (<code>'</code>) character.</p>
                    470: 
                    471:     <div class="example">
                    472: 
                    473:      <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
                    474:      single-quoted attribute value syntax:</p>
                    475: 
                    476:      <pre>&lt;input <em>type='checkbox'</em>&gt;</pre>
                    477: 
                    478:     </div>
                    479: 
                    480:     <p>If an attribute using the single-quoted attribute syntax is to
                    481:     be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    482:     character</a> separating the two.</p>
                    483: 
                    484:    </dd>
                    485: 
                    486:    <dt>Double-quoted attribute value syntax</dt>
                    487: 
                    488:    <dd>
                    489: 
                    490:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    491:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    492:     characters</a>, followed by a single U+003D EQUALS SIGN
                    493:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    494:     character">space characters</a>, followed by a single U+0022
                    495:     QUOTATION MARK (<code>"</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    496:     addition to the requirements given above for attribute values,
                    497:     must not contain any literal U+0022 QUOTATION MARK
                    498:     (<code>"</code>) characters, and finally followed by a second
                    499:     single U+0022 QUOTATION MARK (<code>"</code>) character.</p>
                    500: 
                    501:     <div class="example">
                    502: 
                    503:      <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
                    504:      double-quoted attribute value syntax:</p>
                    505: 
                    506:      <pre>&lt;input <em>name="be evil"</em>&gt;</pre>
                    507: 
                    508:     </div>
                    509: 
                    510:     <p>If an attribute using the double-quoted attribute syntax is to
                    511:     be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    512:     character</a> separating the two.</p>
                    513: 
                    514:    </dd>
                    515: 
                    516:   </dl><p>There must never be two or more attributes on the same start tag
                    517:   whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.123     mike      518:   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      519:   is not present; it is implied, but it is still there. An HTML
1.159     mike      520:   document always has a root <code><a href="semantics.html#the-html-element-0">html</a></code> element, even if the
1.1       mike      521:   string <code title="">&lt;html&gt;</code> doesn't appear anywhere in
1.159     mike      522:   the markup.</p><!-- <html> --><p>An <code><a href="semantics.html#the-html-element-0">html</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
                    523:   first thing inside the <code><a href="semantics.html#the-html-element-0">html</a></code> element is not a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- </html> --><p>An <code><a href="semantics.html#the-html-element-0">html</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
                    524:   tag</a> may be omitted if the <code><a href="semantics.html#the-html-element-0">html</a></code> element is not
                    525:   immediately followed by a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- <head> --><p>A <code><a href="semantics.html#the-head-element-0">head</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted <!--if the
1.1       mike      526:   element is empty, or--> if the first thing inside the
1.159     mike      527:   <code><a href="semantics.html#the-head-element-0">head</a></code> element is an element.</p><!-- </head> --><p>A <code><a href="semantics.html#the-head-element-0">head</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
                    528:   tag</a> may be omitted if the <code><a href="semantics.html#the-head-element-0">head</a></code> element is not
                    529:   immediately followed by a <a href="infrastructure.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- <body> --><p>A <code><a href="semantics.html#the-body-element-0">body</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
                    530:   element is empty, or if the first thing inside the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1       mike      531:   element is not a <a href="infrastructure.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>, except if the first thing
1.159     mike      532:   inside the <code><a href="semantics.html#the-body-element-0">body</a></code> element is a <code><a href="semantics.html#script">script</a></code> or
1.1       mike      533:   <code><a href="semantics.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
                    534:   tag is present, the parser makes <style> and <script> elements
                    535:   between </head> and <body> end up in the <head> instead of implying
1.159     mike      536:   the <body> --></p><!-- </body> --><p>A <code><a href="semantics.html#the-body-element-0">body</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
                    537:   tag</a> may be omitted if the <code><a href="semantics.html#the-body-element-0">body</a></code> element is not
1.123     mike      538:   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      539:   tag</a> may be omitted if the <code><a href="semantics.html#the-li-element">li</a></code> element is
                    540:   immediately followed by another <code><a href="semantics.html#the-li-element">li</a></code> element or if there
1.123     mike      541:   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      542:   tag</a> may be omitted if the <code><a href="semantics.html#the-dt-element">dt</a></code> element is
                    543:   immediately followed by another <code><a href="semantics.html#the-dt-element">dt</a></code> element or a
1.123     mike      544:   <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      545:   tag</a> may be omitted if the <code><a href="semantics.html#the-dd-element">dd</a></code> element is
                    546:   immediately followed by another <code><a href="semantics.html#the-dd-element">dd</a></code> element or a
                    547:   <code><a href="semantics.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.123     mike      548:   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      549:   tag</a> may be omitted if the <code><a href="semantics.html#the-p-element">p</a></code> element is
                    550:   immediately followed by an <code><a href="semantics.html#the-address-element">address</a></code>,
                    551:   <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      552:   <!--v2DATAGRID <code>datagrid</code>,--> <code><a href="semantics.html#the-dialog-element">dialog</a></code>,
                    553:   <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>,
                    554:   <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>,
                    555:   <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>,
                    556:   <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>,
                    557:   <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>,
                    558:   <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      559:   <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>,
                    560:   element, or if there is no more content in the parent element and
1.123     mike      561:   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      562:   tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element is
                    563:   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      564:   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      565:   tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element is
                    566:   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      567:   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      568:   <select>; commented out text below can handle the non-<select> case
1.123     mike      569:   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      570:   <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
                    571:   <code>select</code> element and--> is immediately followed by
                    572:   another <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
                    573:   that are ancestors of the <code>optgroup</code> element, up to and
                    574:   including the first ancestor element that is not an
                    575:   <code>optgroup</code> element, have no more content--> there is no
1.123     mike      576:   more content in the parent element.</p><!-- so e.g. the max number of </optgroup>s are omitted here:
1.1       mike      577:    <select><optgroup></select>
                    578:    <p id=x><optgroup></optgroup>x</p>
                    579:    <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
                    580:    <p><optgroup id=x><optgroup></optgroup>x</p>
                    581:    <p><optgroup><optgroup id=x>x</p>
1.123     mike      582:   --><!-- </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      583:   tag</a> may be omitted if the <code><a href="forms.html#the-option-element">option</a></code> element is
                    584:   immediately followed by another <code><a href="forms.html#the-option-element">option</a></code> element, or if
                    585:   it is immediately followed by an <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or
1.123     mike      586:   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      587:   first thing inside the <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is a
                    588:   <code><a href="tabular-data.html#the-col-element">col</a></code> element, and if the element is not immediately
                    589:   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      590:   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      591:   <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.123     mike      592:   <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      593:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-thead-element">thead</a></code> element is
                    594:   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      595:   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      596:   first thing inside the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is a
                    597:   <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, and if the element is not immediately
                    598:   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
                    599:   <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
                    600:   tag</a> has been omitted. (It can't be omitted if the element is
1.123     mike      601:   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      602:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is
                    603:   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      604:   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      605:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element is
                    606:   immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, or if there is
1.123     mike      607:   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      608:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
                    609:   immediately followed by another <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, or if there
1.123     mike      610:   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      611:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-td-element">td</a></code> element is
                    612:   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      613:   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      614:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-th-element">th</a></code> element is
                    615:   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      616:   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
                    617:   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
                    618:   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      619:   elements, even though these elements are technically allowed inside
                    620:   <code><a href="tabular-data.html#the-table-element">table</a></code> elements according to the content models
                    621:   described in this specification. (If a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
                    622:   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      623:   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      624:   immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
                    625:   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>
                    626:   elements. This does not affect the processing of the element. The
                    627:   otherwise optional U+000A LINE FEED (LF) character <em>must</em> be
                    628:   included if the element's contents start with that character
                    629:   (because otherwise the leading newline in the contents would be
1.123     mike      630:   treated like the optional newline, and ignored).</p><div class="example">
1.1       mike      631:    <p>The following two <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
                    632:    <pre>&lt;pre&gt;Hello&lt;/pre&gt;</pre>
                    633:    <pre>&lt;pre&gt;<br>Hello&lt;/pre&gt;</pre>
1.123     mike      634:   </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      635:   occurrences of the string "<code title="">&lt;/</code>" (U+003C
                    636:   LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that
                    637:   case-insensitively match the tag name of the element followed by one
                    638:   of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM
                    639:   FEED (FF), U+0020 SPACE, U+003E GREATER-THAN SIGN (&gt;), or U+002F
1.123     mike      640:   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      641:   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
                    642:   not itself in an <a href="#syntax-escape" title="syntax-escape">escaping text
                    643:   span</a>, and ends at the next <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span end</a>. There
                    644:   cannot be any <a href="#syntax-charref" title="syntax-charref">character
                    645:   references</a> inside an <a href="#syntax-escape" title="syntax-escape">escaping
                    646:   text span</a> &#8212; sequences of characters that would look
                    647:   like <a href="#syntax-charref" title="syntax-charref">character references</a> do not
1.123     mike      648:   have special meaning.</p><p>An <dfn id="syntax-escape-start" title="syntax-escape-start">escaping text span
1.1       mike      649:   start</dfn> is a part of <a href="#syntax-text" title="syntax-text">text</a> that
                    650:   consists of the four character sequence "<code title="">&lt;!--</code>" (U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
1.123     mike      651:   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      652:   a part of <a href="#syntax-text" title="syntax-text">text</a> that consists of the
                    653:   three character sequence "<code title="">--&gt;</code>" (U+002D
1.134     mike      654:   HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN).</p><p>An <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span
1.1       mike      655:   start</a> may share its U+002D HYPHEN-MINUS characters with its
                    656:   corresponding <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span
1.123     mike      657:   end</a>.</p><p>The text in raw text elements and RCDATA elements must not have
1.91      mike      658:   an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a>
                    659:   that is not followed by an <a href="#syntax-escape-end" title="syntax-escape-end">escaping
1.123     mike      660:   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      661:   attributes, and comments. Text must consist of Unicode characters.
                    662:   Text must not contain U+0000 characters. Text must not contain
                    663:   permanently undefined Unicode characters. Text must not contain
                    664:   control characters other than <a href="infrastructure.html#space-character" title="space character">space
                    665:   characters</a>. Extra constraints are placed on what is and what
                    666:   is not allowed in text based on where the text is to be put, as
1.123     mike      667:   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      668:   represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A
                    669:   LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR),
1.123     mike      670:   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      671:   to escape characters that couldn't otherwise legally be included in
1.123     mike      672:   <a href="#syntax-text" title="syntax-text">text</a>.</p><p>Character references must start with a U+0026 AMPERSAND
1.1       mike      673:   (<code>&amp;</code>). Following this, there are three possible kinds
1.123     mike      674:   of character references:</p><dl><dt>Named character references</dt>
1.1       mike      675: 
                    676:    <dd>The ampersand must be followed by one of the names given in the
                    677:    <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
                    678:    case. The name must be one that is terminated by a U+003B SEMICOLON
                    679:    (<code title="">;</code>) character.</dd>
                    680: 
                    681: 
                    682:    <dt>Decimal numeric character reference</dt>
                    683: 
                    684:    <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
                    685:    (<code>#</code>) character, followed by one or more digits in the
                    686:    range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, representing a
                    687:    base-ten integer that itself is a Unicode code point that is
                    688:    not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
                    689:    0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
                    690:    a U+003B SEMICOLON character (<code title="">;</code>).</dd>
                    691: 
                    692: 
                    693:    <dt>Hexadecimal numeric character reference</dt>
                    694: 
                    695:    <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
                    696:    (<code>#</code>) character, which must be followed by either a
                    697:    U+0078 LATIN SMALL LETTER X or a U+0058 LATIN CAPITAL LETTER X
                    698:    character, which must then be followed by one or more digits in the
                    699:    range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, U+0061 LATIN SMALL
                    700:    LETTER A .. U+0066 LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL
                    701:    LETTER A .. U+0046 LATIN CAPITAL LETTER F, representing a
                    702:    base-sixteen integer that itself is a Unicode code point that is
                    703:    not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
                    704:    0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
                    705:    a U+003B SEMICOLON character (<code title="">;</code>).</dd>
                    706: 
                    707:   </dl><p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
                    708:   ampersand</dfn> is a U+0026 AMPERSAND (<code>&amp;</code>) character
                    709:   that is followed by some <a href="#syntax-text" title="syntax-text">text</a> other
                    710:   than a <a href="infrastructure.html#space-character">space character</a>, a U+003C LESS-THAN SIGN
                    711:   character ('&lt;'), or another U+0026 AMPERSAND (<code>&amp;</code>)
1.123     mike      712:   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      713:   the character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
                    714:   MARK, U+005B LEFT SQUARE BRACKET, U+0043 LATIN CAPITAL LETTER C,
                    715:   U+0044 LATIN CAPITAL LETTER D, U+0041 LATIN CAPITAL LETTER A, U+0054
                    716:   LATIN CAPITAL LETTER T, U+0041 LATIN CAPITAL LETTER A, U+005B LEFT
                    717:   SQUARE BRACKET (<code title="">&lt;![CDATA[</code>). Following this
                    718:   sequence, the CDATA section may have <a href="#syntax-text" title="syntax-text">text</a>, with the additional restriction
                    719:   that the text must not contain the three character sequence U+005D
                    720:   RIGHT SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E
                    721:   GREATER-THAN SIGN (<code title="">]]&gt;</code>). Finally, the CDATA
                    722:   section must be ended by the three character sequence U+005D RIGHT
                    723:   SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E GREATER-THAN
1.159     mike      724:   SIGN (<code title="">]]&gt;</code>).</p><h4 id="comments"><span class="secno">9.1.6 </span>Comments</h4><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p><p><dfn id="syntax-comments" title="syntax-comments">Comments</dfn> must start with the
1.1       mike      725:   four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
                    726:   MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title="">&lt;!--</code>). Following this sequence, the comment may
                    727:   have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
                    728:   restriction that the text must not start with a single U+003E
                    729:   GREATER-THAN SIGN ('&gt;') character, nor start with a U+002D
                    730:   HYPHEN-MINUS (<code title="">-</code>) character followed by a
                    731:   U+003E GREATER-THAN SIGN ('&gt;') character, nor contain two
                    732:   consecutive U+002D HYPHEN-MINUS (<code title="">-</code>)
                    733:   characters, nor end with a U+002D HYPHEN-MINUS (<code title="">-</code>) character. Finally, the comment must be ended by
                    734:   the three character sequence U+002D HYPHEN-MINUS, U+002D
1.123     mike      735:   HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--&gt;</code>).</p><div class="impl">
1.1       mike      736: 
1.159     mike      737:   <h3 id="parsing"><span class="secno">9.2 </span>Parsing HTML documents</h3><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1       mike      738: 
                    739:   <p><i>This section only applies to user agents, data mining tools,
                    740:   and conformance checkers.</i></p>
                    741: 
                    742:   <p class="note">The rules for parsing XML documents into DOM trees
                    743:   are covered by the next section, entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
                    744:   syntax</a>".</p>
                    745: 
                    746:   <p>For <a href="dom.html#html-documents">HTML documents</a>, user agents must use the parsing
                    747:   rules described in this section to generate the DOM trees. Together,
                    748:   these rules define what is referred to as the <dfn id="html-parser">HTML
                    749:   parser</dfn>.</p>
                    750: 
                    751:   <div class="note">
                    752: 
                    753:    <p>While the HTML syntax described in this specification bears a
                    754:    close resemblance to SGML and XML, it is a separate language with
                    755:    its own parsing rules.</p>
                    756: 
1.183     mike      757:    <p>Some earlier versions of HTML (in particular from HTML2 to
                    758:    HTML4) were based on SGML and used SGML parsing rules. However, few
1.1       mike      759:    (if any) web browsers ever implemented true SGML parsing for HTML
                    760:    documents; the only user agents to strictly handle HTML as an SGML
                    761:    application have historically been validators. The resulting
                    762:    confusion &#8212; with validators claiming documents to have one
                    763:    representation while widely deployed Web browsers interoperably
                    764:    implemented a different representation &#8212; has wasted decades
                    765:    of productivity. This version of HTML thus returns to a non-SGML
                    766:    basis.</p>
                    767: 
                    768:    <p>Authors interested in using SGML tools in their authoring
                    769:    pipeline are encouraged to use XML tools and the XML serialization
                    770:    of HTML.</p>
                    771: 
                    772:   </div>
                    773: 
                    774:   <p>This specification defines the parsing rules for HTML documents,
                    775:   whether they are syntactically correct or not. Certain points in the
                    776:   parsing algorithm are said to be <dfn id="parse-error" title="parse error">parse
                    777:   errors</dfn>. The error handling for parse errors is well-defined:
                    778:   user agents must either act as described below when encountering
                    779:   such problems, or must abort processing at the first error that they
                    780:   encounter for which they do not wish to apply the rules described
                    781:   below.</p>
                    782: 
                    783:   <p>Conformance checkers must report at least one parse error
                    784:   condition to the user if one or more parse error conditions exist in
                    785:   the document and must not report parse error conditions if none
                    786:   exist in the document. Conformance checkers may report more than one
1.174     mike      787:   parse error condition if more than one parse error condition exists
1.1       mike      788:   in the document. Conformance checkers are not required to recover
                    789:   from parse errors.</p>
                    790: 
                    791:   <p class="note">Parse errors are only errors with the
                    792:   <em>syntax</em> of HTML. In addition to checking for parse errors,
                    793:   conformance checkers will also verify that the document obeys all
                    794:   the other conformance requirements described in this
                    795:   specification.</p>
                    796: 
                    797:   <p>For the purposes of conformance checkers, if a resource is
                    798:   determined to be in <a href="#syntax">the HTML syntax</a>, then it is an
                    799:   <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                    800: 
                    801: 
                    802:   <h4 id="overview-of-the-parsing-model"><span class="secno">9.2.1 </span>Overview of the parsing model</h4>
                    803: 
                    804:   <p>The input to the HTML parsing process consists of a stream of
                    805:   Unicode characters, which is passed through a
                    806:   <a href="#tokenization">tokenization</a> stage followed by a <a href="#tree-construction">tree
                    807:   construction</a> stage. The output is a <code>Document</code>
                    808:   object.</p>
                    809: 
                    810:   <p class="note">Implementations that <a href="infrastructure.html#non-scripted">do not
                    811:   support scripting</a> do not have to actually create a DOM
                    812:   <code>Document</code> object, but the DOM tree in such cases is
                    813:   still used as the model for the rest of the specification.</p>
                    814: 
                    815:   <p>In the common case, the data handled by the tokenization stage
1.159     mike      816:   comes from the network, but <a href="embedded-content-0.html#dynamic-markup-insertion" title="dynamic markup
                    817:   insertion">it can also come from script</a>, e.g. using the <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code> API.</p>
1.1       mike      818: 
                    819:   <p><img alt="" src="images/parsing-model-overview.png"></p>
                    820: 
                    821:   <p id="nestedParsing">There is only one set of states for the
                    822:   tokenizer stage and the tree construction stage, but the tree
                    823:   construction stage is reentrant, meaning that while the tree
                    824:   construction stage is handling one token, the tokenizer might be
                    825:   resumed, causing further tokens to be emitted and processed before
                    826:   the first token's processing is complete.</p>
                    827: 
                    828:   <div class="example">
                    829: 
                    830:    <p>In the following example, the tree construction stage will be
                    831:    called upon to handle a "p" start tag token while handling the
                    832:    "script" start tag token:</p>
                    833: 
                    834:    <pre>...
                    835: &lt;script&gt;
                    836:  document.write('&lt;p&gt;');
                    837: &lt;/script&gt;
                    838: ...</pre>
                    839: 
                    840:   </div>
                    841: 
                    842:   <p>To handle these cases, parsers have a <dfn id="script-nesting-level">script nesting
                    843:   level</dfn>, which must be initially set to zero, and a <dfn id="parser-pause-flag">parser
                    844:   pause flag</dfn>, which must be initially set to false.</p>
                    845: 
                    846: 
                    847: 
                    848:   <h4 id="the-input-stream"><span class="secno">9.2.2 </span>The <dfn>input stream</dfn></h4>
                    849: 
                    850:   <p>The stream of Unicode characters that comprises the input to the
                    851:   tokenization stage will be initially seen by the user agent as a
                    852:   stream of bytes (typically coming over the network or from the local
                    853:   file system). The bytes encode the actual characters according to a
                    854:   particular <em>character encoding</em>, which the user agent must
                    855:   use to decode the bytes into characters.</p>
                    856: 
                    857:   <p class="note">For XML documents, the algorithm user agents must
                    858:   use to determine the character encoding is given by the XML
1.104     mike      859:   specification. This section does not apply to XML documents. <a href="references.html#refsXML">[XML]</a></p>
1.1       mike      860: 
                    861: 
1.168     mike      862:   <h5 id="determining-the-character-encoding"><span class="secno">9.2.2.1 </span>Determining the character encoding</h5><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p>
1.1       mike      863: 
                    864:   <p>In some cases, it might be impractical to unambiguously determine
                    865:   the encoding before parsing the document. Because of this, this
                    866:   specification provides for a two-pass mechanism with an optional
                    867:   pre-scan. Implementations are allowed, as described below, to apply
                    868:   a simplified parsing algorithm to whatever bytes they have available
                    869:   before beginning to parse the document. Then, the real parser is
                    870:   started, using a tentative encoding derived from this pre-parse and
                    871:   other out-of-band metadata. If, while the document is being loaded,
                    872:   the user agent discovers an encoding declaration that conflicts with
                    873:   this information, then the parser can get reinvoked to perform a
                    874:   parse of the document with the real encoding.</p>
                    875: 
                    876:   <p id="documentEncoding">User agents must use the following
                    877:   algorithm (the <dfn id="encoding-sniffing-algorithm">encoding sniffing algorithm</dfn>) to determine
                    878:   the character encoding to use when decoding a document in the first
                    879:   pass. This algorithm takes as input any out-of-band metadata
                    880:   available to the user agent (e.g. the <a href="infrastructure.html#content-type" title="Content-Type">Content-Type metadata</a> of the document)
                    881:   and all the bytes available so far, and returns an encoding and a
                    882:   <dfn id="concept-encoding-confidence" title="concept-encoding-confidence">confidence</dfn>. The
                    883:   confidence is either <i>tentative</i>, <i>certain</i>, or
                    884:   <i>irrelevant</i>. The encoding used, and whether the confidence in
                    885:   that encoding is <i>tentative</i> or <i>certain</i>, is <a href="#meta-charset-during-parse">used during the parsing</a> to
                    886:   determine whether to <a href="#change-the-encoding">change the encoding</a>. If no
                    887:   encoding is necessary, e.g. because the parser is operating on a
                    888:   stream of Unicode characters and doesn't have to use an encoding at
                    889:   all, then the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                    890:   <i>irrelevant</i>.</p>
                    891: 
                    892:   <ol><li><p>If the transport layer specifies an encoding, and it is
                    893:    supported, return that encoding with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                    894:    <i>certain</i>, and abort these steps.</p></li>
                    895: 
                    896:    <li><p>The user agent may wait for more bytes of the resource to be
                    897:    available, either in this step or at any later step in this
                    898:    algorithm. For instance, a user agent might wait 500ms or 512
                    899:    bytes, whichever came first. In general preparsing the source to
                    900:    find the encoding improves performance, as it reduces the need to
                    901:    throw away the data structures used when parsing upon finding the
                    902:    encoding information. However, if the user agent delays too long to
                    903:    obtain data to determine the encoding, then the cost of the delay
                    904:    could outweigh any performance improvements from the
                    905:    preparse.</p></li>
                    906: 
                    907:    <li><p>For each of the rows in the following table, starting with
                    908:    the first one and going down, if there are as many or more bytes
                    909:    available than the number of bytes in the first column, and the
                    910:    first bytes of the file match the bytes given in the first column,
                    911:    then return the encoding given in the cell in the second column of
                    912:    that row, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                    913:    <i>certain</i>, and abort these steps:</p>
                    914: 
                    915:     <!-- this table is present in several forms in this file; keep them in sync -->
                    916:     <table><thead><tr><th>Bytes in Hexadecimal
                    917:        </th><th>Encoding
                    918:      </th></tr></thead><tbody><!-- nobody uses this
                    919:       <tr>
                    920:        <td>00 00 FE FF
                    921:        <td>UTF-32BE
                    922:       <tr>
                    923:        <td>FF FE 00 00
                    924:        <td>UTF-32LE
                    925: --><tr><td>FE FF
                    926:        </td><td>UTF-16BE
                    927:       </td></tr><tr><td>FF FE
                    928:        </td><td>UTF-16LE
                    929:       </td></tr><tr><td>EF BB BF
                    930:        </td><td>UTF-8
                    931: <!-- nobody uses this
                    932:       <tr>
                    933:        <td>DD 73 66 73
                    934:        <td>UTF-EBCDIC
                    935: -->
                    936:     </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
                    937:    (BOMs).</p></li>
                    938: 
                    939:    <li><p>Otherwise, the user agent will have to search for explicit
                    940:    character encoding information in the file itself. This should
                    941:    proceed as follows:
                    942: 
                    943:     </p><p>Let <var title="">position</var> be a pointer to a byte in the
                    944:     input stream, initially pointing at the first byte. If at any
                    945:     point during these substeps the user agent either runs out of
                    946:     bytes or decides that scanning further bytes would not be
                    947:     efficient, then skip to the next step of the overall character
                    948:     encoding detection algorithm. User agents may decide that scanning
                    949:     <em>any</em> bytes is not efficient, in which case these substeps
                    950:     are entirely skipped.</p>
                    951: 
                    952:     <p>Now, repeat the following "two" steps until the algorithm
                    953:     aborts (either because user agent aborts, as described above, or
                    954:     because a character encoding is found):</p>
                    955: 
                    956:     <ol><li><p>If <var title="">position</var> points to:</p>
                    957: 
                    958:       <dl class="switch"><dt>A sequence of bytes starting with: 0x3C 0x21 0x2D 0x2D (ASCII '&lt;!--')</dt>
                    959:        <dd>
                    960: 
                    961:         <p>Advance the <var title="">position</var> pointer so that it
                    962:         points at the first 0x3E byte which is preceded by two 0x2D
                    963:         bytes (i.e. at the end of an ASCII '--&gt;' sequence) and comes
                    964:         after the 0x3C byte that was found. (The two 0x2D bytes can be
                    965:         the same as the those in the '&lt;!--' sequence.)</p>
                    966: 
                    967:        </dd>
                    968: 
                    969:        <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 '&lt;meta' followed by a space or slash)</dt>
                    970:        <dd>
                    971: 
                    972:         <ol><li><p>Advance the <var title="">position</var> pointer so
                    973:          that it points at the next 0x09, 0x0A, 0x0C, 0x0D, 0x20, or
                    974:          0x2F byte (the one in sequence of characters matched
                    975:          above).</p></li>
                    976: 
                    977:          <li><p><a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">Get
                    978:          an attribute</a> and its value. If no attribute was
                    979:          sniffed, then skip this inner set of steps, and jump to the
                    980:          second step in the overall "two step" algorithm.</p></li>
                    981: 
                    982:          <li><p>If the attribute's name is neither "<code title="">charset</code>" nor "<code title="">content</code>",
                    983:          then return to step 2 in these inner steps.</p></li>
                    984: 
                    985:          <li><p>If the attribute's name is "<code title="">charset</code>", let <var title="">charset</var> be
                    986:          the attribute's value, interpreted as a character
                    987:          encoding.</p></li>
                    988: 
                    989:          <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
                    990:          extracting an encoding from a Content-Type</a>, giving the
                    991:          attribute's value as the string to parse. If an encoding is
                    992:          returned, let <var title="">charset</var> be that
                    993:          encoding. Otherwise, return to step 2 in these inner
                    994:          steps.</p></li>
                    995: 
                    996:          <li><p>If <var title="">charset</var> is a UTF-16 encoding,
                    997:          change the value of <var title="">charset</var> to
                    998:          UTF-8.</p></li>
                    999: 
                   1000:          <li><p>If <var title="">charset</var> is a supported
                   1001:          character encoding, then return the given encoding, with
                   1002:          <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1003:          <i>tentative</i>, and abort all these steps.</p></li>
                   1004: 
                   1005:          <li><p>Otherwise, return to step 2 in these inner
                   1006:          steps.</p></li>
                   1007: 
                   1008:         </ol></dd>
                   1009: 
                   1010:        <dt>A sequence of bytes starting with a 0x3C byte (ASCII '&lt;'), optionally a 0x2F byte (ASCII '/'), and finally a byte in the range 0x41-0x5A or 0x61-0x7A (an ASCII letter)</dt>
                   1011:        <dd>
                   1012: 
                   1013:         <ol><li><p>Advance the <var title="">position</var> pointer so
                   1014:          that it points at the next 0x09 (ASCII TAB), 0x0A (ASCII LF),
                   1015:          0x0C (ASCII FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E
                   1016:          (ASCII '&gt;') byte.</p></li>
                   1017: 
                   1018:          <li><p>Repeatedly <a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
                   1019:          attribute</a> until no further attributes can be found,
                   1020:          then jump to the second step in the overall "two step"
                   1021:          algorithm.</p></li>
                   1022: 
                   1023:         </ol></dd>
                   1024: 
                   1025:        <dt>A sequence of bytes starting with: 0x3C 0x21 (ASCII '&lt;!')</dt>
                   1026:        <dt>A sequence of bytes starting with: 0x3C 0x2F (ASCII '&lt;/')</dt>
                   1027:        <dt>A sequence of bytes starting with: 0x3C 0x3F (ASCII '&lt;?')</dt>
                   1028:        <dd>
                   1029: 
                   1030:         <p>Advance the <var title="">position</var> pointer so that it
                   1031:         points at the first 0x3E byte (ASCII '&gt;') that comes after the
                   1032:         0x3C byte that was found.</p>
                   1033: 
                   1034:        </dd>
                   1035: 
                   1036:        <dt>Any other byte</dt>
                   1037:        <dd>
                   1038: 
                   1039:         <p>Do nothing with that byte.</p>
                   1040: 
                   1041:        </dd>
                   1042: 
                   1043:       </dl></li>
                   1044: 
                   1045:      <li>Move <var title="">position</var> so it points at the next
                   1046:      byte in the input stream, and return to the first step of this
                   1047:      "two step" algorithm.</li>
                   1048: 
                   1049:     </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
                   1050:     attribute</dfn>, it means doing this:</p>
                   1051: 
                   1052:     <ol><li><p>If the byte at <var title="">position</var> is one of 0x09
                   1053:      (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII FF), 0x0D (ASCII CR),
                   1054:      0x20 (ASCII space), or 0x2F (ASCII '/') then advance <var title="">position</var> to the next byte and redo this
                   1055:      substep.</p></li>
                   1056: 
                   1057:      <li><p>If the byte at <var title="">position</var> is 0x3E (ASCII
                   1058:      '&gt;'), then abort the "get an attribute" algorithm. There isn't
                   1059:      one.</p></li>
                   1060: 
                   1061:      <li><p>Otherwise, the byte at <var title="">position</var> is the
                   1062:      start of the attribute name. Let <var title="">attribute
                   1063:      name</var> and <var title="">attribute value</var> be the empty
                   1064:      string.</p></li>
                   1065: 
                   1066:      <li><p><i>Attribute name</i>: Process the byte at <var title="">position</var> as follows:</p>
                   1067: 
                   1068:       <dl class="switch"><dt>If it is 0x3D (ASCII '='), and the <var title="">attribute
                   1069:        name</var> is longer than the empty string</dt>
                   1070: 
                   1071:        <dd>Advance <var title="">position</var> to the next byte and
                   1072:        jump to the step below labeled <i>value</i>.</dd>
                   1073: 
                   1074:        <dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
                   1075:        FF), 0x0D (ASCII CR), or 0x20 (ASCII space)</dt>
                   1076: 
                   1077:        <dd>Jump to the step below labeled <i>spaces</i>.</dd>
                   1078: 
                   1079:        <dt>If it is 0x2F (ASCII '/') or 0x3E (ASCII '&gt;')</dt>
                   1080: 
                   1081:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1082:        name is the value of <var title="">attribute name</var>, its
                   1083:        value is the empty string.</dd>
                   1084: 
                   1085:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1086:        'Z')</dt>
                   1087: 
                   1088:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1089:        name</var> (where <var title="">b</var> is the value of the
                   1090:        byte at <var title="">position</var>).</dd>
                   1091: 
                   1092:        <dt>Anything else</dt>
                   1093: 
                   1094:        <dd>Append the Unicode character with the same code point as the
                   1095:        value of the byte at <var title="">position</var>) to <var title="">attribute name</var>. (It doesn't actually matter how
                   1096:        bytes outside the ASCII range are handled here, since only
                   1097:        ASCII characters can contribute to the detection of a character
                   1098:        encoding.)</dd>
                   1099: 
                   1100:       </dl></li>
                   1101: 
                   1102:      <li><p>Advance <var title="">position</var> to the next byte and
                   1103:      return to the previous step.</p></li>
                   1104: 
                   1105:      <li><p><i>Spaces</i>: If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
                   1106:      LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
                   1107:      advance <var title="">position</var> to the next byte, then,
                   1108:      repeat this step.</p></li>
                   1109: 
                   1110:      <li><p>If the byte at <var title="">position</var> is
                   1111:      <em>not</em> 0x3D (ASCII '='), abort the "get an attribute"
                   1112:      algorithm. The attribute's name is the value of <var title="">attribute name</var>, its value is the empty
                   1113:      string.</p></li>
                   1114: 
                   1115:      <li><p>Advance <var title="">position</var> past the 0x3D (ASCII
                   1116:      '=') byte.</p></li>
                   1117: 
                   1118:      <li><p><i>Value:</i> If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
                   1119:      LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
                   1120:      advance <var title="">position</var> to the next byte, then,
                   1121:      repeat this step.</p></li>
                   1122: 
                   1123:      <li><p>Process the byte at <var title="">position</var> as
                   1124:      follows:</p>
                   1125: 
                   1126:       <dl class="switch"><dt>If it is 0x22 (ASCII '"') or 0x27 ("'")</dt>
                   1127: 
                   1128:        <dd>
                   1129: 
                   1130:         <ol><li>Let <var title="">b</var> be the value of the byte at
                   1131:          <var title="">position</var>.</li>
                   1132: 
                   1133:          <li>Advance <var title="">position</var> to the next
                   1134:          byte.</li>
                   1135: 
                   1136:          <li>If the value of the byte at <var title="">position</var>
                   1137:          is the value of <var title="">b</var>, then advance <var title="">position</var> to the next byte and abort the "get
                   1138:          an attribute" algorithm. The attribute's name is the value of
                   1139:          <var title="">attribute name</var>, and its value is the
                   1140:          value of <var title="">attribute value</var>.</li>
                   1141: 
                   1142:          <li>Otherwise, if the value of the byte at <var title="">position</var> is in the range 0x41 (ASCII 'A') to
                   1143:          0x5A (ASCII 'Z'), then append a Unicode character to <var title="">attribute value</var> whose code point is 0x20 more
                   1144:          than the value of the byte at <var title="">position</var>.</li>
                   1145: 
                   1146:          <li>Otherwise, append a Unicode character to <var title="">attribute value</var> whose code point is the same as
                   1147:          the value of the byte at <var title="">position</var>.</li>
                   1148: 
                   1149:          <li>Return to the second step in these substeps.</li>
                   1150: 
                   1151:         </ol></dd>
                   1152: 
                   1153:        <dt>If it is 0x3E (ASCII '&gt;')</dt>
                   1154: 
                   1155:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1156:        name is the value of <var title="">attribute name</var>, its
                   1157:        value is the empty string.</dd>
                   1158: 
                   1159: 
                   1160:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1161:        'Z')</dt>
                   1162: 
                   1163:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1164:        value</var> (where <var title="">b</var> is the value of the
                   1165:        byte at <var title="">position</var>). Advance <var title="">position</var> to the next byte.</dd>
                   1166: 
                   1167:        <dt>Anything else</dt>
                   1168: 
                   1169:        <dd>Append the Unicode character with the same code point as the
                   1170:        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>
                   1171: 
                   1172:       </dl></li>
                   1173: 
                   1174:      <li><p>Process the byte at <var title="">position</var> as
                   1175:      follows:</p>
                   1176: 
                   1177:       <dl class="switch"><dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
                   1178:        FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E (ASCII
                   1179:        '&gt;')</dt>
                   1180: 
                   1181:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1182:        name is the value of <var title="">attribute name</var> and its
                   1183:        value is the value of <var title="">attribute value</var>.</dd>
                   1184: 
                   1185:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1186:        'Z')</dt>
                   1187: 
                   1188:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1189:        value</var> (where <var title="">b</var> is the value of the
                   1190:        byte at <var title="">position</var>).</dd>
                   1191: 
                   1192:        <dt>Anything else</dt>
                   1193: 
                   1194:        <dd>Append the Unicode character with the same code point as the
                   1195:        value of the byte at <var title="">position</var>) to <var title="">attribute value</var>.</dd>
                   1196: 
                   1197:       </dl></li>
                   1198: 
                   1199:      <li><p>Advance <var title="">position</var> to the next byte and
                   1200:      return to the previous step.</p></li>
                   1201: 
                   1202:     </ol><p>For the sake of interoperability, user agents should not use a
                   1203:     pre-scan algorithm that returns different results than the one
                   1204:     described above. (But, if you do, please at least let us know, so
                   1205:     that we can improve this algorithm and benefit everyone...)</p>
                   1206: 
                   1207:    </li>
                   1208: 
                   1209:    <li><p>If the user agent has information on the likely encoding for
                   1210:    this page, e.g. based on the encoding of the page when it was last
                   1211:    visited, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1212:    <i>tentative</i>, and abort these steps.</p></li>
                   1213: 
                   1214:    <li><p>The user agent may attempt to autodetect the character
                   1215:    encoding from applying frequency analysis or other algorithms to
                   1216:    the data stream. If autodetection succeeds in determining a
                   1217:    character encoding, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1.104     mike     1218:    <i>tentative</i>, and abort these steps. <a href="references.html#refsUNIVCHARDET">[UNIVCHARDET]</a></p></li>
1.1       mike     1219: 
                   1220:    <li><p>Otherwise, return an implementation-defined or
                   1221:    user-specified default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1222:    <i>tentative</i>. In non-legacy environments, the more
                   1223:    comprehensive <code title="">UTF-8</code> encoding is
                   1224:    recommended. Due to its use in legacy content, <code title="">windows-1252</code> is recommended as a default in
1.187     mike     1225:    predominantly Western demographics instead.</p></li>
1.1       mike     1226: 
                   1227:   </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
                   1228:   be set to the value returned from this algorithm, at the same time
                   1229:   as the user agent uses the returned value to select the decoder to
                   1230:   use for the input stream.</p>
                   1231: 
                   1232: 
1.237     mike     1233:   <h5 id="character-encodings-0"><span class="secno">9.2.2.2 </span>Character encodings</h5><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p>
1.1       mike     1234: 
1.237     mike     1235:   <p>User agents must at a minimum support the UTF-8 and Windows-1252
                   1236:   encodings, but may support more.</p>
                   1237: 
                   1238:   <p class="note">It is not unusual for Web browsers to support dozens
                   1239:   if not upwards of a hundred distinct character encodings.</p>
                   1240: 
                   1241:   <p>User agents must support the preferred MIME name of every
                   1242:   character encoding they support that has a preferred MIME name, and
                   1243:   should support all the IANA-registered aliases of every character
                   1244:   encoding they support. <a href="references.html#refsIANACHARSET">[IANACHARSET]</a></p>
                   1245: 
                   1246:   <p>When comparing a string specifying a character encoding with the
                   1247:   name or alias of a character encoding to determine if they are
                   1248:   equal, user agents must remove any leading or trailing <a href="infrastructure.html#space-character" title="space character">space characters</a> in both names, and
                   1249:   then perform the comparison in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   1250:   case-insensitive</a> manner.</p>
                   1251: 
                   1252: <!-- this bit will be replaced by actual alias registrations in due course -->
                   1253: 
                   1254:   <p>In addition, user agents must support the aliases given in the
                   1255:   following table for every character encoding they support, so that
                   1256:   labels from the first column are treated as equivalent to the labels
                   1257:   given in the corresponding cell from the second column on the same
                   1258:   row.</p>
                   1259: 
                   1260:   <table><caption>Additional character encoding aliases</caption>
                   1261:    <thead><tr><th> Alias </th><th> Corresponding encoding </th><th> References
                   1262:    </th></tr></thead><tbody><tr><td> x-sjis </td><td> windows-31J </td><td>
                   1263:          <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
                   1264:          <a href="references.html#refsWIN31J">[WIN31J]</a>
                   1265:     </td></tr><tr><td> windows-932 </td><td> windows-31J </td><td>
                   1266:          <a href="references.html#refsWIN31J">[WIN31J]</a>
                   1267:     </td></tr><tr><td> x-x-big5 </td><td> Big5 </td><td>
                   1268:          <a href="references.html#refsBIG5">[BIG5]</a>
                   1269:    </td></tr></tbody></table><!-- end of bit that will be replaced by actual alias registrations in due course --><hr><p>When a user agent would otherwise use an encoding given in the
                   1270:   first column of the following table to either convert content to
                   1271:   Unicode characters or convert Unicode characters to bytes, it must
                   1272:   instead use the encoding given in the cell in the second column of
                   1273:   the same row. When a byte or sequence of bytes is treated
                   1274:   differently due to this encoding aliasing, it is said to have been
                   1275:   <dfn id="misinterpreted-for-compatibility">misinterpreted for compatibility</dfn>.</p>
                   1276: 
                   1277:   <table><caption>Character encoding overrides</caption>
                   1278:    <thead><tr><th> Input encoding </th><th> Replacement encoding </th><th> References
                   1279:    </th></tr></thead><tbody><!-- how about EUC-JP? --><tr><td> EUC-KR </td><td> windows-949 </td><td>
                   1280:          <a href="references.html#refsEUCKR">[EUCKR]</a>
                   1281:          <a href="references.html#refsWIN949">[WIN949]</a>
                   1282:     </td></tr><tr><td> GB2312 </td><td> GBK </td><td>
                   1283:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1284:          <a href="references.html#refsGBK">[GBK]</a>
                   1285:     </td></tr><tr><td> GB_2312-80 </td><td> GBK </td><td>
                   1286:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1287:          <a href="references.html#refsGBK">[GBK]</a>
                   1288:     </td></tr><tr><td> ISO-8859-1 </td><td> windows-1252 </td><td>
                   1289:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1290:          <a href="references.html#refsWIN1252">[WIN1252]</a>
                   1291:     </td></tr><tr><td> ISO-8859-9 </td><td> windows-1254 </td><td>
                   1292:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1293:          <a href="references.html#refsWIN1254">[WIN1254]</a>
                   1294:     </td></tr><tr><td> ISO-8859-11 </td><td> windows-874 </td><td>
                   1295:          <a href="references.html#refsISO885911">[ISO885911]</a>
                   1296:          <a href="references.html#refsWIN874">[WIN874]</a>
                   1297:     </td></tr><tr><td> KS_C_5601-1987 </td><td> windows-949 </td><td>
                   1298:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1299:          <a href="references.html#refsWIN949">[WIN949]</a>
                   1300:     </td></tr><tr><td> Shift_JIS </td><td> windows-31J </td><td>
                   1301:          <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
                   1302:          <a href="references.html#refsWIN31J">[WIN31J]</a>
                   1303:     </td></tr><tr><td> TIS-620 </td><td> windows-874 </td><td>
                   1304:          <a href="references.html#refsTIS620">[TIS620]</a>
                   1305:          <a href="references.html#refsWIN874">[WIN874]</a>
                   1306:     </td></tr><tr><td> US-ASCII </td><td> windows-1252 </td><td>
                   1307:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1308:          <a href="references.html#refsWIN1252">[WIN1252]</a>
                   1309:    </td></tr></tbody></table><p class="note">The requirement to treat certain encodings as other
                   1310:   encodings according to the table above is a <a href="introduction.html#willful-violation">willful
                   1311:   violation</a> of the W3C Character Model specification, motivated
                   1312:   by a desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
                   1313: 
                   1314:   <p>When a user agent is to use the UTF-16 encoding but no BOM has
                   1315:   been found, user agents must default to UTF-16LE.</p>
                   1316: 
                   1317:   <p class="note">The requirement to default UTF-16 to LE rather than
                   1318:   BE is a <a href="introduction.html#willful-violation">willful violation</a> of RFC 2781, motivated by a
                   1319:   desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
                   1320: 
                   1321:   <hr><p>User agents must not support the CESU-8, UTF-7, BOCU-1 and SCSU
                   1322:   encodings. <a href="references.html#refsCESU8">[CESU8]</a> <a href="references.html#refsUTF7">[UTF7]</a> <a href="references.html#refsBOCU1">[BOCU1]</a> <a href="references.html#refsSCSU">[SCSU]</a></p>
                   1323: 
                   1324:   <p>Support for encodings based on EBCDIC is not recommended. This
                   1325:   encoding is rarely used for publicly-facing Web content.</p>
                   1326: 
                   1327:   <p>Support for UTF-32 is not recommended. This encoding is rarely
                   1328:   used, and frequently implemented incorrectly.</p>
                   1329: 
                   1330:   <p class="note">This specification does not make any attempt to
                   1331:   support EBCDIC-based encodings and UTF-32 in its algorithms; support
                   1332:   and use of these encodings can thus lead to unexpected behavior in
                   1333:   implementations of this specification.</p>
                   1334: 
                   1335: 
                   1336: 
                   1337:   <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.3 </span>Preprocessing the input stream</h5>
1.1       mike     1338: 
                   1339:   <p>Given an encoding, the bytes in the input stream must be
                   1340:   converted to Unicode characters for the tokenizer, as described by
                   1341:   the rules for that encoding, except that the leading U+FEFF BYTE
                   1342:   ORDER MARK character, if any, must not be stripped by the encoding
                   1343:   layer (it is stripped by the rule below).</p> <!-- this is to
                   1344:   prevent two leading BOMs from being both stripped, once by the
                   1345:   decoder, and once by the parser -->
                   1346: 
                   1347:   <p>Bytes or sequences of bytes in the original byte stream that
                   1348:   could not be converted to Unicode characters must be converted to
                   1349:   U+FFFD REPLACEMENT CHARACTER code points.</p>
                   1350: 
                   1351:   <p class="note">Bytes or sequences of bytes in the original byte
                   1352:   stream that did not conform to the encoding specification
                   1353:   (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
                   1354:   errors that conformance checkers are expected to report.</p>
                   1355: 
                   1356:   <p>Any byte or sequences of bytes in the original byte stream that
1.237     mike     1357:   is <a href="#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
1.1       mike     1358:   error</a>.</p>
                   1359: 
                   1360:   <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
                   1361:   any are present.</p>
                   1362: 
                   1363:   <p>All U+0000 NULL characters in the input must be replaced by
                   1364:   U+FFFD REPLACEMENT CHARACTERs. Any occurrences of such characters is
                   1365:   a <a href="#parse-error">parse error</a>.</p>
                   1366: 
                   1367:   <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
                   1368:   <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
                   1369:   CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
                   1370:   <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+D800
                   1371:   to U+DFFF<!-- surrogates not allowed -->, U+FDD0 to U+FDEF, and
                   1372:   characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF, U+2FFFE,
                   1373:   U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE, U+5FFFF,
                   1374:   U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF, U+9FFFE,
                   1375:   U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE, U+CFFFF,
                   1376:   U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF, U+10FFFE, and
                   1377:   U+10FFFF are <a href="#parse-error" title="parse error">parse errors</a>. (These
                   1378:   are all control characters or permanently undefined Unicode
                   1379:   characters.)</p>
                   1380: 
                   1381:   <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
                   1382:   characters are treated specially. Any CR characters that are
                   1383:   followed by LF characters must be removed, and any CR characters not
                   1384:   followed by LF characters must be converted to LF characters. Thus,
                   1385:   newlines in HTML DOMs are represented by LF characters, and there
                   1386:   are never any CR characters in the input to the
                   1387:   <a href="#tokenization">tokenization</a> stage.</p>
                   1388: 
                   1389:   <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
                   1390:   input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
                   1391:   the <i><a href="#next-input-character">next input character</a></i> is the first character in the
                   1392:   input. The <dfn id="current-input-character">current input character</dfn> is the last character
                   1393:   to have been <i><a href="#consumed">consumed</a></i>.</p>
                   1394: 
                   1395:   <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
                   1396:   character or just before the end of the input stream) where content
1.159     mike     1397:   inserted using <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code> is actually
1.1       mike     1398:   inserted. The insertion point is relative to the position of the
                   1399:   character immediately after it, it is not an absolute offset into
                   1400:   the input stream. Initially, the insertion point is
1.10      mike     1401:   undefined.</p>
1.1       mike     1402: 
                   1403:   <p>The "EOF" character in the tables below is a conceptual character
                   1404:   representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
1.159     mike     1405:   is a <a href="embedded-content-0.html#script-created-parser">script-created parser</a>, then the end of the
1.1       mike     1406:   <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
1.159     mike     1407:   character</dfn> (inserted by the <code title="dom-document-close"><a href="embedded-content-0.html#dom-document-close">document.close()</a></code> method) is
1.1       mike     1408:   consumed. Otherwise, the "EOF" character is not a real character in
                   1409:   the stream, but rather the lack of any further characters.</p>
                   1410: 
                   1411: 
1.237     mike     1412:   <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.4 </span>Changing the encoding while parsing</h5>
1.1       mike     1413: 
                   1414:   <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
                   1415:   encoding</dfn>, it must run the following steps. This might happen
                   1416:   if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
                   1417:   failed to find an encoding, or if it found an encoding that was not
                   1418:   the actual encoding of the file.</p>
                   1419: 
                   1420:   <ol><li>If the new encoding is identical or equivalent to the encoding
                   1421:    that is already being used to interpret the input stream, then set
                   1422:    the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1423:    <i>certain</i> and abort these steps. This happens when the
                   1424:    encoding information found in the file matches what the
                   1425:    <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
                   1426:    encoding, and in the second pass through the parser if the first
                   1427:    pass found that the encoding sniffing algorithm described in the
                   1428:    earlier section failed to find the right encoding.</li>
                   1429: 
                   1430:    <li>If the encoding that is already being used to interpret the
                   1431:    input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1432:    <i>certain</i> and abort these steps. The new encoding is ignored;
                   1433:    if it was anything but the same encoding, then it would be clearly
                   1434:    incorrect.</li>
                   1435: 
                   1436:    <li>If the new encoding is a UTF-16 encoding, change it to
                   1437:    UTF-8.</li>
                   1438: 
                   1439:    <li>If all the bytes up to the last byte converted by the current
                   1440:    decoder have the same Unicode interpretations in both the current
                   1441:    encoding and the new encoding, and if the user agent supports
                   1442:    changing the converter on the fly, then the user agent may change
                   1443:    to the new converter for the encoding on the fly. Set the
                   1444:    <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
                   1445:    convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1446:    <i>certain</i>, and abort these steps.</li>
                   1447: 
                   1448:    <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
                   1449:    <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
                   1450:    browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
                   1451:    sniffing algorithm</a> and instead just set the encoding to the
                   1452:    new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1453:    <i>certain</i>. Whenever possible, this should be done without
                   1454:    actually contacting the network layer (the bytes should be
                   1455:    re-parsed from memory), even if, e.g., the document is marked as
                   1456:    not being cacheable. If this is not possible and contacting the
                   1457:    network layer would involve repeating a request that uses a method
                   1458:    other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
                   1459:    equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1460:    <i>certain</i> and ignore the new encoding. The resource will be
                   1461:    misinterpreted. User agents may notify the user of the situation,
                   1462:    to aid in application development.</li>
                   1463: 
                   1464:   </ol><h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4>
                   1465: 
                   1466:   <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5>
                   1467: 
                   1468:   <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
                   1469:   the primary operation of the tree construction stage.</p>
                   1470: 
                   1471:   <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
                   1472:   "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
                   1473:   "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
                   1474:   "<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     1475:   "<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     1476:   "<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>",
                   1477:   "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
                   1478:   "<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
                   1479:   table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
                   1480:   foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
                   1481:   body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
                   1482:   frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
                   1483:   frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
                   1484:   after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
                   1485:   frameset</a>" during the course of the parsing, as described in
                   1486:   the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
                   1487:   how tokens are processed and whether CDATA sections are
                   1488:   supported.</p>
                   1489: 
                   1490:   <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
                   1491:   head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   1492:   body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
                   1493:   table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   1494:   body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
                   1495:   "<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
                   1496:   that the other modes defer to them at various times. When the
                   1497:   algorithm below says that the user agent is to do something
                   1498:   "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
                   1499:   mode", where <var title="">m</var> is one of these modes, the user
                   1500:   agent must use the rules described under the <var title="">m</var>
                   1501:   <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
                   1502:   <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>
                   1503:   to a new value.</p>
                   1504: 
                   1505:   <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.91      mike     1506:   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     1507:   <dfn id="original-insertion-mode">original insertion mode</dfn> is also set. This is the
                   1508:   insertion mode to which the tree construction stage will return.</p>
                   1509: 
                   1510:   <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
                   1511:   mode: in foreign content">in foreign content</a>", the
                   1512:   <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
                   1513:   is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1514:   foreign content">in foreign content</a>" mode to handle HTML
                   1515:   (i.e. not foreign) content.</p>
                   1516: 
                   1517:   <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
                   1518:   mode appropriately</dfn>, it means the UA must follow these
                   1519:   steps:</p>
                   1520: 
                   1521:   <ol><li>Let <var title="">last</var> be false.</li>
                   1522: 
                   1523:    <li>Let <var title="">node</var> be the last node in the
                   1524:    <a href="#stack-of-open-elements">stack of open elements</a>.</li>
                   1525: 
                   1526:    <li>If <var title="">node</var> is the first node in the stack of
                   1527:    open elements, then set <var title="">last</var> to true and set
                   1528:    <var title="">node</var> to the <var title="">context</var>
                   1529:    element. (<a href="#fragment-case">fragment case</a>)</li>
                   1530: 
                   1531:    <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
                   1532:    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
                   1533:    steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1534: 
                   1535:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
                   1536:    <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
                   1537:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
                   1538:    mode: in cell">in cell</a>" and abort these steps.</li>
                   1539: 
                   1540:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
                   1541:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
                   1542:    mode: in row">in row</a>" and abort these steps.</li>
                   1543: 
                   1544:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
                   1545:    <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
                   1546:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
                   1547:    table body">in table body</a>" and abort these steps.</li>
                   1548: 
                   1549:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
                   1550:    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
                   1551:    these steps.</li>
                   1552: 
                   1553:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
                   1554:    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
                   1555:    abort these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1556: 
                   1557:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   1558:    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
                   1559:    steps.</li>
                   1560: 
                   1561:    <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
                   1562:    namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then switch the
                   1563:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1564:    foreign content">in foreign content</a>", let the
                   1565:    <a href="#secondary-insertion-mode">secondary insertion mode</a> be "<a href="#parsing-main-inbody" title="insertion
                   1566:    mode: in body">in body</a>", and abort these steps.</li>
                   1567: 
1.159     mike     1568:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element-0">head</a></code> element,
1.1       mike     1569:    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
                   1570:    these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- This is only
                   1571:    here for now in case people think that the spec accidentally
                   1572:    omitted it and try to "fix" it. Note that noscript-in-head is also
                   1573:    handled this way. This is all intentional. The only thing it
                   1574:    doesn't handle is the scripting-disabled fragment parsing case for
                   1575:    a <head> element containing a <noscript> which itself contains
                   1576:    something other than a <link> or a <style> element; you'd expect
                   1577:    that to break out of the <noscript> but it doesn't. This is an edge
                   1578:    case that doesn't affect the spec, since the algorithm for fragment
                   1579:    parsing is only used for innerHTML/outerHTML/insertAdjacentHTML(),
                   1580:    where we know scripting is enabled. (XXX except maybe if innerHTML
                   1581:    is set from another browsing context on a document with designMode
                   1582:    set?) -->
                   1583: 
1.159     mike     1584:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element-0">body</a></code> element,
1.1       mike     1585:    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
                   1586:    steps.</li>
                   1587: 
1.5       mike     1588:    <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.1       mike     1589:    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
                   1590:    these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1591: 
1.159     mike     1592:    <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element-0">html</a></code> element,
1.1       mike     1593:    then: if the <a href="#head-element-pointer"><code title="">head</code> element
                   1594:    pointer</a> is null, switch the <a href="#insertion-mode">insertion mode</a> to
                   1595:    "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
                   1596:    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
                   1597:    case, abort these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- XXX
                   1598:    can the head element pointer ever be non-null when we're going
                   1599:    through these steps? -->
                   1600: 
                   1601:    <li>If <var title="">last</var> is true, then switch the
                   1602:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
                   1603:    body">in body</a>" and abort these steps. (<a href="#fragment-case">fragment
                   1604:    case</a>)</li>
                   1605: 
                   1606:    <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
                   1607:    elements</a>.</li>
                   1608: 
                   1609:    <li>Return to step 3.</li>
                   1610: 
                   1611:   </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5>
                   1612: 
                   1613:   <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
                   1614:   stack grows downwards; the topmost node on the stack is the first
                   1615:   one added to the stack, and the bottommost node of the stack is the
                   1616:   most recently added node in the stack (notwithstanding when the
                   1617:   stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
                   1618: 
                   1619:   <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
                   1620:   html</a>" <a href="#insertion-mode">insertion mode</a> creates the
1.159     mike     1621:   <code><a href="semantics.html#the-html-element-0">html</a></code> root element node, which is then added to the
1.1       mike     1622:   stack.</p>
                   1623: 
                   1624:   <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
1.159     mike     1625:   elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1       mike     1626:   element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
                   1627:   parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
                   1628:   case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
                   1629:   html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
                   1630: 
1.159     mike     1631:   <p>The <code><a href="semantics.html#the-html-element-0">html</a></code> node, however it is created, is the topmost
1.1       mike     1632:   node of the stack. It never gets popped off the stack.</p>
                   1633: 
                   1634:   <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
                   1635:   stack.</p>
                   1636: 
                   1637:   <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
                   1638:   element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
                   1639:   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
                   1640:   open elements</a> (<a href="#fragment-case">fragment case</a>), then the
                   1641:   <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
1.159     mike     1642:   of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code> element).</p>
1.1       mike     1643: 
                   1644:   <p>Elements in the stack fall into the following categories:</p>
                   1645: 
                   1646:   <dl><dt><dfn id="special">Special</dfn></dt>
                   1647: 
                   1648:    <dd><p>The following HTML elements have varying levels of special
                   1649:    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>,
                   1650:    <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     1651:    <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.159     mike     1652:    <code><a href="semantics.html#the-blockquote-element">blockquote</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="semantics.html#the-br-element">br</a></code>,
1.5       mike     1653:    <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     1654:    <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
                   1655:    <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>,
                   1656:    <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>,
1.159     mike     1657:    <code><a href="semantics.html#the-dt-element">dt</a></code>, <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>, <code><a href="forms.html#the-fieldset-element">fieldset</a></code>,
                   1658:    <code><a href="text-level-semantics.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>,
1.86      mike     1659:    <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>,
                   1660:    <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>,
1.159     mike     1661:    <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-0">head</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>,
                   1662:    <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="text-level-semantics.html#the-iframe-element">iframe</a></code>, <!--
1.86      mike     1663:    <code>image</code>, (commented out because this isn't an element
                   1664:    that can end up on the stack, so it doesn't matter) -->
1.159     mike     1665:    <code><a href="text-level-semantics.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="obsolete.html#isindex-0">isindex</a></code>,
1.86      mike     1666:    <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>,
                   1667:    <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>,
                   1668:    <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>,
1.159     mike     1669:    <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="text-level-semantics.html#the-param-element">param</a></code>,
1.86      mike     1670:    <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>,
                   1671:    <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>,
                   1672:    <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>,
1.159     mike     1673:    <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-0">title</a></code>,
1.174     mike     1674:    <code><a href="tabular-data.html#the-tr-element">tr</a></code>, <code><a href="semantics.html#the-ul-element">ul</a></code>, <code>wbr</code>, and
                   1675:    <code><a href="obsolete.html#xmp">xmp</a></code>.</p></dd>
1.1       mike     1676: 
                   1677:    <dt><dfn id="scoping">Scoping</dfn></dt>
                   1678:    <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
                   1679:    an element in scope">scopes</a> for various parts of the
1.5       mike     1680:    parsing: <code><a href="obsolete.html#the-applet-element">applet</a></code>, <code><a href="forms.html#the-button-element">button</a></code>,
1.159     mike     1681:    <code><a href="tabular-data.html#the-caption-element">caption</a></code>, <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="obsolete.html#the-marquee-element">marquee</a></code>,
                   1682:    <code><a href="text-level-semantics.html#the-object-element">object</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>, <code><a href="tabular-data.html#the-td-element">td</a></code>,
1.1       mike     1683:    <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
                   1684: 
                   1685:    <dt><dfn id="formatting">Formatting</dfn></dt>
                   1686:    <dd><p>The following HTML elements are those that end up in the
                   1687:    <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     1688:    <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>,
                   1689:    <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>,
                   1690:    <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>,
                   1691:    <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
                   1692:    <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1       mike     1693: 
                   1694:    <dt><dfn id="phrasing">Phrasing</dfn></dt>
                   1695:    <dd><p>All other elements found while parsing an HTML
                   1696:    document.</p></dd>
                   1697: 
1.234     mike     1698:   </dl><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-the-specific-scope" title="has an element in the specific scope">have an element in a
                   1699:   specific scope</dfn> consisting of a list of element types <var title="">list</var> when the following algorithm terminates in a
                   1700:   match state:</p>
1.1       mike     1701: 
                   1702:   <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   1703:    node</a> (the bottommost node of the stack).</p></li>
                   1704: 
                   1705:    <li><p>If <var title="">node</var> is the target node, terminate in
                   1706:    a match state.</p></li>
                   1707: 
1.234     mike     1708:    <li><p>Otherwise, if <var title="">node</var> is one of the element
                   1709:    types in <var title="">list</var>, terminate in a failure
                   1710:    state.</p></li>
1.1       mike     1711: 
                   1712:    <li><p>Otherwise, set <var title="">node</var> to the previous
                   1713:    entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
                   1714:    2. (This will never fail, since the loop will always terminate in
                   1715:    the previous step if the top of the stack &#8212; an
1.159     mike     1716:    <code><a href="semantics.html#the-html-element-0">html</a></code> element &#8212; is reached.)</p></li>
1.1       mike     1717: 
1.234     mike     1718:   </ol><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-scope" title="has an element in scope">have an element in scope</dfn> when
                   1719:   it <a href="#has-an-element-in-the-specific-scope">has an element in the specific scope</a> consisting
                   1720:   of the following element types:</p>
                   1721: 
                   1722:   <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
                   1723:    <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
                   1724:    <li><code><a href="semantics.html#the-html-element-0">html</a></code> in the HTML namespace</li> <!-- (This can only happen if the <var title="">node</var> is the topmost node of the <span>stack of open elements</span>, and prevents the next step from being invoked if there are no more elements in the stack.) -->
                   1725:    <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1726:    <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
                   1727:    <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
                   1728:    <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
                   1729:    <li><code><a href="obsolete.html#the-marquee-element">marquee</a></code> in the HTML namespace</li>
                   1730:    <li><code><a href="text-level-semantics.html#the-object-element">object</a></code> in the HTML namespace</li>
                   1731:    <li><code title="">foreignObject</code> in the SVG namespace</li>
                   1732:   </ul><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-list-item-scope" title="has an element in list item scope">have an element in list
                   1733:   item scope</dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
                   1734:   scope</a> consisting of the following element types:</p>
                   1735: 
                   1736:   <ul class="brief"><li>All the element types listed above for the <i><a href="#has-an-element-in-scope">has an element
                   1737:    in scope</a></i> algorithm.</li>
                   1738:    <li><code><a href="semantics.html#the-ol-element">ol</a></code> in the HTML namespace</li>
                   1739:    <li><code><a href="semantics.html#the-ul-element">ul</a></code> in the HTML namespace</li>
                   1740:   </ul><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-table-scope" title="has an element in table scope">have an element in <em>table
                   1741:   scope</em></dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
                   1742:   scope</a> consisting of the following element types:</p>
                   1743: 
                   1744:   <ul class="brief"><li><code><a href="semantics.html#the-html-element-0">html</a></code> in the HTML namespace</li> <!-- (This can only happen if the <var title="">node</var> is the topmost node of the <span>stack of open elements</span>, and prevents the next step from being invoked if there are no more elements in the stack.) -->
                   1745:    <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1746:   </ul><p>Nothing happens if at any time any of the elements in the
1.1       mike     1747:   <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
                   1748:   or removed from, the <code>Document</code> tree. In particular, the
                   1749:   stack is not changed in this situation. This can cause, amongst
                   1750:   other strange effects, content to be appended to nodes that are no
                   1751:   longer in the DOM.</p>
                   1752: 
                   1753:   <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
                   1754:   the stack is manipulated in a random-access fashion.</p>
                   1755: 
                   1756: 
                   1757:   <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5>
                   1758: 
                   1759:   <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
                   1760:   empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
                   1761: 
                   1762:   <p>The list contains elements in the <a href="#formatting">formatting</a>
                   1763:   category, and scope markers. The scope markers are inserted when
1.159     mike     1764:   entering <code><a href="obsolete.html#the-applet-element">applet</a></code> elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code>
1.1       mike     1765:   elements, marquees, table cells, and table captions, and are used to
1.5       mike     1766:   prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.159     mike     1767:   elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code> elements, marquees, and
1.1       mike     1768:   tables.</p>
                   1769: 
                   1770:   <p class="note">The scope markers are unrelated to the concept of an
                   1771:   element being <a href="#has-an-element-in-scope" title="has an element in scope">in
                   1772:   scope</a>.</p>
                   1773: 
                   1774:   <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1775:   elements</a> is associated with the token for which it was
                   1776:   created, so that further elements can be created for that token if
                   1777:   necessary.</p>
                   1778: 
                   1779:   <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
                   1780:   active formatting elements</dfn>, the UA must perform the following
                   1781:   steps:</p>
                   1782: 
                   1783:   <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1784:    elements</a>, then there is nothing to reconstruct; stop this
                   1785:    algorithm.</li>
                   1786: 
                   1787:    <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
                   1788:    active formatting elements</a> is a marker, or if it is an
                   1789:    element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
                   1790:    there is nothing to reconstruct; stop this algorithm.</li>
                   1791: 
                   1792:    <li>Let <var title="">entry</var> be the last (most recently added)
                   1793:    element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1794:    elements</a>.</li>
                   1795: 
                   1796:    <li>If there are no entries before <var title="">entry</var> in the
                   1797:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
                   1798:    8.</li>
                   1799: 
                   1800:    <li>Let <var title="">entry</var> be the entry one earlier than
                   1801:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1802:    elements</a>.</li>
                   1803: 
                   1804:    <li>If <var title="">entry</var> is neither a marker nor an element
                   1805:    that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
                   1806:    4.</li>
                   1807: 
                   1808:    <li>Let <var title="">entry</var> be the element one later than
                   1809:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1810:    elements</a>.</li>
                   1811: 
                   1812:    <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   1813:    element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
                   1814: 
                   1815:    <li>Append <var title="">new element</var> to the <a href="#current-node">current
                   1816:    node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
                   1817:    elements</a> so that it is the new <a href="#current-node">current
                   1818:    node</a>.</li>
                   1819: 
                   1820:    <li>Replace the entry for <var title="">entry</var> in the list
                   1821:    with an entry for <var title="">new element</var>.</li>
                   1822: 
                   1823:    <li>If the entry for <var title="">new element</var> in the
                   1824:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
                   1825:    entry in the list, return to step 7.</li>
                   1826: 
                   1827:   </ol><p>This has the effect of reopening all the formatting elements that
                   1828:   were opened in the current body, cell, or caption (whichever is
                   1829:   youngest) that haven't been explicitly closed.</p>
                   1830: 
                   1831:   <p class="note">The way this specification is written, the
                   1832:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
                   1833:   elements in chronological order with the least recently added
                   1834:   element first and the most recently added element last (except for
                   1835:   while steps 8 to 11 of the above algorithm are being executed, of
                   1836:   course).</p>
                   1837: 
                   1838:   <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
                   1839:   active formatting elements up to the last marker</dfn>, the UA must
                   1840:   perform the following steps:</p>
                   1841: 
                   1842:   <ol><li>Let <var title="">entry</var> be the last (most recently added)
                   1843:    entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
                   1844: 
                   1845:    <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
                   1846:    formatting elements</a>.</li>
                   1847: 
                   1848:    <li>If <var title="">entry</var> was a marker, then stop the
                   1849:    algorithm at this point. The list has been cleared up to the last
                   1850:    marker.</li>
                   1851: 
                   1852:    <li>Go to step 1.</li>
                   1853: 
                   1854:   </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5>
                   1855: 
                   1856:   <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
                   1857:   pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
                   1858:   pointer</dfn> are both null.</p>
                   1859: 
1.159     mike     1860:   <p>Once a <code><a href="semantics.html#the-head-element-0">head</a></code> element has been parsed (whether
1.1       mike     1861:   implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
                   1862:   element pointer</a> gets set to point to this node.</p>
                   1863: 
                   1864:   <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   1865:   points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
                   1866:   whose end tag has not yet been seen. It is used to make form
                   1867:   controls associate with forms in the face of dramatically bad
                   1868:   markup, for historical reasons.</p>
                   1869: 
                   1870: 
                   1871:   <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5>
                   1872: 
                   1873:   <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
                   1874:   <code>Document</code> with which the parser is associated when the
                   1875:   parser was created, and "disabled" otherwise.</p>
                   1876: 
                   1877:   <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
                   1878:   when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
                   1879:   parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
                   1880:   don't execute in that case.</p>
                   1881: 
                   1882:   <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
                   1883:   created. It is set to "not ok" after certain tokens are seen.</p>
                   1884: 
                   1885: 
1.159     mike     1886:   <h4 id="tokenization"><span class="secno">9.2.4 </span><dfn>Tokenization</dfn></h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1       mike     1887: 
                   1888:   <p>Implementations must act as if they used the following state
                   1889:   machine to tokenize HTML. The state machine must start in the
                   1890:   <a href="#data-state">data state</a>. Most states consume a single character,
                   1891:   which may have various side-effects, and either switches the state
                   1892:   machine to a new state to <em>reconsume</em> the same character, or
                   1893:   switches it to a new state (to consume the next character), or
                   1894:   repeats the same state (to consume the next character). Some states
                   1895:   have more complicated behavior and can consume several characters
                   1896:   before switching to another state.</p>
                   1897: 
                   1898:   <p>The exact behavior of certain states depends on a <dfn id="content-model-flag">content
                   1899:   model flag</dfn> that is set after certain tokens are emitted. The
1.91      mike     1900:   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
                   1901:   state. In the RCDATA and RAWTEXT states, a further <dfn id="escape-flag">escape
1.1       mike     1902:   flag</dfn> is used to control the behavior of the tokenizer. It is
                   1903:   either true or false, and initially must be set to the false
                   1904:   state. The <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
                   1905:   elements</a> also affects tokenization.</p>
                   1906: 
                   1907:   <p>The output of the tokenization step is a series of zero or more
                   1908:   of the following tokens: DOCTYPE, start tag, end tag, comment,
                   1909:   character, end-of-file. DOCTYPE tokens have a name, a public
                   1910:   identifier, a system identifier, and a <i>force-quirks
                   1911:   flag</i>. When a DOCTYPE token is created, its name, public
                   1912:   identifier, and system identifier must be marked as missing (which
                   1913:   is a distinct state from the empty string), and the <i>force-quirks
                   1914:   flag</i> must be set to <i>off</i> (its other state is
                   1915:   <i>on</i>). Start and end tag tokens have a tag name, a
                   1916:   <i>self-closing flag</i>, and a list of attributes, each of which
                   1917:   has a name and a value. When a start or end tag token is created,
                   1918:   its <i>self-closing flag</i> must be unset (its other state is that
                   1919:   it be set), and its attributes list must be empty. Comment and
                   1920:   character tokens have data.</p>
                   1921: 
                   1922:   <p>When a token is emitted, it must immediately be handled by the
                   1923:   <a href="#tree-construction">tree construction</a> stage. The tree construction stage
                   1924:   can affect the state of the <a href="#content-model-flag">content model flag</a>, and can
                   1925:   insert additional characters into the stream. (For example, the
                   1926:   <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
1.159     mike     1927:   using the <a href="embedded-content-0.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
1.1       mike     1928:   characters into the stream being tokenized.)</p>
                   1929: 
                   1930:   <p>When a start tag token is emitted with its <i>self-closing
                   1931:   flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
                   1932:   self-closing flag">acknowledged</dfn> when it is processed by the
                   1933:   tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
                   1934: 
                   1935:   <p>When an end tag token is emitted, the <a href="#content-model-flag">content model
                   1936:   flag</a> must be switched to the PCDATA state.</p>
                   1937: 
                   1938:   <p>When an end tag token is emitted with attributes, that is a
                   1939:   <a href="#parse-error">parse error</a>.</p>
                   1940: 
                   1941:   <p>When an end tag token is emitted with its <i>self-closing
                   1942:   flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
                   1943: 
                   1944:   <p>Before each step of the tokenizer, the user agent must first
                   1945:   check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
                   1946:   tokenizer must abort the processing of any nested invocations of the
                   1947:   tokenizer, yielding control back to the caller. If it is false, then
                   1948:   the user agent may then check to see if either one of the scripts in
                   1949:   the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will execute as soon as
                   1950:   possible</a> or the first script in the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts
                   1951:   that will execute asynchronously</a>, has <a href="semantics.html#completed-loading">completed
                   1952:   loading</a>. If one has, then it must be <a href="semantics.html#executing-a-script-block" title="executing a
                   1953:   script block">executed</a> and removed from its list.</p>
                   1954: 
                   1955:   <p>The tokenizer state machine consists of the states defined in the
                   1956:   following subsections.</p>
                   1957: 
                   1958:   <!-- XXX should go through these reordering the entries so that
                   1959:   they're in some consistent order, like, by Unicode, errors last, or
                   1960:   something -->
                   1961: 
                   1962:   <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5>
                   1963: 
                   1964:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   1965: 
                   1966:   <dl class="switch"><dt>U+0026 AMPERSAND (&amp;)</dt>
                   1967:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to one of the
                   1968:    PCDATA or RCDATA states and the <a href="#escape-flag">escape flag</a> is
                   1969:    false: switch to the <a href="#character-reference-data-state">character reference data
1.56      mike     1970:    state</a>.</dd>
                   1971:    <dd>Otherwise: treat it as per the "anything else" entry
                   1972:    below.</dd>
1.1       mike     1973: 
                   1974:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   1975:    <dd>
                   1976: 
                   1977:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     1978:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     1979:     is false, and there are at least three characters before this
                   1980:     one in the input stream, and the last four characters in the
                   1981:     input stream, including this one, are U+003C LESS-THAN SIGN,
                   1982:     U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, and U+002D
                   1983:     HYPHEN-MINUS ("&lt;!--"), then set the <a href="#escape-flag">escape flag</a>
                   1984:     to true.</p>
                   1985: 
                   1986:     <p>In any case, emit the input character as a character
                   1987:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   1988: 
                   1989:    </dd>
                   1990: 
                   1991:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   1992:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   1993:    state: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   1994:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     1995:    RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     1996:    is false: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   1997:    <dd>Otherwise: treat it as per the "anything else" entry
                   1998:    below.</dd>
                   1999: 
                   2000:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2001:    <dd>
                   2002: 
                   2003:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2004:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape
1.1       mike     2005:     flag</a> is true, and the last three characters in the input
                   2006:     stream including this one are U+002D HYPHEN-MINUS, U+002D
                   2007:     HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("--&gt;"), set the
                   2008:     <a href="#escape-flag">escape flag</a> to false.</p> <!-- no need to check
                   2009:     that there are enough characters, since you can only run into
                   2010:     this if the flag is true in the first place, which requires four
                   2011:     characters. -->
                   2012: 
                   2013:     <p>In any case, emit the input character as a character
                   2014:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   2015: 
                   2016:    </dd>
                   2017: 
                   2018:    <dt>EOF</dt>
                   2019:    <dd>Emit an end-of-file token.</dd>
                   2020: 
                   2021:    <dt>Anything else</dt>
                   2022:    <dd>Emit the input character as a character token. Stay in the
                   2023:    <a href="#data-state">data state</a>.</dd>
                   2024: 
                   2025:   </dl><h5 id="character-reference-data-state"><span class="secno">9.2.4.2 </span><dfn>Character reference data state</dfn></h5>
                   2026: 
                   2027:   <p><i>(This cannot happen if the <a href="#content-model-flag">content model flag</a>
1.91      mike     2028:   is set to the RAWTEXT state.)</i></p>
1.1       mike     2029: 
                   2030:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
                   2031:   <a href="#additional-allowed-character">additional allowed character</a>.</p>
                   2032: 
                   2033:   <p>If nothing is returned, emit a U+0026 AMPERSAND character
                   2034:   token.</p>
                   2035: 
                   2036:   <p>Otherwise, emit the character token that was returned.</p>
                   2037: 
                   2038:   <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
                   2039: 
                   2040: 
                   2041:   <h5 id="tag-open-state"><span class="secno">9.2.4.3 </span><dfn>Tag open state</dfn></h5>
                   2042: 
                   2043:   <p>The behavior of this state depends on the <a href="#content-model-flag">content model
                   2044:   flag</a>.</p>
                   2045: 
                   2046:   <dl><dt>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA
1.91      mike     2047:    or RAWTEXT states</dt>
1.1       mike     2048: 
                   2049:    <dd>
                   2050: 
                   2051:     <p>Consume the <a href="#next-input-character">next input character</a>. If it is a
                   2052:     U+002F SOLIDUS (/) character, switch to the <a href="#close-tag-open-state">close tag open
                   2053:     state</a>. Otherwise, emit a U+003C LESS-THAN SIGN character
                   2054:     token and reconsume the <a href="#current-input-character">current input character</a> in the
                   2055:     <a href="#data-state">data state</a>.</p>
                   2056: 
                   2057:    </dd>
                   2058: 
                   2059:    <dt>If the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   2060:    state</dt>
                   2061: 
                   2062:    <dd>
                   2063: 
                   2064:     <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2065: 
                   2066:     <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2067:      <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
                   2068: 
                   2069:      <dt>U+002F SOLIDUS (/)</dt>
                   2070:      <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
                   2071: 
                   2072:      <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2073:      <dd>Create a new start tag token, set its tag name to the
                   2074:      lowercase version of the input character (add 0x0020 to the
                   2075:      character's code point), then switch to the <a href="#tag-name-state">tag name
                   2076:      state</a>. (Don't emit the token yet; further details will
                   2077:      be filled in before it is emitted.)</dd>
                   2078: 
                   2079:      <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2080:      <dd>Create a new start tag token, set its tag name to the input
                   2081:      character, then switch to the <a href="#tag-name-state">tag name
                   2082:      state</a>. (Don't emit the token yet; further details will
                   2083:      be filled in before it is emitted.)</dd>
                   2084: 
                   2085:      <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2086:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2087:      character token and a U+003E GREATER-THAN SIGN character
                   2088:      token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2089: 
                   2090:      <dt>U+003F QUESTION MARK (?)</dt>
                   2091:      <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2092:      comment state</a>.</dd>
                   2093: 
                   2094:      <dt>Anything else</dt>
                   2095:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2096:      character token and reconsume the <a href="#current-input-character">current input character</a> in the
                   2097:      <a href="#data-state">data state</a>.</dd>
                   2098: 
                   2099:     </dl></dd>
                   2100: 
                   2101:   </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.4 </span><dfn>Close tag open state</dfn></h5>
                   2102: 
                   2103:   <p>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA or
1.91      mike     2104:   RAWTEXT states but no start tag token has ever been emitted by this
1.1       mike     2105:   instance of the tokenizer (<a href="#fragment-case">fragment case</a>), or, if the
1.91      mike     2106:   <a href="#content-model-flag">content model flag</a> is set to the RCDATA or RAWTEXT states
1.1       mike     2107:   and the next few characters do not match the tag name of the last
                   2108:   start tag token emitted (compared in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2109:   case-insensitive</a> manner), or if they do but they are not
                   2110:   immediately followed by one of the following characters:</p>
                   2111: 
                   2112:   <ul class="brief"><li>U+0009 CHARACTER TABULATION</li>
                   2113:    <li>U+000A LINE FEED (LF)</li>
                   2114:    <li>U+000C FORM FEED (FF)</li>
                   2115:    <!--<li>U+000D CARRIAGE RETURN (CR)</li>-->
                   2116:    <li>U+0020 SPACE</li>
                   2117:    <li>U+003E GREATER-THAN SIGN (&gt;)</li>
                   2118:    <li>U+002F SOLIDUS (/)</li>
                   2119:    <li>EOF</li>
                   2120:   </ul><p>...then emit a U+003C LESS-THAN SIGN character token, a U+002F
                   2121:   SOLIDUS character token, and switch to the <a href="#data-state">data state</a>
                   2122:   to process the <a href="#next-input-character">next input character</a>.</p>
                   2123: 
                   2124:   <p>Otherwise, if the <a href="#content-model-flag">content model flag</a> is set to the
                   2125:   PCDATA state, or if the next few characters <em>do</em> match that tag
                   2126:   name, consume the <a href="#next-input-character">next input character</a>:</p>
                   2127: 
                   2128:   <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2129:    <dd>Create a new end tag token, set its tag name to the lowercase
                   2130:    version of the input character (add 0x0020 to the character's
                   2131:    code point), then switch to the <a href="#tag-name-state">tag name
                   2132:    state</a>. (Don't emit the token yet; further details will be
                   2133:    filled in before it is emitted.)</dd>
                   2134: 
                   2135:    <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2136:    <dd>Create a new end tag token, set its tag name to the input
                   2137:    character, then switch to the <a href="#tag-name-state">tag name state</a>. (Don't
                   2138:    emit the token yet; further details will be filled in before it
                   2139:    is emitted.)</dd>
                   2140: 
                   2141:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2142:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
                   2143:    state</a>.</dd>
                   2144: 
                   2145:    <dt>EOF</dt>
                   2146:    <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2147:    character token and a U+002F SOLIDUS character token. Reconsume
                   2148:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2149: 
                   2150:    <dt>Anything else</dt>
                   2151:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2152:    comment state</a>.</dd>
                   2153: 
                   2154:   </dl><h5 id="tag-name-state"><span class="secno">9.2.4.5 </span><dfn>Tag name state</dfn></h5>
                   2155: 
                   2156:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2157: 
                   2158:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2159:    <dt>U+000A LINE FEED (LF)</dt>
                   2160:    <dt>U+000C FORM FEED (FF)</dt>
                   2161:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2162:    <dt>U+0020 SPACE</dt>
                   2163:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2164: 
                   2165:    <dt>U+002F SOLIDUS (/)</dt>
                   2166:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2167: 
                   2168:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2169:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2170:    state</a>.</dd>
                   2171: 
                   2172:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2173:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2174:    (add 0x0020 to the character's code point) to the current tag
                   2175:    token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2176: 
                   2177:    <dt>EOF</dt>
                   2178:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2179:    <a href="#data-state">data state</a>.</dd>
                   2180: 
                   2181:    <dt>Anything else</dt>
                   2182:    <dd>Append the <a href="#current-input-character">current input character</a> to the current tag token's
                   2183:    tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2184: 
                   2185:   </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.6 </span><dfn>Before attribute name state</dfn></h5>
                   2186: 
                   2187:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2188: 
                   2189:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2190:    <dt>U+000A LINE FEED (LF)</dt>
                   2191:    <dt>U+000C FORM FEED (FF)</dt>
                   2192:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2193:    <dt>U+0020 SPACE</dt>
                   2194:    <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2195: 
                   2196:    <dt>U+002F SOLIDUS (/)</dt>
                   2197:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2198: 
                   2199:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2200:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2201:    state</a>.</dd>
                   2202: 
                   2203:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2204:    <dd>Start a new attribute in the current tag token. Set that
                   2205:    attribute's name to the lowercase version of the <a href="#current-input-character">current input
                   2206:    character</a> (add 0x0020 to the character's code point), and its
                   2207:    value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2208:    state</a>.</dd>
                   2209: 
                   2210:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2211:    <dt>U+0027 APOSTROPHE (')</dt>
                   2212:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2213:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2214:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2215:    entry below.</dd>
                   2216: 
                   2217:    <dt>EOF</dt>
                   2218:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2219:    <a href="#data-state">data state</a>.</dd>
                   2220: 
                   2221:    <dt>Anything else</dt>
                   2222:    <dd>Start a new attribute in the current tag token. Set that
                   2223:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2224:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2225:    state</a>.</dd>
                   2226: 
                   2227:   </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.7 </span><dfn>Attribute name state</dfn></h5>
                   2228: 
                   2229:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2230: 
                   2231:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2232:    <dt>U+000A LINE FEED (LF)</dt>
                   2233:    <dt>U+000C FORM FEED (FF)</dt>
                   2234:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2235:    <dt>U+0020 SPACE</dt>
                   2236:    <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2237: 
                   2238:    <dt>U+002F SOLIDUS (/)</dt>
                   2239:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2240: 
                   2241:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2242:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2243: 
                   2244:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2245:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2246:    state</a>.</dd>
                   2247: 
                   2248:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2249:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2250:    (add 0x0020 to the character's code point) to the current
                   2251:    attribute's name. Stay in the <a href="#attribute-name-state">attribute name
                   2252:    state</a>.</dd>
                   2253: 
                   2254:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2255:    <dt>U+0027 APOSTROPHE (')</dt>
                   2256:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2257:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2258:    entry below.</dd>
                   2259: 
                   2260:    <dt>EOF</dt>
                   2261:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2262:    <a href="#data-state">data state</a>.</dd>
                   2263: 
                   2264:    <dt>Anything else</dt>
                   2265:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2266:    name. Stay in the <a href="#attribute-name-state">attribute name state</a>.</dd>
                   2267: 
                   2268:   </dl><p>When the user agent leaves the attribute name state (and before
                   2269:   emitting the tag token, if appropriate), the complete attribute's
                   2270:   name must be compared to the other attributes on the same token;
                   2271:   if there is already an attribute on the token with the exact same
                   2272:   name, then this is a <a href="#parse-error">parse error</a> and the new
                   2273:   attribute must be dropped, along with the value that gets
                   2274:   associated with it (if any).</p>
                   2275: 
                   2276: 
                   2277:   <h5 id="after-attribute-name-state"><span class="secno">9.2.4.8 </span><dfn>After attribute name state</dfn></h5>
                   2278: 
                   2279:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2280: 
                   2281:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2282:    <dt>U+000A LINE FEED (LF)</dt>
                   2283:    <dt>U+000C FORM FEED (FF)</dt>
                   2284:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2285:    <dt>U+0020 SPACE</dt>
                   2286:    <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2287: 
                   2288:    <dt>U+002F SOLIDUS (/)</dt>
                   2289:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2290: 
                   2291:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2292:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2293: 
                   2294:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2295:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2296:    state</a>.</dd>
                   2297: 
                   2298:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2299:    <dd>Start a new attribute in the current tag token. Set that
                   2300:    attribute's name to the lowercase version of the <a href="#current-input-character">current input character</a>
                   2301:    (add 0x0020 to the character's code point), and its value to
                   2302:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2303:    state</a>.</dd>
                   2304: 
                   2305:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2306:    <dt>U+0027 APOSTROPHE (')</dt>
                   2307:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2308:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2309:    entry below.</dd>
                   2310: 
                   2311:    <dt>EOF</dt>
                   2312:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2313:    <a href="#data-state">data state</a>.</dd>
                   2314: 
                   2315:    <dt>Anything else</dt>
                   2316:    <dd>Start a new attribute in the current tag token. Set that
                   2317:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2318:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2319:    state</a>.</dd>
                   2320: 
                   2321:   </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.9 </span><dfn>Before attribute value state</dfn></h5>
                   2322: 
                   2323:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2324: 
                   2325:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2326:    <dt>U+000A LINE FEED (LF)</dt>
                   2327:    <dt>U+000C FORM FEED (FF)</dt>
                   2328:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2329:    <dt>U+0020 SPACE</dt>
                   2330:    <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2331: 
                   2332:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2333:    <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
                   2334: 
                   2335:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2336:    <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
                   2337:    and reconsume this input character.</dd>
                   2338: 
                   2339:    <dt>U+0027 APOSTROPHE (')</dt>
                   2340:    <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
                   2341: 
                   2342:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2343:    <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
                   2344:    the <a href="#data-state">data state</a>.</dd>
                   2345: 
                   2346:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2347:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2348:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2349:    entry below.</dd>
                   2350: 
                   2351:    <dt>EOF</dt>
                   2352:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2353:    <a href="#data-state">data state</a>.</dd>
                   2354: 
                   2355:    <dt>Anything else</dt>
                   2356:    <dd>Append the <a href="#current-input-character">current input character</a> to the current
                   2357:    attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2358:    state</a>.</dd>
                   2359: 
                   2360:   </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.10 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
                   2361: 
                   2362:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2363: 
                   2364:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2365:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2366:    state</a>.</dd>
                   2367: 
                   2368:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2369:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2370:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2371:    being U+0022 QUOTATION MARK (").</dd>
                   2372: 
                   2373:    <dt>EOF</dt>
                   2374:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2375:    <a href="#data-state">data state</a>.</dd>
                   2376: 
                   2377:    <dt>Anything else</dt>
                   2378:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2379:    value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted)
                   2380:    state</a>.</dd>
                   2381: 
                   2382:   </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.11 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
                   2383: 
                   2384:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2385: 
                   2386:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   2387:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2388:    state</a>.</dd>
                   2389: 
                   2390:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2391:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2392:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2393:    being U+0027 APOSTROPHE (').</dd>
                   2394: 
                   2395:    <dt>EOF</dt>
                   2396:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2397:    <a href="#data-state">data state</a>.</dd>
                   2398: 
                   2399:    <dt>Anything else</dt>
                   2400:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2401:    value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted)
                   2402:    state</a>.</dd>
                   2403: 
                   2404:   </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.12 </span><dfn>Attribute value (unquoted) state</dfn></h5>
                   2405: 
                   2406:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2407: 
                   2408:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2409:    <dt>U+000A LINE FEED (LF)</dt>
                   2410:    <dt>U+000C FORM FEED (FF)</dt>
                   2411:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2412:    <dt>U+0020 SPACE</dt>
                   2413:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2414: 
                   2415:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2416:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2417:    state</a>, with no <a href="#additional-allowed-character">additional allowed
                   2418:    character</a>.</dd>
                   2419: 
                   2420:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2421:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2422:    state</a>.</dd>
                   2423: 
                   2424:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2425:    <dt>U+0027 APOSTROPHE (')</dt>
                   2426:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2427:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2428:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2429:    entry below.</dd>
                   2430: 
                   2431:    <dt>EOF</dt>
                   2432:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2433:    <a href="#data-state">data state</a>.</dd>
                   2434: 
                   2435:    <dt>Anything else</dt>
                   2436:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2437:    value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2438:    state</a>.</dd>
                   2439: 
                   2440:   </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>
                   2441: 
                   2442:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
                   2443: 
                   2444:   <p>If nothing is returned, append a U+0026 AMPERSAND character to
                   2445:   the current attribute's value.</p>
                   2446: 
                   2447:   <p>Otherwise, append the returned character token to the current
                   2448:   attribute's value.</p>
                   2449: 
                   2450:   <p>Finally, switch back to the attribute value state that you were
                   2451:   in when were switched into this state.</p>
                   2452: 
                   2453: 
                   2454:   <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.14 </span><dfn>After attribute value (quoted) state</dfn></h5>
                   2455: 
                   2456:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2457: 
                   2458:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2459:    <dt>U+000A LINE FEED (LF)</dt>
                   2460:    <dt>U+000C FORM FEED (FF)</dt>
                   2461:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2462:    <dt>U+0020 SPACE</dt>
                   2463:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2464: 
                   2465:    <dt>U+002F SOLIDUS (/)</dt>
                   2466:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2467: 
                   2468:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2469:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2470:    state</a>.</dd>
                   2471: 
                   2472:    <dt>EOF</dt>
                   2473:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2474:    <a href="#data-state">data state</a>.</dd>
                   2475: 
                   2476:    <dt>Anything else</dt>
                   2477:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2478:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2479: 
                   2480:   </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.15 </span><dfn>Self-closing start tag state</dfn></h5>
                   2481: 
                   2482:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2483: 
                   2484:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2485:    <dd>Set the <i>self-closing flag</i> of the current tag
                   2486:    token. Emit the current tag token. Switch to the <a href="#data-state">data
                   2487:    state</a>.</dd>
                   2488: 
                   2489:    <dt>EOF</dt>
                   2490:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2491:    <a href="#data-state">data state</a>.</dd>
                   2492: 
                   2493:    <dt>Anything else</dt>
                   2494:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2495:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2496: 
                   2497:   </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.16 </span><dfn>Bogus comment state</dfn></h5>
                   2498: 
                   2499:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2500:   flag</a> is set to the PCDATA state.)</i></p>
                   2501: 
                   2502:   <p>Consume every character up to and including the first U+003E
                   2503:   GREATER-THAN SIGN character (&gt;) or the end of the file (EOF),
                   2504:   whichever comes first. Emit a comment token whose data is the
                   2505:   concatenation of all the characters starting from and including
                   2506:   the character that caused the state machine to switch into the
                   2507:   bogus comment state, up to and including the character immediately
                   2508:   before the last consumed character (i.e. up to the character just
                   2509:   before the U+003E or EOF character). (If the comment was started
                   2510:   by the end of the file (EOF), the token is empty.)</p>
                   2511: 
                   2512:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   2513: 
                   2514:   <p>If the end of the file was reached, reconsume the EOF
                   2515:   character.</p>
                   2516: 
                   2517: 
                   2518:   <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.17 </span><dfn>Markup declaration open state</dfn></h5>
                   2519: 
                   2520:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2521:   flag</a> is set to the PCDATA state.)</i></p>
                   2522: 
                   2523:   <p>If the next two characters are both U+002D HYPHEN-MINUS (-)
                   2524:   characters, consume those two characters, create a comment token
                   2525:   whose data is the empty string, and switch to the <a href="#comment-start-state">comment
                   2526:   start state</a>.</p>
                   2527: 
                   2528:   <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2529:   case-insensitive</a> match for the word "DOCTYPE", then consume
                   2530:   those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
                   2531: 
                   2532:   <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
                   2533:   content</a>" and the <a href="#current-node">current node</a> is not an element
                   2534:   in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
                   2535:   an <span>ASCII case-sensitive</span> match for the string "[CDATA["
                   2536:   (the five uppercase letters "CDATA" with a U+005B LEFT SQUARE
                   2537:   BRACKET character before and after), then consume those characters
1.91      mike     2538:   and switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1       mike     2539: 
                   2540:   <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
                   2541:   <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
                   2542:   consumed, if any, is the first character that will be in the
                   2543:   comment.</p>
                   2544: 
                   2545: 
                   2546:   <h5 id="comment-start-state"><span class="secno">9.2.4.18 </span><dfn>Comment start state</dfn></h5>
                   2547: 
                   2548:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2549: 
                   2550:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2551:    <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
                   2552: 
                   2553:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2554:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
                   2555:    <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
                   2556:    -->
                   2557: 
                   2558:    <dt>EOF</dt>
                   2559:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2560:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2561: 
                   2562:    <dt>Anything else</dt>
                   2563:    <dd>Append the input character to the comment token's
                   2564:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2565: 
                   2566:   </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.19 </span><dfn>Comment start dash state</dfn></h5>
                   2567: 
                   2568:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2569: 
                   2570:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2571:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2572: 
                   2573:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2574:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
                   2575:    the <a href="#data-state">data state</a>.</dd>
                   2576: 
                   2577:    <dt>EOF</dt>
                   2578:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2579:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2580:    in comment end state -->
                   2581: 
                   2582:    <dt>Anything else</dt>
                   2583:    <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
                   2584:    character to the comment token's data. Switch to the
                   2585:    <a href="#comment-state">comment state</a>.</dd>
                   2586: 
                   2587:   </dl><h5 id="comment-state"><span class="secno">9.2.4.20 </span><dfn id="comment">Comment 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+002D HYPHEN-MINUS (-)</dt>
                   2592:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
                   2593: 
                   2594:    <dt>EOF</dt>
                   2595:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2596:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2597:    in comment end state -->
                   2598: 
                   2599:    <dt>Anything else</dt>
                   2600:    <dd>Append the input character to the comment token's data. Stay
                   2601:    in the <a href="#comment-state">comment state</a>.</dd>
                   2602: 
                   2603:   </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.21 </span><dfn>Comment end dash state</dfn></h5>
                   2604: 
                   2605:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2606: 
                   2607:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2608:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2609: 
                   2610:    <dt>EOF</dt>
                   2611:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2612:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2613:    in comment end state -->
                   2614: 
                   2615:    <dt>Anything else</dt>
                   2616:    <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
                   2617:    character to the comment token's data. Switch to the
                   2618:    <a href="#comment-state">comment state</a>.</dd>
                   2619: 
                   2620:   </dl><h5 id="comment-end-state"><span class="secno">9.2.4.22 </span><dfn>Comment end state</dfn></h5>
                   2621: 
                   2622:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2623: 
                   2624:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2625:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2626:    state</a>.</dd>
                   2627: 
                   2628:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2629:    <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
                   2630:    (-) character to the comment token's data. Stay in the
                   2631:    <a href="#comment-end-state">comment end state</a>.</dd>
                   2632: 
                   2633:    <dt>U+0009 CHARACTER TABULATION</dt>
                   2634:    <dt>U+000A LINE FEED (LF)</dt>
                   2635:    <dt>U+000C FORM FEED (FF)</dt>
                   2636:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2637:    <dt>U+0020 SPACE</dt>
                   2638:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2639:    characters and the input character to the comment token's
                   2640:    data. Switch to the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2641: 
                   2642:    <dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2643:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
                   2644:    state</a>.</dd>
                   2645: 
                   2646:    <dt>EOF</dt>
                   2647:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2648:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
                   2649:    security reasons: otherwise, hostile user could put a <script> in
                   2650:    a comment e.g. in a blog comment and then DOS the server so that
                   2651:    the end tag isn't read, and then the commented <script> tag would
                   2652:    be treated as live code -->
                   2653: 
                   2654:    <dt>Anything else</dt>
                   2655:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2656:    characters and the input character to the comment token's
                   2657:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2658: 
                   2659:   </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.23 </span><dfn>Comment end bang state</dfn></h5>
                   2660: 
                   2661:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2662: 
                   2663:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2664:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2665:    state</a>.</dd>
                   2666: 
                   2667:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2668:    <dd>Append two U+002D HYPHEN-MINUS (-) characters and a U+0021
                   2669:    EXCLAMATION MARK (!) character to the comment token's data. Switch
                   2670:    to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2671: 
                   2672:    <dt>EOF</dt>
                   2673:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2674:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2675:    comment in comment end state -->
                   2676: 
                   2677:    <dt>Anything else</dt>
                   2678:    <dd>Append two U+002D HYPHEN-MINUS (-) characters, a U+0021
                   2679:    EXCLAMATION MARK (!) character, and the input character to the
                   2680:    comment token's data. Switch to the <a href="#comment-state">comment
                   2681:    state</a>.</dd>
                   2682: 
                   2683:   </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.24 </span><dfn>Comment end space state</dfn></h5>
                   2684: 
                   2685:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2686: 
                   2687:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2688:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2689:    state</a>.</dd>
                   2690: 
                   2691:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2692:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2693: 
                   2694:    <dt>U+0009 CHARACTER TABULATION</dt>
                   2695:    <dt>U+000A LINE FEED (LF)</dt>
                   2696:    <dt>U+000C FORM FEED (FF)</dt>
                   2697:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2698:    <dt>U+0020 SPACE</dt>
                   2699:    <dd>Append the input character to the comment token's data. Stay in
                   2700:    the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2701: 
                   2702:    <dt>EOF</dt>
                   2703:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2704:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2705:    comment in comment end state -->
                   2706: 
                   2707:    <dt>Anything else</dt>
                   2708:    <dd>Append the input character to the comment token's data. Switch
                   2709:    to the <a href="#comment-state">comment state</a>.</dd>
                   2710: 
                   2711:   </dl><h5 id="doctype-state"><span class="secno">9.2.4.25 </span><dfn>DOCTYPE state</dfn></h5>
                   2712: 
                   2713:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2714: 
                   2715:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2716:    <dt>U+000A LINE FEED (LF)</dt>
                   2717:    <dt>U+000C FORM FEED (FF)</dt>
                   2718:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2719:    <dt>U+0020 SPACE</dt>
                   2720:    <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2721: 
                   2722:    <dt>EOF</dt>
                   2723:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2724:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2725:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2726: 
                   2727:    <dt>Anything else</dt>
                   2728:    <dd><a href="#parse-error">Parse error</a>. Reconsume the current
                   2729:    character in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2730: 
                   2731:   </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.26 </span><dfn>Before DOCTYPE name state</dfn></h5>
                   2732: 
                   2733:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2734: 
                   2735:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2736:    <dt>U+000A LINE FEED (LF)</dt>
                   2737:    <dt>U+000C FORM FEED (FF)</dt>
                   2738:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2739:    <dt>U+0020 SPACE</dt>
                   2740:    <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2741: 
                   2742:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2743:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2744:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
                   2745:    the <a href="#data-state">data state</a>.</dd>
                   2746: 
                   2747:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2748:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2749:    lowercase version of the input character (add 0x0020 to the
                   2750:    character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2751:    state</a>.</dd>
                   2752: 
                   2753:    <dt>EOF</dt>
                   2754:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2755:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2756:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2757: 
                   2758:    <dt>Anything else</dt>
                   2759:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2760:    <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2761:    state</a>.</dd>
                   2762: 
                   2763:   </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.27 </span><dfn>DOCTYPE name state</dfn></h5>
                   2764: 
                   2765:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2766: 
                   2767:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2768:    <dt>U+000A LINE FEED (LF)</dt>
                   2769:    <dt>U+000C FORM FEED (FF)</dt>
                   2770:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2771:    <dt>U+0020 SPACE</dt>
                   2772:    <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   2773: 
                   2774:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2775:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2776:    state</a>.</dd>
                   2777: 
                   2778:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2779:    <dd>Append the lowercase version of the input character (add 0x0020
                   2780:    to the character's code point) to the current DOCTYPE token's
                   2781:    name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   2782: 
                   2783:    <dt>EOF</dt>
                   2784:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2785:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2786:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2787: 
                   2788:    <dt>Anything else</dt>
                   2789:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2790:    token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   2791: 
                   2792:   </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.28 </span><dfn>After DOCTYPE name state</dfn></h5>
                   2793: 
                   2794:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2795: 
                   2796:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2797:    <dt>U+000A LINE FEED (LF)</dt>
                   2798:    <dt>U+000C FORM FEED (FF)</dt>
                   2799:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2800:    <dt>U+0020 SPACE</dt>
                   2801:    <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   2802: 
                   2803:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2804:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2805:    state</a>.</dd>
                   2806: 
                   2807:    <dt>EOF</dt>
                   2808:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2809:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2810:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2811: 
                   2812:    <dt>Anything else</dt>
                   2813:    <dd>
                   2814: 
                   2815:     <p>If the six characters starting from the <a href="#current-input-character">current input
                   2816:     character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
                   2817:     for the word "PUBLIC", then consume those characters and switch to
                   2818:     the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</p>
                   2819: 
                   2820:     <p>Otherwise, if the six characters starting from the
                   2821:     <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2822:     case-insensitive</a> match for the word "SYSTEM", then consume
                   2823:     those characters and switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system
                   2824:     identifier state</a>.</p>
                   2825: 
                   2826:     <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
                   2827:     DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
                   2828:     the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
                   2829: 
                   2830:    </dd>
                   2831: 
                   2832:   </dl><h5 id="before-doctype-public-identifier-state"><span class="secno">9.2.4.29 </span><dfn>Before DOCTYPE public identifier state</dfn></h5>
                   2833: 
                   2834:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2835: 
                   2836:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2837:    <dt>U+000A LINE FEED (LF)</dt>
                   2838:    <dt>U+000C FORM FEED (FF)</dt>
                   2839:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2840:    <dt>U+0020 SPACE</dt>
                   2841:    <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
                   2842: 
                   2843:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2844:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   2845:    (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
                   2846:    (double-quoted) state</a>.</dd>
                   2847: 
                   2848:    <dt>U+0027 APOSTROPHE (')</dt>
                   2849:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   2850:    (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
                   2851:    (single-quoted) state</a>.</dd>
                   2852: 
                   2853:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2854:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2855:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2856:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2857: 
                   2858:    <dt>EOF</dt>
                   2859:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2860:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2861:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2862: 
                   2863:    <dt>Anything else</dt>
                   2864:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2865:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   2866:    DOCTYPE state</a>.</dd>
                   2867: 
                   2868:   </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>
                   2869: 
                   2870:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2871: 
                   2872:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2873:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   2874: 
                   2875:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2876:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2877:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2878:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2879: 
                   2880:    <dt>EOF</dt>
                   2881:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2882:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2883:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2884: 
                   2885:    <dt>Anything else</dt>
                   2886:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2887:    token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
                   2888:    identifier (double-quoted) state</a>.</dd>
                   2889: 
                   2890:   </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>
                   2891: 
                   2892:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2893: 
                   2894:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   2895:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   2896: 
                   2897:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2898:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2899:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2900:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2901: 
                   2902:    <dt>EOF</dt>
                   2903:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2904:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2905:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2906: 
                   2907:    <dt>Anything else</dt>
                   2908:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2909:    token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
                   2910:    identifier (single-quoted) state</a>.</dd>
                   2911: 
                   2912:   </dl><h5 id="after-doctype-public-identifier-state"><span class="secno">9.2.4.32 </span><dfn>After DOCTYPE public identifier state</dfn></h5>
                   2913: 
                   2914:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2915: 
                   2916:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2917:    <dt>U+000A LINE FEED (LF)</dt>
                   2918:    <dt>U+000C FORM FEED (FF)</dt>
                   2919:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2920:    <dt>U+0020 SPACE</dt>
                   2921:    <dd>Stay in the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   2922: 
                   2923:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2924:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   2925:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   2926:    (double-quoted) state</a>.</dd>
                   2927: 
                   2928:    <dt>U+0027 APOSTROPHE (')</dt>
                   2929:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   2930:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   2931:    (single-quoted) state</a>.</dd>
                   2932: 
                   2933:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2934:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2935:    state</a>.</dd>
                   2936: 
                   2937:    <dt>EOF</dt>
                   2938:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2939:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2940:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2941: 
                   2942:    <dt>Anything else</dt>
                   2943:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2944:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   2945:    DOCTYPE state</a>.</dd>
                   2946: 
                   2947:   </dl><h5 id="before-doctype-system-identifier-state"><span class="secno">9.2.4.33 </span><dfn>Before DOCTYPE system identifier state</dfn></h5>
                   2948: 
                   2949:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2950: 
                   2951:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2952:    <dt>U+000A LINE FEED (LF)</dt>
                   2953:    <dt>U+000C FORM FEED (FF)</dt>
                   2954:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2955:    <dt>U+0020 SPACE</dt>
                   2956:    <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
                   2957: 
                   2958:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2959:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   2960:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   2961:    (double-quoted) state</a>.</dd>
                   2962: 
                   2963:    <dt>U+0027 APOSTROPHE (')</dt>
                   2964:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   2965:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   2966:    (single-quoted) state</a>.</dd>
                   2967: 
                   2968:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2969:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2970:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2971:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2972: 
                   2973:    <dt>EOF</dt>
                   2974:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2975:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2976:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2977: 
                   2978:    <dt>Anything else</dt>
                   2979:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2980:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   2981:    DOCTYPE state</a>.</dd>
                   2982: 
                   2983:   </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>
                   2984: 
                   2985:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2986: 
                   2987:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2988:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   2989: 
                   2990:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2991:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2992:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2993:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2994: 
                   2995:    <dt>EOF</dt>
                   2996:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2997:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2998:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2999: 
                   3000:    <dt>Anything else</dt>
                   3001:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3002:    token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
                   3003:    identifier (double-quoted) state</a>.</dd>
                   3004: 
                   3005:   </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>
                   3006: 
                   3007:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3008: 
                   3009:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   3010:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3011: 
                   3012:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3013:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3014:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3015:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3016: 
                   3017:    <dt>EOF</dt>
                   3018:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3019:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3020:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3021: 
                   3022:    <dt>Anything else</dt>
                   3023:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3024:    token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
                   3025:    identifier (single-quoted) state</a>.</dd>
                   3026: 
                   3027:   </dl><h5 id="after-doctype-system-identifier-state"><span class="secno">9.2.4.36 </span><dfn>After DOCTYPE system identifier state</dfn></h5>
                   3028: 
                   3029:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3030: 
                   3031:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3032:    <dt>U+000A LINE FEED (LF)</dt>
                   3033:    <dt>U+000C FORM FEED (FF)</dt>
                   3034:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3035:    <dt>U+0020 SPACE</dt>
                   3036:    <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3037: 
                   3038:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3039:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3040:    state</a>.</dd>
                   3041: 
                   3042:    <dt>EOF</dt>
                   3043:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3044:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3045:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3046: 
                   3047:    <dt>Anything else</dt>
                   3048:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
                   3049:    state</a>. (This does <em>not</em> set the DOCTYPE token's
                   3050:    <i>force-quirks flag</i> to <i>on</i>.)</dd>
                   3051: 
                   3052:   </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.37 </span><dfn>Bogus DOCTYPE state</dfn></h5>
                   3053: 
                   3054:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3055: 
                   3056:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3057:    <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
                   3058:    state</a>.</dd>
                   3059: 
                   3060:    <dt>EOF</dt>
                   3061:    <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
                   3062:    <a href="#data-state">data state</a>.</dd>
                   3063: 
                   3064:    <dt>Anything else</dt>
                   3065:    <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
                   3066: 
                   3067:   </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.38 </span><dfn>CDATA section state</dfn></h5>
                   3068: 
                   3069:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
1.91      mike     3070:   flag</a> is set to the PCDATA state.)</i></p>
1.1       mike     3071: 
                   3072:   <p>Consume every character up to the next occurrence of the three
                   3073:   character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
                   3074:   BRACKET U+003E GREATER-THAN SIGN (<code title="">]]&gt;</code>), or the
                   3075:   end of the file (EOF), whichever comes first. Emit a series of
                   3076:   character tokens consisting of all the characters consumed except
                   3077:   the matching three character sequence at the end (if one was found
                   3078:   before the end of the file).</p>
                   3079: 
                   3080:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   3081: 
                   3082:   <p>If the end of the file was reached, reconsume the EOF
                   3083:   character.</p>
                   3084: 
                   3085: 
                   3086: 
                   3087:   <h5 id="tokenizing-character-references"><span class="secno">9.2.4.39 </span>Tokenizing character references</h5>
                   3088: 
                   3089:   <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
                   3090:   reference</dfn>. This definition is used when parsing character
                   3091:   references <a href="#character-reference-data-state" title="character reference data state">in
                   3092:   text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
                   3093:   state">in attributes</a>.</p>
                   3094: 
                   3095:   <p>The behavior depends on the identity of the next character (the
                   3096:   one immediately after the U+0026 AMPERSAND character):</p>
                   3097: 
                   3098:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3099:    <dt>U+000A LINE FEED (LF)</dt>
                   3100:    <dt>U+000C FORM FEED (FF)</dt>
                   3101:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3102:    <dt>U+0020 SPACE</dt>
                   3103:    <dt>U+003C LESS-THAN SIGN</dt>
                   3104:    <dt>U+0026 AMPERSAND</dt>
                   3105:    <dt>EOF</dt>
                   3106:    <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
                   3107: 
                   3108:    <dd>Not a character reference. No characters are consumed, and
                   3109:    nothing is returned. (This is not an error, either.)</dd>
                   3110: 
                   3111: 
                   3112:    <dt>U+0023 NUMBER SIGN (#)</dt>
                   3113: 
                   3114:    <dd>
                   3115: 
                   3116:     <p>Consume the U+0023 NUMBER SIGN.</p>
                   3117: 
                   3118:     <p>The behavior further depends on the character after the U+0023
                   3119:     NUMBER SIGN:</p>
                   3120: 
                   3121:     <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
                   3122:      <dt>U+0058 LATIN CAPITAL LETTER X</dt>
                   3123: 
                   3124:      <dd>
                   3125: 
                   3126:       <p>Consume the X.</p>
                   3127: 
                   3128:       <p>Follow the steps below, but using the range of characters
                   3129:       U+0030 DIGIT ZERO through to U+0039 DIGIT NINE, U+0061 LATIN
                   3130:       SMALL LETTER A through to U+0066 LATIN SMALL LETTER F, and
                   3131:       U+0041 LATIN CAPITAL LETTER A, through to U+0046 LATIN CAPITAL
                   3132:       LETTER F (in other words, 0-9, A-F, a-f).</p>
                   3133: 
                   3134:       <p>When it comes to interpreting the number, interpret it as a
                   3135:       hexadecimal number.</p>
                   3136: 
                   3137:      </dd>
                   3138: 
                   3139: 
                   3140:      <dt>Anything else</dt>
                   3141: 
                   3142:      <dd>
                   3143: 
                   3144:       <p>Follow the steps below, but using the range of characters
                   3145:       U+0030 DIGIT ZERO through to U+0039 DIGIT NINE (i.e. just
                   3146:       0-9).</p>
                   3147: 
                   3148:       <p>When it comes to interpreting the number, interpret it as a
                   3149:       decimal number.</p>
                   3150: 
                   3151:      </dd>
                   3152: 
                   3153:     </dl><p>Consume as many characters as match the range of characters
                   3154:     given above.</p>
                   3155: 
                   3156:     <p>If no characters match the range, then don't consume any
                   3157:     characters (and unconsume the U+0023 NUMBER SIGN character and, if
                   3158:     appropriate, the X character). This is a <a href="#parse-error">parse
                   3159:     error</a>; nothing is returned.</p>
                   3160: 
                   3161:     <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
                   3162:     that too. If it isn't, there is a <a href="#parse-error">parse
                   3163:     error</a>.</p>
                   3164: 
                   3165:     <p>If one or more characters match the range, then take them all
                   3166:     and interpret the string of characters as a number (either
                   3167:     hexadecimal or decimal as appropriate).</p>
                   3168: 
                   3169:     <p>If that number is one of the numbers in the first column of the
                   3170:     following table, then this is a <a href="#parse-error">parse error</a>. Find the
                   3171:     row with that number in the first column, and return a character
                   3172:     token for the Unicode character given in the second column of that
                   3173:     row.</p>
                   3174: 
                   3175:     <table><thead><tr><th>Number </th><th colspan="2">Unicode character
                   3176:      </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
                   3177:       </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
                   3178:       </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN ('&#8364;')
                   3179:       </td></tr><tr><td>0x81 </td><td>U+0081 </td><td>&lt;control&gt;
                   3180:       </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK ('&#8218;')
                   3181:       </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK ('&#402;')
                   3182:       </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK ('&#8222;')
                   3183:       </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS ('&#8230;')
                   3184:       </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER ('&#8224;')
                   3185:       </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER ('&#8225;')
                   3186:       </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT ('&#710;')
                   3187:       </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN ('&#8240;')
                   3188:       </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON ('&#352;')
                   3189:       </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK ('&#8249;')
                   3190:       </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE ('&#338;')
                   3191:       </td></tr><tr><td>0x8D </td><td>U+008D </td><td>&lt;control&gt;
                   3192:       </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON ('&#381;')
                   3193:       </td></tr><tr><td>0x8F </td><td>U+008F </td><td>&lt;control&gt;
                   3194:       </td></tr><tr><td>0x90 </td><td>U+0090 </td><td>&lt;control&gt;
                   3195:       </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK ('&#8216;')
                   3196:       </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK ('&#8217;')
                   3197:       </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK ('&#8220;')
                   3198:       </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK ('&#8221;')
                   3199:       </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET ('&#8226;')
                   3200:       </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH ('&#8211;')
                   3201:       </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH ('&#8212;')
                   3202:       </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE ('&#732;')
                   3203:       </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN ('&#8482;')
                   3204:       </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON ('&#353;')
                   3205:       </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK ('&#8250;')
                   3206:       </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE ('&#339;')
                   3207:       </td></tr><tr><td>0x9D </td><td>U+009D </td><td>&lt;control&gt;
                   3208:       </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON ('&#382;')
                   3209:       </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS ('&#376;')
1.18      mike     3210:     </td></tr></tbody></table><p>Otherwise, if the number is greater than 0x10FFFF, then this is
                   3211:     a <a href="#parse-error">parse error</a>. Return a U+FFFD REPLACEMENT
                   3212:     CHARACTER.</p>
                   3213: 
                   3214:     <p>Otherwise, return a character token for the Unicode character
1.1       mike     3215:     whose code point is that number.
                   3216: 
                   3217:     <!-- this is the same as the equivalent list in the input stream
                   3218:     section -->
                   3219:     If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
                   3220:     allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
                   3221:     allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
                   3222:     0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xD800 to
                   3223:     0xDFFF<!-- surrogates not allowed -->, 0xFDD0 to 0xFDEF, or is one
                   3224:     of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF,
                   3225:     0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF, 0x6FFFE,
                   3226:     0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE, 0x9FFFF,
                   3227:     0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE,
                   3228:     0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF, 0x10FFFE, or
1.18      mike     3229:     0x10FFFF, then this is a <a href="#parse-error">parse error</a>.</p>
1.1       mike     3230: 
                   3231:    </dd>
                   3232: 
                   3233: 
                   3234:    <dt>Anything else</dt>
                   3235: 
                   3236:    <dd>
                   3237: 
                   3238:     <p>Consume the maximum number of characters possible, with the
                   3239:     consumed characters matching one of the identifiers in the first
                   3240:     column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
                   3241:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
                   3242: 
                   3243:     <p>If no match can be made, then this is a <a href="#parse-error">parse
                   3244:     error</a>. No characters are consumed, and nothing is
                   3245:     returned.</p>
                   3246: 
                   3247:     <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>
                   3248: 
                   3249:     <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
                   3250:     attribute</a>, and the last character matched is not a U+003B
                   3251:     SEMICOLON (<code title="">;</code>), and the next character is in
                   3252:     the range U+0030 DIGIT ZERO to U+0039 DIGIT NINE, U+0041 LATIN
                   3253:     CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z, or U+0061 LATIN
                   3254:     SMALL LETTER A to U+007A LATIN SMALL LETTER Z, then, for
                   3255:     historical reasons, all the characters that were matched after the
                   3256:     U+0026 AMPERSAND (&amp;) must be unconsumed, and nothing is
                   3257:     returned.</p>
                   3258: 
                   3259:     <p>Otherwise, return a character token for the character
                   3260:     corresponding to the character reference name (as given by the
                   3261:     second column of the <a href="named-character-references.html#named-character-references">named character references</a>
                   3262:     table).</p>
                   3263: 
                   3264:     <div class="example">
                   3265: 
                   3266:      <p>If the markup contains <code title="">I'm &amp;notit; I tell
                   3267:      you</code>, the character reference is parsed as "not", as in,
                   3268:      <code title="">I'm &#172;it; I tell you</code>. But if the markup
                   3269:      was <code title="">I'm &amp;notin; I tell you</code>, the
                   3270:      character reference would be parsed as "notin;", resulting in
                   3271:      <code title="">I'm &#8713; I tell you</code>.</p>
                   3272: 
                   3273:     </div>
                   3274: 
                   3275:    </dd>
                   3276: 
                   3277:   </dl><h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4>
                   3278: 
                   3279:   <p>The input to the tree construction stage is a sequence of tokens
                   3280:   from the <a href="#tokenization">tokenization</a> stage. The tree construction
                   3281:   stage is associated with a DOM <code>Document</code> object when a
                   3282:   parser is created. The "output" of this stage consists of
                   3283:   dynamically modifying or extending that document's DOM tree.</p>
                   3284: 
                   3285:   <p>This specification does not define when an interactive user agent
                   3286:   has to render the <code>Document</code> so that it is available to
                   3287:   the user, or when it has to begin accepting user input.</p>
                   3288: 
                   3289:   <p>As each token is emitted from the tokenizer, the user agent must
                   3290:   process the token according to the rules given in the section
                   3291:   corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
                   3292: 
                   3293:   <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
                   3294:   character</dfn> into a node, if that node has a child immediately
                   3295:   before where the character is to be inserted, and that child is a
                   3296:   <code>Text</code> node, and that <code>Text</code> node was the last
                   3297:   node that the parser inserted into the document, then the character
                   3298:   must be appended to that <code>Text</code> node; otherwise, a new
                   3299:   <code>Text</code> node whose data is just that character must be
                   3300:   inserted in the appropriate place.</p>
                   3301: 
                   3302:   <div class="example">
                   3303: 
                   3304:    <p>Here are some sample inputs to the parser and the corresponding
                   3305:    number of text nodes that they result in, assuming a user agent
                   3306:    that executes scripts.</p>
                   3307: 
                   3308:    <table><thead><tr><th>Input </th><th>Number of text nodes
                   3309:     </th></tr></thead><tbody><tr><td><pre>A&lt;script&gt;
                   3310: var&#160;script&#160;=&#160;document.getElementsByTagName('script')[0];
                   3311: document.body.removeChild(script);
                   3312: &lt;/script&gt;B</pre>
                   3313:       </td><td>Two adjacent text nodes in the document, containing "A" and "B".
                   3314:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3315: var&#160;text&#160;=&#160;document.createTextNode('B');
                   3316: document.body.appendChild(text);
                   3317: &lt;/script&gt;C</pre>
                   3318:       </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
                   3319:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3320: var&#160;text&#160;=&#160;document.getElementsByTagName('script')[0].firstChild;
                   3321: text.data&#160;=&#160;'B';
                   3322: document.body.appendChild(text);
                   3323: &lt;/script&gt;B</pre>
                   3324:       </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
                   3325:      </td></tr><tr><td><pre>A&lt;table&gt;B&lt;tr&gt;C&lt;/tr&gt;C&lt;/table&gt;</pre>
                   3326:       </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>.)
                   3327:      </td></tr><tr><td><pre>A&lt;table&gt;&lt;tr&gt;&#160;B&lt;/tr&gt;&#160;B&lt;/table&gt;</pre>
                   3328:       </td><td>Two adjacent text nodes before the table, containing "A" and "&#160;B&#160;B" (space-B-space-B) respectively. (This is caused by <a href="#foster-parent" title="foster parent">foster parenting</a>.)
                   3329:      </td></tr><tr><td><pre>A&lt;table&gt;&lt;tr&gt;&#160;B&lt;/tr&gt;&#160;&lt;/em&gt;C&lt;/table&gt;</pre>
                   3330:       </td><td>Three adjacent text nodes before the table, containing "A", "&#160;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.)
                   3331:    </td></tr></tbody></table></div>
                   3332: 
                   3333:   <p id="mutation-during-parsing">DOM mutation events must not fire
                   3334:   for changes caused by the UA parsing the document. (Conceptually,
                   3335:   the parser is not mutating the DOM, it is constructing it.) This
1.159     mike     3336:   includes the parsing of any content inserted using <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code> and <code title="dom-document-writeln"><a href="embedded-content-0.html#dom-document-writeln">document.writeln()</a></code> calls. <a href="references.html#refsDOMEVENTS">[DOMEVENTS]</a></p>
1.1       mike     3337: 
                   3338:   <p class="note">Not all of the tag names mentioned below are
                   3339:   conformant tag names in this specification; many are included to
                   3340:   handle legacy content. They still form part of the algorithm that
                   3341:   implementations are required to implement to claim conformance.</p>
                   3342: 
                   3343:   <p class="note">The algorithm described below places no limit on the
                   3344:   depth of the DOM tree generated, or on the length of tag names,
                   3345:   attribute names, attribute values, text nodes, etc. While
                   3346:   implementors are encouraged to avoid arbitrary limits, it is
                   3347:   recognized that <a href="infrastructure.html#hardwareLimitations">practical
                   3348:   concerns</a> will likely force user agents to impose nesting
                   3349:   depths.</p>
                   3350: 
                   3351: 
                   3352:   <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5>
                   3353: 
                   3354:   <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
                   3355:   element for the token">create an element for a token</dfn> in a
                   3356:   particular namespace, the UA must create a node implementing the
                   3357:   interface appropriate for the element type corresponding to the tag
                   3358:   name of the token in the given namespace (as given in the
                   3359:   specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
                   3360:   element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
                   3361:   defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
                   3362:   the tag name being the name of that element, with the node being in
                   3363:   the given namespace, and with the attributes on the node being those
                   3364:   given in the given token.</p>
                   3365: 
                   3366:   <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
                   3367:   namespace</a> that is not defined in this specification is
1.44      mike     3368:   <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1       mike     3369:   interface is not defined by that namespace's specification must use
                   3370:   the interface <code>Element</code>.</p>
                   3371: 
                   3372:   <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
                   3373:   created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
                   3374:   invoked once the attributes are set. (This initializes the element's
                   3375:   <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
                   3376:   attributes.)</p>
                   3377: 
                   3378:   <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
                   3379:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3380:   for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
                   3381:   append this node to the <a href="#current-node">current node</a>, and push it onto
                   3382:   the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3383:   <a href="#current-node">current node</a>.</p>
                   3384: 
                   3385:   <p>The steps below may also require that the UA insert an HTML
                   3386:   element in a particular place, in which case the UA must follow the
                   3387:   same steps except that it must insert or append the new node in the
                   3388:   location specified instead of appending it to the <a href="#current-node">current
                   3389:   node</a>. (This happens in particular during the parsing of
                   3390:   tables with invalid content.)</p>
                   3391: 
                   3392:   <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
                   3393:   algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
                   3394:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
                   3395:   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
                   3396:   <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
                   3397:   created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
                   3398:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
                   3399:   inserting it wherever it is to be inserted.</p>
                   3400: 
                   3401:   <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
                   3402:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3403:   for the token</a> in the given namespace, and then append this
                   3404:   node to the <a href="#current-node">current node</a>, and push it onto the
                   3405:   <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3406:   <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>
                   3407:   whose value is not exactly the same as the element's namespace, that
                   3408:   is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
                   3409:   element has an <code title="">xmlns:xlink</code> attribute in the
                   3410:   <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
                   3411:   Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
                   3412: 
                   3413:   <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
                   3414:   attributes</dfn> for a token, then, if the token has an attribute
                   3415:   named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
                   3416: 
                   3417:   <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
                   3418:   attributes</dfn> for a token, then, for each attribute on the token
                   3419:   whose attribute name is one of the ones in the first column of the
                   3420:   following table, change the attribute's name to the name given in
                   3421:   the corresponding cell in the second column. (This fixes the case of
                   3422:   SVG attributes that are not all lowercase.)</p>
                   3423: 
                   3424:   <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
                   3425:    </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
                   3426:     </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
                   3427:     </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
                   3428:     </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
                   3429:     </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
                   3430:     </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
                   3431:     </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
                   3432:     </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
                   3433:     </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
                   3434:     </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
                   3435:     </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
                   3436:     </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
                   3437:     </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
                   3438:     </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   3439:     </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
                   3440:     </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
                   3441:     </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
                   3442:     </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
                   3443:     </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
                   3444:     </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
                   3445:     </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
                   3446:     </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
                   3447:     </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
                   3448:     </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
                   3449:     </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
                   3450:     </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
                   3451:     </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
                   3452:     </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
                   3453:     </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
                   3454:     </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
                   3455:     </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
                   3456:     </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
                   3457:     </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
                   3458:     </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
                   3459:     </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
                   3460:     </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
                   3461:     </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
                   3462:     </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
                   3463:     </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
                   3464:     </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
                   3465:     </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
                   3466:     </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
                   3467:     </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
                   3468:     </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
                   3469:     </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
                   3470:     </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
                   3471:     </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
                   3472:     </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
                   3473:     </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
                   3474:     </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
                   3475:     </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
                   3476:     </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
                   3477:     </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
                   3478:     </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
                   3479:     </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
                   3480:     </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
                   3481:     </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
                   3482:     </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
                   3483:     </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
                   3484:     </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
                   3485:     </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
                   3486:     </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
                   3487:   </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
                   3488:   foreign attributes</dfn> for a token, then, if any of the attributes
                   3489:   on the token match the strings given in the first column of the
                   3490:   following table, let the attribute be a namespaced attribute, with
                   3491:   the prefix being the string given in the corresponding cell in the
                   3492:   second column, the local name being the string given in the
                   3493:   corresponding cell in the third column, and the namespace being the
                   3494:   namespace given in the corresponding cell in the fourth
                   3495:   column. (This fixes the use of namespaced attributes, in particular
                   3496:   <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
                   3497:   the <span>XML namespace</span></a>.)</p>
                   3498: 
                   3499:   <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
                   3500:    </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>
                   3501:     </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>
                   3502:     </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>
                   3503:     </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>
                   3504:     </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>
                   3505:     </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>
                   3506:     </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>
                   3507:     </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 -->
                   3508:     </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>
                   3509:     </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>
                   3510:     </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>
                   3511:     </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     3512:   </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     3513:   <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
                   3514:   following steps. These algorithms are always invoked in response to
                   3515:   a start tag token.</p>
                   3516: 
                   3517:   <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
                   3518: 
1.91      mike     3519:    <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
                   3520:    text element parsing algorithm</a>, switch the tokenizer's
                   3521:    <a href="#content-model-flag">content model flag</a> to the RAWTEXT state; otherwise the
1.1       mike     3522:    algorithm invoked was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing
                   3523:    algorithm</a>, switch the tokenizer's <a href="#content-model-flag">content model
                   3524:    flag</a> to the RCDATA state.</p></li>
                   3525: 
                   3526:    <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   3527:    <a href="#insertion-mode">insertion mode</a>.</p>
                   3528: 
1.91      mike     3529:    </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
                   3530:    RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     3531: 
                   3532:   </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>
                   3533: 
                   3534:   <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
                   3535:   tags</dfn>, then, while the <a href="#current-node">current node</a> is a
                   3536:   <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
                   3537:   <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
                   3538:   <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
                   3539:   <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
                   3540:   pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   3541:   elements</a>.</p>
                   3542: 
                   3543:   <p>If a step requires the UA to generate implied end tags but lists
                   3544:   an element to exclude from the process, then the UA must perform the
                   3545:   above steps as if that element was not in the above list.</p>
                   3546: 
                   3547: 
                   3548:   <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5>
                   3549: 
                   3550:   <p>Foster parenting happens when content is misnested in tables.</p>
                   3551: 
                   3552:   <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
                   3553:   parent">foster parented</dfn>, the node <var title="">node</var>
                   3554:   must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3555: 
                   3556:   <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
                   3557:   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
                   3558:   elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
                   3559:   such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3560:   the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
                   3561:   case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
                   3562:   element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
1.159     mike     3563:   <code><a href="semantics.html#the-html-element-0">html</a></code> element). Otherwise, if there is a
1.1       mike     3564:   <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
                   3565:   elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3566:   <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
                   3567:   node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
                   3568:   the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3569:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   3570: 
                   3571:   <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
                   3572:   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
                   3573:   elements</a>, then <var title="">node</var> must be inserted
                   3574:   immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3575:   the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
                   3576:   element</a></i>; otherwise, <var title="">node</var> must be
                   3577:   <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3578: 
                   3579: 
                   3580: 
                   3581:   <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>
                   3582: 
                   3583:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
                   3584:   mode: initial">initial</a>", tokens must be handled as follows:</p>
                   3585: 
                   3586:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3587:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3588:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3589:    <dd>
                   3590:     <p>Ignore the token.</p>
                   3591:    </dd>
                   3592: 
                   3593:    <dt>A comment token</dt>
                   3594:    <dd>
                   3595:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   3596:     object with the <code title="">data</code> attribute set to the
                   3597:     data given in the comment token.</p>
                   3598:    </dd>
                   3599: 
                   3600:    <dt>A DOCTYPE token</dt>
                   3601:    <dd>
                   3602: 
                   3603:     <p>If the DOCTYPE token's name is not a
                   3604:     <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
                   3605:     missing, or the token's system identifier is neither missing nor a
                   3606:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
                   3607:     "<code>about:legacy-compat</code>", and none of the sets of
                   3608:     conditions in the following list are matched, then there is a
                   3609:     <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
                   3610:     following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
                   3611:     permitted DOCTYPE</dfn>.</p>
                   3612: 
                   3613:     <ul><!-- only things that trigger no-quirks mode and were valid in
                   3614:      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     3615:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3616:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.0//EN</code>", and the
                   3617:      token's system identifier is either missing or the
                   3618:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
                   3619: 
                   3620:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3621:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3622:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.01//EN</code>", and the
                   3623:      token's system identifier is either missing or the
                   3624:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
                   3625: 
                   3626:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3627:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3628:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.0&#160;Strict//EN</code>",
                   3629:      and the token's system identifier is the
                   3630:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
                   3631: 
                   3632:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3633:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3634:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.1//EN</code>", and the
                   3635:      token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
                   3636:      string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
                   3637: 
                   3638:     </ul><p>Conformance checkers may, based on the values (including
                   3639:     presence or lack thereof) of the DOCTYPE token's name, public
                   3640:     identifier, or system identifier, switch to a conformance checking
                   3641:     mode for another language (e.g. based on the DOCTYPE token a
                   3642:     conformance checker could recognize that the document is an
1.183     mike     3643:     HTML4-era document, and defer to an HTML4 conformance
1.1       mike     3644:     checker.)</p>
                   3645: 
                   3646:     <p>Append a <code>DocumentType</code> node to the
                   3647:     <code>Document</code> node, with the <code title="">name</code>
                   3648:     attribute set to the name given in the DOCTYPE token, or the empty
                   3649:     string if the name was missing; the <code title="">publicId</code>
                   3650:     attribute set to the public identifier given in the DOCTYPE token,
                   3651:     or the empty string if the public identifier was missing; the
                   3652:     <code title="">systemId</code> attribute set to the system
                   3653:     identifier given in the DOCTYPE token, or the empty string if the
                   3654:     system identifier was missing; and the other attributes specific
                   3655:     to <code>DocumentType</code> objects set to null and empty lists
                   3656:     as appropriate. Associate the <code>DocumentType</code> node with
                   3657:     the <code>Document</code> object so that it is returned as the
                   3658:     value of the <code title="">doctype</code> attribute of the
                   3659:     <code>Document</code> object.</p>
                   3660: 
                   3661:     <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
                   3662:     one of the conditions in the following list, then set the
                   3663:     <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
                   3664: 
                   3665:     <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
                   3666:      <li> The name is set to anything other than "<code title="">HTML</code>". </li>
                   3667:      <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
                   3668:      <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   3669:      <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   3670:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
                   3671:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
                   3672:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
                   3673:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
                   3674:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
                   3675:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
                   3676:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
                   3677:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
                   3678:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
                   3679:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   3680:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
                   3681:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
                   3682:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
                   3683:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
                   3684:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
                   3685:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
                   3686:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
                   3687:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
                   3688:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
                   3689:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
                   3690:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
                   3691:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
                   3692:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
                   3693:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
                   3694:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
                   3695:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
                   3696:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
                   3697:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
                   3698:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
                   3699:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
                   3700:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
                   3701:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
                   3702:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
                   3703:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
                   3704:      <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
                   3705:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
                   3706:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
                   3707:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
                   3708:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
                   3709:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
                   3710:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
                   3711:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
                   3712:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
                   3713:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
                   3714:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
                   3715:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
                   3716:      <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
                   3717:      <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
                   3718:      <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
                   3719:      <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
                   3720:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
                   3721:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
                   3722:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
                   3723:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
                   3724:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   3725:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
                   3726:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
                   3727:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
                   3728:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
                   3729:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
                   3730:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
                   3731:      <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
                   3732:      <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
                   3733:    <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
                   3734:      <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
                   3735:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
                   3736:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
                   3737:      <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
                   3738:      <li> The public identifier is set to: "<code title="">HTML</code>" </li>
                   3739:      <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
                   3740:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   3741:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   3742:     </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
                   3743:     in the following list, then set the <code>Document</code> to
                   3744:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
                   3745: 
                   3746:     <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
                   3747:      <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
                   3748:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   3749:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   3750:     </ul><p>The name, system identifier, and public identifier strings must
                   3751:     be compared to the values given in the lists above in an
                   3752:     <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
                   3753:     whose value is the empty string is not considered missing for the
                   3754:     purposes of the conditions above.</p>
                   3755: 
                   3756:     <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>
                   3757: 
                   3758:    </dd>
                   3759: 
                   3760:    <dt>Anything else</dt>
                   3761:    <dd>
                   3762: 
                   3763:     <p><a href="#parse-error">Parse error</a>.</p>
                   3764: 
                   3765:     <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
                   3766: 
                   3767:     <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
                   3768:     reprocess the current token.</p>
                   3769: 
                   3770:    </dd>
                   3771: 
                   3772:   </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>
                   3773: 
                   3774:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
                   3775:   mode: before html">before html</a>", tokens must be handled as follows:</p>
                   3776: 
                   3777:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   3778:    <dd>
                   3779:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3780:    </dd>
                   3781: 
                   3782:    <dt>A comment token</dt>
                   3783:    <dd>
                   3784:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   3785:     object with the <code title="">data</code> attribute set to the
                   3786:     data given in the comment token.</p>
                   3787:    </dd>
                   3788: 
                   3789:    <dt>A character token that is one of U+0009 CHARACTER
                   3790:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3791:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3792:    <dd>
                   3793:     <p>Ignore the token.</p>
                   3794:    </dd>
                   3795: 
                   3796:    <dt>A start tag whose tag name is "html"</dt>
                   3797:    <dd>
                   3798: 
                   3799:     <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
                   3800:     namespace</a>. Append it to the <code>Document</code>
                   3801:     object. Put this element in the <a href="#stack-of-open-elements">stack of open
                   3802:     elements</a>.</p>
                   3803: 
                   3804:     <p id="parser-appcache">If the <code>Document</code> is being
                   3805:     loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
                   3806:     <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
                   3807:     has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
                   3808:     then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
                   3809:     attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
                   3810:     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     3811:     algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
                   3812:     any <a href="infrastructure.html#url-fragment" title="url-fragment">&lt;fragment&gt;</a> component
                   3813:     removed; otherwise, if there is no such attribute or resolving it
                   3814:     fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
                   3815:     cache selection algorithm</a> with no manifest. The algorithm
                   3816:     must be passed the <code>Document</code> object.</p>
1.1       mike     3817: 
                   3818:     <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>
                   3819: 
                   3820:    </dd>
                   3821: 
                   3822:    <dt>Anything else</dt>
                   3823:    <dd>
                   3824: 
1.159     mike     3825:     <p>Create an <code><a href="semantics.html#the-html-element-0">html</a></code> element. Append it to the
1.1       mike     3826:     <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
                   3827:     of open elements</a>.</p>
                   3828: 
                   3829:     <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
                   3830:     context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
                   3831:     algorithm</a> with no manifest, passing it the
                   3832:     <code>Document</code> object.</p>
                   3833: 
                   3834:     <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
                   3835:     reprocess the current token.</p>
                   3836: 
                   3837:     <p class="XXX">Should probably make end tags be ignored, so
                   3838:     that "&lt;/head&gt;&lt;!-- --&gt;&lt;html&gt;" puts the comment before the
                   3839:     root node (or should we?)</p>
                   3840: 
                   3841:    </dd>
                   3842: 
                   3843:   </dl><p>The root element can end up being removed from the
                   3844:   <code>Document</code> object, e.g. by scripts; nothing in particular
                   3845:   happens in such cases, content continues being appended to the nodes
                   3846:   as described in the next section.</p>
                   3847: 
                   3848: 
                   3849:   <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>
                   3850: 
                   3851:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
                   3852:   mode: before head">before head</a>", tokens must be handled as follows:</p>
                   3853: 
                   3854:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3855:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3856:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3857:    <dd>
                   3858:     <p>Ignore the token.</p> <!-- :-( -->
                   3859:    </dd>
                   3860: 
                   3861:    <dt>A comment token</dt>
                   3862:    <dd>
                   3863:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   3864:     node</a> with the <code title="">data</code> attribute set to
                   3865:     the data given in the comment token.</p>
                   3866:    </dd>
                   3867: 
                   3868:    <dt>A DOCTYPE token</dt>
                   3869:    <dd>
                   3870:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3871:    </dd>
                   3872: 
                   3873:    <dt>A start tag whose tag name is "html"</dt>
                   3874:    <dd>
                   3875:     <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
                   3876:     mode</a>.</p>
                   3877:    </dd>
                   3878: 
                   3879:    <dt>A start tag whose tag name is "head"</dt>
                   3880:    <dd>
                   3881: 
                   3882:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   3883: 
                   3884:     <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
1.159     mike     3885:     to the newly created <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike     3886: 
                   3887:     <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>
                   3888: 
                   3889:    </dd>
                   3890: 
                   3891:    <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
                   3892:    <dd>
                   3893: 
                   3894:     <p>Act as if a start tag token with the tag name "head" and no
                   3895:     attributes had been seen, then reprocess the current token.</p>
                   3896: 
                   3897:    </dd>
                   3898: 
                   3899:    <dt>Any other end tag</dt>
                   3900:    <dd>
                   3901: 
                   3902:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3903: 
                   3904:    </dd>
                   3905: 
                   3906:    <dt>Anything else</dt>
                   3907:    <dd>
                   3908: 
                   3909:     <p>Act as if a start tag token with the tag name "head" and no
                   3910:     attributes had been seen, then reprocess the current
                   3911:     token.</p>
                   3912: 
                   3913:    </dd>
                   3914: 
                   3915:   </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>
                   3916: 
                   3917:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
                   3918:   mode: in head">in head</a>", tokens must be handled as follows:</p>
                   3919: 
                   3920:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3921:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3922:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3923:    <dd>
                   3924:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   3925:     the <a href="#current-node">current node</a>.</p>
                   3926:    </dd>
                   3927: 
                   3928:    <dt>A comment token</dt>
                   3929:    <dd>
                   3930:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   3931:     node</a> with the <code title="">data</code> attribute set to
                   3932:     the data given in the comment token.</p>
                   3933:    </dd>
                   3934: 
                   3935:    <dt>A DOCTYPE token</dt>
                   3936:    <dd>
                   3937:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3938:    </dd>
                   3939: 
                   3940:    <dt>A start tag whose tag name is "html"</dt>
                   3941:    <dd>
                   3942:     <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
                   3943:     mode</a>.</p>
                   3944:    </dd>
                   3945: 
                   3946:    <dt>A start tag whose tag name is one of: "base", "command",
                   3947:    "link"</dt>
                   3948:    <dd>
                   3949: 
                   3950:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   3951:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   3952:     elements</a>.</p>
                   3953: 
                   3954:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   3955:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   3956: 
                   3957:    </dd>
                   3958: 
                   3959:    <dt>A start tag whose tag name is "meta"</dt>
                   3960:    <dd>
                   3961: 
                   3962:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   3963:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   3964:     elements</a>.</p>
                   3965: 
                   3966:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   3967:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   3968: 
                   3969:     <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
                   3970:     value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   3971:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   3972:     encoding</a> to the encoding given by the value of the
                   3973:     <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
                   3974: 
                   3975:     <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
                   3976:     applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
                   3977:     Content-Type</a> to its value returns a supported encoding
                   3978:     <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   3979:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   3980:     encoding</a> to the encoding <var title="">encoding</var>.</p>
                   3981: 
                   3982:    </dd>
                   3983: 
                   3984:    <dt>A start tag whose tag name is "title"</dt>
                   3985:    <dd>
                   3986:     <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
                   3987:    </dd>
                   3988: 
                   3989:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   3990:    <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
                   3991:    <dd>
1.91      mike     3992:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     3993:    </dd>
                   3994: 
                   3995:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
                   3996:    <dd>
                   3997: 
                   3998:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   3999: 
                   4000:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
                   4001:     noscript</a>".</p>
                   4002: 
                   4003:    </dd>
                   4004: 
                   4005:    <dt id="scriptTag">A start tag whose tag name is "script"</dt>
                   4006:    <dd>
                   4007: 
                   4008:     <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
                   4009:      <a href="#html-namespace-0">HTML namespace</a>.</p></li>
                   4010: 
                   4011:      <li>
                   4012: 
                   4013:       <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
                   4014: 
                   4015:       <p class="note">This ensures that, if the script is external,
1.159     mike     4016:       any <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>
1.1       mike     4017:       calls in the script will execute in-line, instead of blowing the
                   4018:       document away, as would happen in most other cases. It also
                   4019:       prevents the script from executing until the end tag is
                   4020:       seen.</p>
                   4021: 
                   4022:      </li>
                   4023: 
                   4024:      <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
                   4025:      fragment parsing algorithm</a>, then mark the
                   4026:      <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
                   4027:      executed"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
                   4028: 
                   4029:      <li><p>Append the new element to the <a href="#current-node">current node</a>
                   4030:      and push it onto the <a href="#stack-of-open-elements">stack of open
                   4031:      elements</a>.</p></li>
                   4032: 
                   4033:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
1.91      mike     4034:      the RAWTEXT state.</p></li>
1.1       mike     4035: 
                   4036:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   4037:      <a href="#insertion-mode">insertion mode</a>.</p>
                   4038: 
1.91      mike     4039:      </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
                   4040:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     4041: 
                   4042:     </ol></dd>
                   4043: 
                   4044:    <dt>An end tag whose tag name is "head"</dt>
                   4045:    <dd>
                   4046: 
                   4047:     <p>Pop the <a href="#current-node">current node</a> (which will be the
1.159     mike     4048:     <code><a href="semantics.html#the-head-element-0">head</a></code> element) off the <a href="#stack-of-open-elements">stack of open
1.1       mike     4049:     elements</a>.</p>
                   4050: 
                   4051:     <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>
                   4052: 
                   4053:    </dd>
                   4054: 
                   4055:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4056:    <dd>
                   4057:     <p>Act as described in the "anything else" entry below.</p>
                   4058:    </dd>
                   4059: 
                   4060:    <dt>A start tag whose tag name is "head"</dt>
                   4061:    <dt>Any other end tag</dt>
                   4062:    <dd>
                   4063:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4064:    </dd>
                   4065: 
                   4066:    <dt>Anything else</dt>
                   4067:    <dd>
                   4068: 
                   4069:     <!-- can't get here with an EOF and a fragment case -->
                   4070: 
                   4071:     <p>Act as if an end tag token with the tag name "head" had
                   4072:     been seen, and reprocess the current token.</p>
                   4073: 
                   4074:     <p class="XXX">In certain UAs, <a href="https://bugzilla.mozilla.org/attachment.cgi?id=180157&amp;action=view">some
                   4075:     elements</a> don't trigger the "in body" mode straight away,
                   4076:     but instead get put into the head. Do we want to copy
                   4077:     that?</p>
                   4078: 
                   4079:    </dd>
                   4080: 
                   4081:   </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>
                   4082: 
                   4083:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
                   4084:   mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
                   4085: 
                   4086:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   4087:    <dd>
                   4088:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4089:    </dd>
                   4090: 
                   4091:    <dt>A start tag whose tag name is "html"</dt>
                   4092:    <dd>
                   4093:     <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
                   4094:     mode</a>.</p>
                   4095:    </dd>
                   4096: 
                   4097:    <dt>An end tag whose tag name is "noscript"</dt>
                   4098:    <dd>
                   4099: 
                   4100:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   4101:     <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   4102:     elements</a>; the new <a href="#current-node">current node</a> will be a
1.159     mike     4103:     <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike     4104: 
                   4105:     <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>
                   4106: 
                   4107:    </dd>
                   4108: 
                   4109:    <dt>A character token that is one of U+0009 CHARACTER
                   4110:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4111:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4112:    <dt>A comment token</dt>
                   4113:    <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
                   4114:    <dd>
                   4115:     <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
                   4116:     mode</a>.</p>
                   4117:    </dd>
                   4118: 
                   4119:    <dt>An end tag whose tag name is "br"</dt>
                   4120:    <dd>
                   4121:     <p>Act as described in the "anything else" entry below.</p>
                   4122:    </dd>
                   4123: 
                   4124:    <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
                   4125:    <dt>Any other end tag</dt>
                   4126:    <dd>
                   4127:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4128:    </dd>
                   4129: 
                   4130:    <dt>Anything else</dt>
                   4131:    <dd>
                   4132: 
                   4133:     <!-- can't get here with an EOF and a fragment case -->
                   4134: 
                   4135:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   4136:     name "noscript" had been seen and reprocess the current
                   4137:     token.</p>
                   4138: 
                   4139:    </dd>
                   4140: 
                   4141:   </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>
                   4142: 
                   4143:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
                   4144:   mode: after head">after head</a>", tokens must be handled as follows:</p>
                   4145: 
                   4146:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4147:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4148:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4149:    <dd>
                   4150:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   4151:     the <a href="#current-node">current node</a>.</p>
                   4152:    </dd>
                   4153: 
                   4154:    <dt>A comment token</dt>
                   4155:    <dd>
                   4156:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4157:     node</a> with the <code title="">data</code> attribute set to
                   4158:     the data given in the comment token.</p>
                   4159:    </dd>
                   4160: 
                   4161:    <dt>A DOCTYPE token</dt>
                   4162:    <dd>
                   4163:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4164:    </dd>
                   4165: 
                   4166:    <dt>A start tag whose tag name is "html"</dt>
                   4167:    <dd>
                   4168:     <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
                   4169:     mode</a>.</p>
                   4170:    </dd>
                   4171: 
                   4172:    <dt>A start tag whose tag name is "body"</dt>
                   4173:    <dd>
                   4174: 
                   4175:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4176: 
                   4177:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4178: 
                   4179:     <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>
                   4180: 
                   4181:    </dd>
                   4182: 
                   4183:    <dt>A start tag whose tag name is "frameset"</dt>
                   4184:    <dd>
                   4185: 
                   4186:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4187: 
                   4188:     <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>
                   4189: 
                   4190:    </dd>
                   4191: 
                   4192:    <dt>A start tag token whose tag name is one of: "base", "link",
                   4193:    "meta", "noframes", "script", "style", "title"</dt>
                   4194:    <dd>
                   4195: 
                   4196:     <p><a href="#parse-error">Parse error</a>.</p>
                   4197: 
                   4198:     <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
                   4199:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4200: 
                   4201:     <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
                   4202:     mode</a>.</p>
                   4203: 
                   4204:     <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
                   4205:     of open elements</a>.</p>
                   4206: 
                   4207:     <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
                   4208:     pointer</a> cannot be null at this point.</p>
                   4209: 
                   4210:    </dd>
                   4211: 
                   4212:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4213:    <dd>
                   4214:     <p>Act as described in the "anything else" entry below.</p>
                   4215:    </dd>
                   4216: 
                   4217:    <dt>A start tag whose tag name is "head"</dt>
                   4218:    <dt>Any other end tag</dt>
                   4219:    <dd>
                   4220:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4221:    </dd>
                   4222: 
                   4223:    <dt>Anything else</dt>
                   4224:    <dd>
                   4225:     <p>Act as if a start tag token with the tag name "body" and no
                   4226:     attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
                   4227:     flag</a> back to "ok", and then reprocess the current
                   4228:     token.</p>
                   4229:    </dd>
                   4230: 
                   4231:   </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>
                   4232: 
                   4233:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
                   4234:   mode: in body">in body</a>", tokens must be handled as follows:</p>
                   4235: 
                   4236:   <dl class="switch"><dt>A character token</dt>
                   4237:    <dd>
                   4238: 
                   4239:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4240:     any.</p>
                   4241: 
                   4242:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   4243:     character</a> into the <a href="#current-node">current node</a>.</p>
                   4244: 
                   4245:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   4246:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   4247:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   4248:     flag</a> to "not ok".</p>
                   4249: 
                   4250:    </dd>
                   4251: 
                   4252:    <dt>A comment token</dt>
                   4253:    <dd>
                   4254:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4255:     node</a> with the <code title="">data</code> attribute set to
                   4256:     the data given in the comment token.</p>
                   4257:    </dd>
                   4258: 
                   4259:    <dt>A DOCTYPE token</dt>
                   4260:    <dd>
                   4261:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4262:    </dd>
                   4263: 
                   4264:    <dt>A start tag whose tag name is "html"</dt>
                   4265:    <dd>
                   4266:     <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
                   4267:     check to see if the attribute is already present on the top
                   4268:     element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
                   4269:     add the attribute and its corresponding value to that element.</p>
                   4270:    </dd>
                   4271: 
                   4272:    <dt>A start tag token whose tag name is one of: "base", "command",
                   4273:    "link", "meta", "noframes", "script", "style", "title"</dt>
                   4274:    <dd>
                   4275:     <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
                   4276:     mode</a>.</p>
                   4277:    </dd>
                   4278: 
                   4279:    <dt>A start tag whose tag name is "body"</dt>
                   4280:    <dd>
                   4281: 
                   4282:     <p><a href="#parse-error">Parse error</a>.</p>
                   4283: 
                   4284:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159     mike     4285:     elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1       mike     4286:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4287:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4288: 
                   4289:     <p>Otherwise, for each attribute on the token, check to see if
1.159     mike     4290:     the attribute is already present on the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1       mike     4291:     element (the second element) on the <a href="#stack-of-open-elements">stack of open
                   4292:     elements</a>. If it is not, add the attribute and its
                   4293:     corresponding value to that element.</p>
                   4294: 
                   4295:    </dd>
                   4296: 
                   4297:    <dt>A start tag whose tag name is "frameset"</dt>
                   4298:    <dd>
                   4299: 
                   4300:     <p><a href="#parse-error">Parse error</a>.</p>
                   4301: 
                   4302:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159     mike     4303:     elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1       mike     4304:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4305:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4306: 
                   4307:     <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
                   4308:     the token.</p>
                   4309: 
                   4310:     <p>Otherwise, run the following steps:</p>
                   4311: 
                   4312:     <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
                   4313:      elements</a> from its parent node, if it has one.</p></li>
                   4314: 
                   4315:      <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
                   4316:      open elements</a>, from the <a href="#current-node">current node</a> up to,
1.159     mike     4317:      but not including, the root <code><a href="semantics.html#the-html-element-0">html</a></code> element.</p>
1.1       mike     4318: 
                   4319:      </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   4320:      token.</p></li>
                   4321: 
                   4322:      <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>
                   4323: 
                   4324:     </li></ol></dd>
                   4325: 
                   4326:    <dt>An end-of-file token</dt>
                   4327:    <dd>
                   4328: 
                   4329:     <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
                   4330:     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>
                   4331:     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
                   4332:     <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
                   4333:     <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
                   4334:     <code><a href="tabular-data.html#the-thead-element">thead</a></code> element, a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the
1.159     mike     4335:     <code><a href="semantics.html#the-body-element-0">body</a></code> element, or the <code><a href="semantics.html#the-html-element-0">html</a></code> element, then
1.1       mike     4336:     this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
                   4337:     fragment cases) -->
                   4338: 
                   4339:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   4340: 
                   4341:    </dd>
                   4342: 
                   4343:    <dt>An end tag whose tag name is "body"</dt>
                   4344:    <dd>
                   4345: 
                   4346:     <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
                   4347:     in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
                   4348:     token.</p>
                   4349: 
                   4350:     <!-- if we get here, the insertion mode here is forcibly "in
                   4351:     body". -->
                   4352: 
                   4353:     <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
                   4354:     elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
                   4355:     <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
                   4356:     <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
                   4357:     <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
                   4358:     <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
                   4359:     <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
                   4360:     <code><a href="tabular-data.html#the-th-element">th</a></code> element, a <code><a href="tabular-data.html#the-thead-element">thead</a></code> element, a
1.159     mike     4361:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the <code><a href="semantics.html#the-body-element-0">body</a></code> element, or the
                   4362:     <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1       mike     4363:     error</a>.</p> <!-- (some of those are fragment cases, e.g. for
                   4364:     <tbody> you'd have hit the first paragraph since the <body>
                   4365:     wouldn't be in scope, unless it was a fragment case) -->
                   4366: 
                   4367:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   4368:     then we'd have to somehow keep track of its state when we switch
                   4369:     to after-body. -->
                   4370: 
                   4371:     <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>
                   4372: 
                   4373:    </dd>
                   4374: 
                   4375:    <dt>An end tag whose tag name is "html"</dt>
                   4376:    <dd>
                   4377: 
                   4378:     <p>Act as if an end tag with tag name "body" had been seen,
                   4379:     then, if that token wasn't ignored, reprocess the current
                   4380:     token.</p>
                   4381: 
                   4382:     <p class="note">The fake end tag token here can only be
                   4383:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   4384: 
                   4385:    </dd>
                   4386: 
                   4387:    <!-- start tags for non-phrasing flow content elements -->
                   4388: 
                   4389:    <!-- the normal ones -->
                   4390:    <dt>A start tag whose tag name is one of: "address", "article",
1.86      mike     4391:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
                   4392:    "details", "dialog", "dir", "div", "dl", "fieldset", "figure",
                   4393:    "footer", "header", "hgroup", "menu", "nav", "ol", "p", "section",
                   4394:    "ul"</dt>
1.1       mike     4395:    <dd>
                   4396: 
                   4397:     <!-- As of May 2008 this doesn't match any browser exactly, but is
                   4398:     as close to what IE does as I can get without doing the non-tree
                   4399:     DOM nonsense, and thus should actually afford better compatibility
                   4400:     when implemented by the other browsers. -->
                   4401: 
                   4402:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4403:     an element in scope">has a <code>p</code> element in
                   4404:     scope</a>, then act as if an end tag with the tag name
                   4405:     "p" had been seen.</p>
                   4406: 
                   4407:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4408: 
                   4409:    </dd>
                   4410: 
                   4411:    <!-- as normal, but close h1-h6 if it's the current node -->
                   4412:    <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
                   4413:    "h5", "h6"</dt>
                   4414:    <dd>
                   4415: 
                   4416:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4417:     an element in scope">has a <code>p</code> element in
                   4418:     scope</a>, then act as if an end tag with the tag name
                   4419:     "p" had been seen.</p>
                   4420: 
                   4421:     <p>If the <a href="#current-node">current node</a> is an element whose tag name
                   4422:     is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
                   4423:     <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
                   4424:     the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4425:     <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
                   4426: 
                   4427:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4428: 
                   4429:    </dd>
                   4430: 
                   4431:    <!-- as normal, but drops leading newline -->
                   4432:    <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
                   4433:    <dd>
                   4434: 
                   4435:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4436:     an element in scope">has a <code>p</code> element in
                   4437:     scope</a>, then act as if an end tag with the tag name
                   4438:     "p" had been seen.</p>
                   4439: 
                   4440:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4441: 
                   4442:     <p>If the next token is a U+000A LINE FEED (LF) character
                   4443:     token, then ignore that token and move on to the next
                   4444:     one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
                   4445:     ignored as an authoring convenience.)</p>
                   4446: 
                   4447:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4448: 
                   4449:    </dd>
                   4450: 
                   4451:    <!-- as normal, but interacts with the form element pointer -->
                   4452:    <dt>A start tag whose tag name is "form"</dt>
                   4453:    <dd>
                   4454: 
                   4455:     <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
                   4456:     pointer</a> is not null, then this is a <a href="#parse-error">parse
                   4457:     error</a>; ignore the token.</p>
                   4458: 
                   4459:     <p>Otherwise:</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><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
                   4467:     <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
                   4468:     point to the element created.</p>
                   4469: 
                   4470:    </dd>
                   4471: 
                   4472:    <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
                   4473:    <dt>A start tag whose tag name is "li"</dt>
                   4474:    <dd>
                   4475: 
                   4476:     <p>Run the following algorithm:</p>
                   4477: 
                   4478:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4479: 
                   4480:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4481:      node</a> (the bottommost node of the stack).</p></li>
                   4482: 
                   4483:      <li><p>If <var title="">node</var> is an <code><a href="semantics.html#the-li-element">li</a></code> element,
                   4484:      then act as if an end tag with the tag name "li" had
                   4485:      been seen, then jump to the last step.</p></li>
                   4486: 
                   4487:      <li><p><i>Loop</i>: If <var title="">node</var> is not in the
                   4488:      <a href="#formatting">formatting</a> category, and is not in the
                   4489:      <a href="#phrasing">phrasing</a> category, and is not an
                   4490:      <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>
                   4491:      element, then jump to the last step.</p></li> <!-- an element
                   4492:      <foo> is in this list if the following markup:
                   4493: 
                   4494:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
                   4495: 
                   4496:      ...results in the second <li> not being (in any way) a descendant
                   4497:      of the first <li>, or if <foo> is a formatting element that gets
                   4498:      reopened later. -->
                   4499: 
                   4500:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4501:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4502:      the step labeled <i>loop</i>.</p></li>
                   4503: 
                   4504:      <li>
                   4505: 
                   4506:       <p>This is the last step.</p>
                   4507: 
                   4508:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4509:       an element in scope">has a <code>p</code> element in
                   4510:       scope</a>, then act as if an end tag with the tag name
                   4511:       "p" had been seen.</p>
                   4512: 
                   4513:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4514:       token.</p>
                   4515: 
                   4516:      </li>
                   4517: 
                   4518:     </ol></dd>
                   4519: 
                   4520:    <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases  -->
                   4521:    <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
                   4522:    <dd>
                   4523: 
                   4524:     <p>Run the following algorithm:</p>
                   4525: 
                   4526:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4527: 
                   4528:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4529:      node</a> (the bottommost node of the stack).</p></li>
                   4530: 
                   4531:      <li><p><i>Loop</i>: If <var title="">node</var> is a
                   4532:      <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
                   4533:      tag with the same tag name as <var title="">node</var> had been
                   4534:      seen, then jump to the last step.</p></li>
                   4535: 
                   4536:      <li><p>If <var title="">node</var> is not in the
                   4537:      <a href="#formatting">formatting</a> category, and is not in the
                   4538:      <a href="#phrasing">phrasing</a> category, and is not an
                   4539:      <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>
                   4540:      element, then jump to the last step.</p></li> <!-- an element
                   4541:      <foo> is in this list if the following markup:
                   4542: 
                   4543:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
                   4544: 
                   4545:      ...results in the second <dt> not being (in any way) a descendant
                   4546:      of the first <dt>, or if <foo> is a formatting element that gets
                   4547:      reopened later. -->
                   4548: 
                   4549:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4550:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4551:      the step labeled <i>loop</i>.</p></li>
                   4552: 
                   4553:      <li>
                   4554: 
                   4555:       <p>This is the last step.</p>
                   4556: 
                   4557:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4558:       an element in scope">has a <code>p</code> element in
                   4559:       scope</a>, then act as if an end tag with the tag name
                   4560:       "p" had been seen.</p>
                   4561: 
                   4562:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4563:       token.</p>
                   4564: 
                   4565:      </li>
                   4566: 
                   4567:     </ol></dd>
                   4568: 
                   4569:    <!-- same as normal, but effectively ends parsing -->
                   4570:    <dt>A start tag whose tag name is "plaintext"</dt>
                   4571:    <dd>
                   4572: 
                   4573:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4574:     an element in scope">has a <code>p</code> element in
                   4575:     scope</a>, then act as if an end tag with the tag name
                   4576:     "p" had been seen.</p>
                   4577: 
                   4578:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4579: 
                   4580:     <p>Switch the <a href="#content-model-flag">content model flag</a> to the PLAINTEXT
                   4581:     state.</p>
                   4582: 
                   4583:     <p class="note">Once a start tag with the tag name "plaintext"
                   4584:     has been seen, that will be the last token ever seen other
                   4585:     than character tokens (and the end-of-file token), because
                   4586:     there is no way to switch the <a href="#content-model-flag">content model flag</a>
                   4587:     out of the PLAINTEXT state.</p>
                   4588: 
                   4589:    </dd>
                   4590: 
                   4591:    <!-- end tags for non-phrasing flow content elements -->
                   4592: 
                   4593:    <!-- the normal ones -->
                   4594:    <dt>An end tag whose tag name is one of: "address", "article",
1.86      mike     4595:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
                   4596:    "details", "dialog", "dir", "div", "dl", "fieldset", "figure",
                   4597:    "footer", "header", "hgroup", "listing", "menu", "nav", "ol",
                   4598:    "pre", "section", "ul"</dt>
1.1       mike     4599:    <dd>
                   4600: 
                   4601:     <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>
                   4602:     with the same tag name as that of the token, then this is a
                   4603:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4604: 
                   4605:     <p>Otherwise, run these steps:</p>
                   4606: 
                   4607:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4608: 
                   4609:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4610:      the same tag name as that of the token, then this is a
                   4611:      <a href="#parse-error">parse error</a>.</p></li>
                   4612: 
                   4613:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4614:      until an element with the same tag name as the token has been
                   4615:      popped from the stack.</p></li>
                   4616: 
                   4617:     </ol></dd>
                   4618: 
                   4619:    <!-- removes the form element pointer instead of the matching node -->
                   4620:    <dt>An end tag whose tag name is "form"</dt>
                   4621:    <dd>
                   4622: 
                   4623:     <p>Let <var title="">node</var> be the element that the
                   4624:     <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
                   4625:     to.</p>
                   4626: 
                   4627:     <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   4628:     to null.</p>
                   4629: 
                   4630:     <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
                   4631:     elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
                   4632:     scope">have <var title="">node</var> in scope</a>, then this is
                   4633:     a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4634: 
                   4635:     <p>Otherwise, run these steps:</p>
                   4636: 
                   4637:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4638: 
                   4639:      <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
                   4640:      error</a>.</p></li>
                   4641: 
                   4642:      <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
                   4643:      open elements</a>.</p></li>
                   4644: 
                   4645:     </ol></dd>
                   4646: 
                   4647:    <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
                   4648:    <dt>An end tag whose tag name is "p"</dt>
                   4649:    <dd>
                   4650: 
                   4651:     <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>
                   4652:     with the same tag name as that of the token, then this is a
                   4653:     <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
                   4654:     "p" had been seen, then reprocess the current token.</p>
                   4655: 
                   4656:     <p>Otherwise, run these steps:</p>
                   4657: 
                   4658:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4659:      for elements with the same tag name as the token.</p></li>
                   4660: 
                   4661:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4662:      the same tag name as that of the token, then this is a
                   4663:      <a href="#parse-error">parse error</a>.</p></li>
                   4664: 
                   4665:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4666:      until an element with the same tag name as the token has been
                   4667:      popped from the stack.</p></li>
                   4668: 
                   4669:     </ol></dd>
                   4670: 
1.234     mike     4671:    <!-- as normal, but needs care as the elements have optional tags, and are further scoped by <ol>/<ul> -->
                   4672:    <dt>An end tag whose tag name is "li"</dt>
                   4673:    <dd>
                   4674: 
                   4675:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-list-item-scope" title="has an element in list item scope">have an element in list
                   4676:     item scope</a> with the same tag name as that of the token,
                   4677:     then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4678: 
                   4679:     <p>Otherwise, run these steps:</p>
                   4680: 
                   4681:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4682:      for elements with the same tag name as the token.</p></li>
                   4683: 
                   4684:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4685:      the same tag name as that of the token, then this is a
                   4686:      <a href="#parse-error">parse error</a>.</p></li>
                   4687: 
                   4688:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4689:      until an element with the same tag name as the token has been
                   4690:      popped from the stack.</p></li>
                   4691: 
                   4692:     </ol></dd>
                   4693: 
1.1       mike     4694:    <!-- as normal, but needs care as the elements have optional tags -->
1.234     mike     4695:    <dt>An end tag whose tag name is one of: "dd", "dt"</dt>
1.1       mike     4696:    <dd>
                   4697: 
                   4698:     <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>
                   4699:     with the same tag name as that of the token, then this is a
                   4700:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4701: 
                   4702:     <p>Otherwise, run these steps:</p>
                   4703: 
                   4704:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4705:      for elements with the same tag name as the token.</p></li>
                   4706: 
                   4707:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4708:      the same tag name as that of the token, then this is a
                   4709:      <a href="#parse-error">parse error</a>.</p></li>
                   4710: 
                   4711:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4712:      until an element with the same tag name as the token has been
                   4713:      popped from the stack.</p></li>
                   4714: 
                   4715:     </ol></dd>
                   4716: 
                   4717:    <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
                   4718:    <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
                   4719:    <dd>
                   4720: 
                   4721:     <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>
                   4722:     whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
                   4723:     then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4724: 
                   4725:     <p>Otherwise, run these steps:</p>
                   4726: 
                   4727:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4728: 
                   4729:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4730:      the same tag name as that of the token, then this is a
                   4731:      <a href="#parse-error">parse error</a>.</p></li>
                   4732: 
                   4733:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4734:      until an element whose tag name is one of "h1", "h2", "h3", "h4",
                   4735:      "h5", or "h6" has been popped from the stack.</p></li>
                   4736: 
                   4737:     </ol></dd>
                   4738: 
                   4739:    <dt>An end tag whose tag name is "sarcasm"</dt>
                   4740:    <dd>
                   4741:     <p>Take a deep breath, then act as described in the "any other end
                   4742:     tag" entry below.</p>
                   4743:    </dd>
                   4744: 
                   4745:    <!-- ADOPTION AGENCY ELEMENTS
                   4746:         Mozilla-only: bdo blink del ins sub sup q
                   4747:         Safari-only: code dfn kbd nobr samp var wbr
                   4748:         Both: a b big em font i s small strike strong tt u -->
                   4749: 
                   4750:    <dt>A start tag whose tag name is "a"</dt>
                   4751:    <dd>
                   4752: 
                   4753:     <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
                   4754:     contains an element whose tag name is "a" between the end of
                   4755:     the list and the last marker on the list (or the start of the
                   4756:     list if there is no marker on the list), then this is a
                   4757:     <a href="#parse-error">parse error</a>; act as if an end tag with the tag
                   4758:     name "a" had been seen, then remove that element from the
                   4759:     <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
                   4760:     <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
                   4761:     already remove it (it might not have if the element is not
                   4762:     <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
                   4763:     scope</a>).</p>
                   4764: 
                   4765:     <p class="example">In the non-conforming stream
                   4766:     <code>&lt;a&#160;href="a"&gt;a&lt;table&gt;&lt;a&#160;href="b"&gt;b&lt;/table&gt;x</code>,
                   4767:     the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
                   4768:     the second one, and the "x" character would be inside a link
                   4769:     to "b", not to "a". This is despite the fact that the outer
                   4770:     <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
                   4771:     regular <code>&lt;/a&gt;</code> end tag at the start of the table
                   4772:     wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
                   4773: 
                   4774:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4775:     any.</p>
                   4776: 
                   4777:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4778:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4779:     elements</a>.</p>
                   4780: 
                   4781:    </dd>
                   4782: 
                   4783:    <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
                   4784:    "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
                   4785:    <dd>
                   4786: 
                   4787:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4788:     any.</p>
                   4789: 
                   4790:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4791:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4792:     elements</a>.</p>
                   4793: 
                   4794:    </dd>
                   4795: 
                   4796:    <dt>A start tag whose tag name is "nobr"</dt>
                   4797:    <dd>
                   4798: 
                   4799:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4800:     any.</p>
                   4801: 
                   4802:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   4803:     element in scope">has a <code>nobr</code> element in scope</a>,
                   4804:     then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
                   4805:     the tag name "nobr" had been seen, then once again
                   4806:     <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
                   4807:     any.</p>
                   4808: 
                   4809:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4810:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4811:     elements</a>.</p>
                   4812: 
                   4813:    </dd>
                   4814: 
                   4815:    <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
                   4816:    "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
                   4817:    "strike", "strong", "tt", "u"</dt>
                   4818:    <dd>
                   4819: 
                   4820:     <p>Follow these steps:</p>
                   4821: 
                   4822:     <ol><li>
                   4823: 
                   4824:       <p>Let the <var title="">formatting element</var> be the
                   4825:       last element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   4826:       elements</a> that:</p>
                   4827: 
                   4828:       <ul><li>is between the end of the list and the last scope
                   4829:        marker in the list, if any, or the start of the list
                   4830:        otherwise, and</li>
                   4831: 
                   4832:        <li>has the same tag name as the token.</li>
                   4833: 
                   4834:       </ul><p>If there is no such node, or, if that node is also in the
                   4835:       <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
                   4836:       <a href="#parse-error">parse error</a>; ignore the token, and abort these
                   4837:       steps.</p>
                   4838: 
                   4839:       <p>Otherwise, if there is such a node, but that node is not
                   4840:       in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
                   4841:       <a href="#parse-error">parse error</a>; remove the element from the list,
                   4842:       and abort these steps.</p>
                   4843: 
                   4844:       <p>Otherwise, there is a <var title="">formatting
                   4845:       element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
                   4846:       open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
                   4847:       element in scope">in scope</a>. If the element is not the
                   4848:       <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
                   4849:       error</a>. In any case, proceed with the algorithm as
                   4850:       written in the following steps.</p>
                   4851: 
                   4852:      </li>
                   4853: 
                   4854:      <li><p>Let the <var title="">furthest block</var> be the
                   4855:      topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
                   4856:      is lower in the stack than the <var title="">formatting
                   4857:      element</var>, and is not an element in the
                   4858:      <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
                   4859:      categories. There might not be one.</p></li>
                   4860: 
                   4861:      <li><p>If there is no <var title="">furthest block</var>,
                   4862:      then the UA must skip the subsequent steps and instead just
                   4863:      pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
                   4864:      elements</a>, from the <a href="#current-node">current node</a> up to and
                   4865:      including the <var title="">formatting element</var>, and
                   4866:      remove the <var title="">formatting element</var> from the
                   4867:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
                   4868: 
                   4869:      <li><p>Let the <var title="">common ancestor</var> be the element
                   4870:      immediately above the <var title="">formatting element</var> in the
                   4871:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   4872: 
                   4873:      <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
                   4874:      formatting elements</a> relative to the elements on either
                   4875:      side of it in the list.</p></li>
                   4876: 
                   4877:      <li>
                   4878: 
                   4879:       <p>Let <var title="">node</var> and <var title="">last node</var> be the
                   4880:       <var title="">furthest block</var>. Follow these steps:</p>
                   4881: 
                   4882:       <ol><li>Let <var title="">node</var> be the element immediately
                   4883:        above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
                   4884:        elements</a>.</li>
                   4885: 
                   4886:        <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
                   4887:        active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
                   4888:        elements</a> and then go back to step 1.</li>
                   4889: 
                   4890:        <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
                   4891:        in the overall algorithm.</li>
                   4892: 
                   4893:        <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
                   4894:        bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   4895:        elements</a>.</li>
                   4896: 
                   4897:        <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   4898:        element <var title="">node</var> was created, replace the entry
                   4899:        for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
                   4900:        formatting elements</a> with an entry for the new element,
                   4901:        replace the entry for <var title="">node</var> in the
                   4902:        <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
                   4903:        element, and let <var title="">node</var> be the new
                   4904:        element.</li>
                   4905: 
                   4906:        <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
                   4907:        parent node if any.</li>
                   4908: 
                   4909:        <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
                   4910: 
                   4911:        <li>Return to step 1 of this inner set of steps.</li>
                   4912: 
                   4913:       </ol></li>
                   4914: 
                   4915:      <li>
                   4916: 
                   4917:       <p>If the <var title="">common ancestor</var> node is a
                   4918:       <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>,
                   4919:       <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,
                   4920:       <a href="#foster-parent">foster parent</a> whatever <var title="">last
                   4921:       node</var> ended up being in the previous step, first removing
                   4922:       it from its previous parent node if any.</p>
                   4923: 
                   4924:       <p>Otherwise, append whatever <var title="">last node</var>
                   4925:       ended up being in the previous step to the <var title="">common
                   4926:       ancestor</var> node, first removing it from its previous parent
                   4927:       node if any.</p>
                   4928: 
                   4929:      </li>
                   4930: 
                   4931:      <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   4932:      <var title="">formatting element</var> was created.</p></li>
                   4933: 
                   4934:      <li><p>Take all of the child nodes of the <var title="">furthest
                   4935:      block</var> and append them to the element created in the last
                   4936:      step.</p></li>
                   4937: 
                   4938:      <li><p>Append that new element to the <var title="">furthest
                   4939:      block</var>.</p></li>
                   4940: 
                   4941:      <li><p>Remove the <var title="">formatting element</var> from the
                   4942:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
                   4943:      new element into the <a href="#list-of-active-formatting-elements">list of active formatting
                   4944:      elements</a> at the position of the aforementioned
                   4945:      bookmark.</p></li>
                   4946: 
                   4947:      <li><p>Remove the <var title="">formatting element</var> from the
                   4948:      <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
                   4949:      into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
                   4950:      the position of the <var title="">furthest block</var> in that
                   4951:      stack.</p></li>
                   4952: 
                   4953:      <li><p>Jump back to step 1 in this series of steps.</p></li>
                   4954: 
                   4955:     </ol><!--XXX
                   4956:     <div class="example">
                   4957:      <p class="XXX">Need an example.</p>
                   4958:     </div>
                   4959: --><p class="note">Because of the way this algorithm causes elements to
                   4960:     change parents, it has been dubbed the "adoption agency algorithm"
                   4961:     (in contrast with other possibly algorithms for dealing with
                   4962:     misnested content, which included the "incest algorithm", the
                   4963:     "secret affair algorithm", and the "Heisenberg algorithm").</p>
                   4964: 
                   4965:    </dd>
                   4966: 
                   4967:    <dt>A start tag whose tag name is "button"</dt>
                   4968:    <dd>
                   4969: 
                   4970:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4971:     an element in scope">has a <code>button</code> element in
                   4972:     scope</a>, then this is a <a href="#parse-error">parse error</a>;
                   4973:     act as if an end tag with the tag name "button" had been seen,
                   4974:     then reprocess the token.</p>
                   4975: 
                   4976:     <p>Otherwise:</p>
                   4977: 
                   4978:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4979:     any.</p>
                   4980: 
                   4981:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4982: 
                   4983:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   4984:     formatting elements</a>.</p>
                   4985: 
                   4986:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4987: 
                   4988:    </dd>
                   4989: 
                   4990:    <dt>A start tag token whose tag name is one of: "applet",
                   4991:    "marquee", "object"</dt>
                   4992:    <dd>
                   4993: 
                   4994:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4995:     any.</p>
                   4996: 
                   4997:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4998: 
                   4999:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5000:     formatting elements</a>.</p>
                   5001: 
                   5002:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5003: 
                   5004:    </dd>
                   5005: 
                   5006:    <dt>An end tag token whose tag name is one of: "applet", "button",
                   5007:    "marquee", "object"</dt>
                   5008:    <dd>
                   5009: 
                   5010:     <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>
                   5011:     with the same tag name as that of the token, then this is a
                   5012:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   5013: 
                   5014:     <p>Otherwise, run these steps:</p>
                   5015: 
                   5016:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5017: 
                   5018:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   5019:      the same tag name as that of the token, then this is a
                   5020:      <a href="#parse-error">parse error</a>.</p></li>
                   5021: 
                   5022:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   5023:      until an element with the same tag name as the token has been
                   5024:      popped from the stack.</p></li>
                   5025: 
                   5026:      <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
                   5027:      last marker</a>.</li>
                   5028: 
                   5029:     </ol></dd>
                   5030: 
                   5031:    <dt>A start tag whose tag name is "table"</dt>
                   5032:    <dd>
                   5033: 
                   5034:     <p>If the <code>Document</code> is <em>not</em> set to
                   5035:     <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
                   5036:     elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
                   5037:     <code>p</code> element in scope</a>, then act as if an end tag
                   5038:     with the tag name "p" had been seen.</p> <!-- i hate myself (this
                   5039:     quirk was basically caused by acid2; if i'd realised we could
                   5040:     change the specs when i wrote acid2, we could have avoided having
                   5041:     any parsing-mode quirks) -Hixie -->
                   5042: 
                   5043:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5044: 
                   5045:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5046: 
                   5047:     <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>
                   5048: 
                   5049:    </dd>
                   5050: 
                   5051:    <dt>A start tag whose tag name is one of: "area", "basefont",
                   5052:    "bgsound", "br", "embed", "img", "input", "keygen", "spacer",
                   5053:    "wbr"</dt>
                   5054:    <dd>
                   5055: 
                   5056:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5057:     any.</p>
                   5058: 
                   5059:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5060:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5061:     elements</a>.</p>
                   5062: 
                   5063:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5064:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5065: 
                   5066:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
                   5067:     shouldn't really do it for <area>, <basefont>, <bgsound>, and
                   5068:     <spacer> -->
                   5069: 
                   5070:    </dd>
                   5071: 
                   5072:    <dt>A start tag whose tag name is one of: "param", "source"</dt>
                   5073:    <dd>
                   5074: 
                   5075:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5076:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5077:     elements</a>.</p>
                   5078: 
                   5079:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5080:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5081: 
                   5082:    </dd>
                   5083: 
                   5084:    <dt>A start tag whose tag name is "hr"</dt>
                   5085:    <dd>
                   5086: 
                   5087:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5088:     an element in scope">has a <code>p</code> element in
                   5089:     scope</a>, then act as if an end tag with the tag name
                   5090:     "p" had been seen.</p>
                   5091: 
                   5092:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5093:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5094:     elements</a>.</p>
                   5095: 
                   5096:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5097:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5098: 
                   5099:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5100: 
                   5101:    </dd>
                   5102: 
                   5103:    <dt>A start tag whose tag name is "image"</dt>
                   5104:    <dd>
                   5105:     <p><a href="#parse-error">Parse error</a>. Change the token's tag name
                   5106:     to "img" and reprocess it. (Don't ask.)</p> <!-- As of
                   5107:     2005-12, studies showed that around 0.2% of pages used the
                   5108:     <image> element. -->
                   5109:    </dd>
                   5110: 
                   5111:    <dt id="isindex">A start tag whose tag name is "isindex"</dt>
                   5112:    <dd>
                   5113: 
                   5114:     <p><a href="#parse-error">Parse error</a>.</p>
                   5115: 
                   5116:     <p>If the <a href="#form-element-pointer"><code title="">form</code> element
                   5117:     pointer</a> is not null, then ignore the token.</p>
                   5118: 
                   5119:     <p>Otherwise:</p>
                   5120: 
                   5121:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5122:     token's <i>self-closing flag</i></a>, if it is set.</p> <!--
                   5123:     purely to reduce the number of errors (we don't care if they
                   5124:     included the /, they're not supposed to be including the tag at
                   5125:     all! -->
                   5126: 
                   5127:     <p>Act as if a start tag token with the tag name "form" had been seen.</p>
                   5128: 
                   5129:     <p>If the token has an attribute called "action", set the
                   5130:     <code title="attr-form-action">action</code> attribute on the
                   5131:     resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
                   5132:     "action" attribute of the token.</p>
                   5133: 
                   5134:     <p>Act as if a start tag token with the tag name "hr" had been
                   5135:     seen.</p>
                   5136: 
                   5137:     <p>Act as if a start tag token with the tag name "label" had been
                   5138:     seen.</p>
                   5139: 
                   5140:     <p>Act as if a stream of character tokens had been seen (see below
                   5141:     for what they should say).</p>
                   5142: 
                   5143:     <p>Act as if a start tag token with the tag name "input" had been
                   5144:     seen, with all the attributes from the "isindex" token except
                   5145:     "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
                   5146:     <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
                   5147: 
                   5148:     <p>Act as if a stream of character tokens had been seen (see
                   5149:     below for what they should say).</p>
                   5150: 
                   5151:     <p>Act as if an end tag token with the tag name "label" had been
                   5152:     seen.</p>
                   5153: 
                   5154:     <p>Act as if a start tag token with the tag name "hr" had been
                   5155:     seen.</p>
                   5156: 
                   5157:     <p>Act as if an end tag token with the tag name "form" had been
                   5158:     seen.</p>
                   5159: 
                   5160:     <p>If the token has an attribute with the name "prompt", then the
                   5161:     first stream of characters must be the same string as given in
                   5162:     that attribute, and the second stream of characters must be
                   5163:     empty. Otherwise, the two streams of character tokens together
                   5164:     should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
                   5165:     equivalent of "This is a searchable index. Insert your search
                   5166:     keywords here: (input field)" in the user's preferred
                   5167:     language.</p>
                   5168: 
                   5169:    </dd>
                   5170: 
                   5171:    <dt>A start tag whose tag name is "textarea"</dt>
                   5172:    <dd>
                   5173: 
                   5174:     <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   5175:      token.</p></li>
                   5176: 
                   5177:      <li><p>If the next token is a U+000A LINE FEED (LF) character
                   5178:      token, then ignore that token and move on to the next
                   5179:      one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
                   5180:      ignored as an authoring convenience.)</p></li>
                   5181: 
                   5182:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
                   5183:      the RCDATA state.</p></li>
                   5184: 
                   5185:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
                   5186:      current <a href="#insertion-mode">insertion mode</a>.</p>
                   5187: 
                   5188:      </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
                   5189:      ok".</p></li>
                   5190: 
1.91      mike     5191:      <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
                   5192:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     5193: 
                   5194:     </ol></dd>
                   5195: 
                   5196:    <dt>A start tag whose tag name is "xmp"</dt>
                   5197:    <dd>
                   5198: 
1.233     mike     5199:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5200:     an element in scope">has a <code>p</code> element in
                   5201:     scope</a>, then act as if an end tag with the tag name
                   5202:     "p" had been seen.</p>
                   5203: 
1.1       mike     5204:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5205:     any.</p>
                   5206: 
                   5207:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5208: 
1.91      mike     5209:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5210: 
                   5211:    </dd>
                   5212: 
                   5213:    <dt>A start tag whose tag name is "iframe"</dt>
                   5214:    <dd>
                   5215: 
                   5216:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5217: 
1.91      mike     5218:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5219: 
                   5220:    </dd>
                   5221: 
                   5222:    <dt>A start tag whose tag name is "noembed"</dt>
                   5223:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   5224:    <dd>
                   5225: 
1.91      mike     5226:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5227: 
                   5228:    </dd>
                   5229: 
                   5230:    <dt>A start tag whose tag name is "select"</dt>
                   5231:    <dd>
                   5232: 
                   5233:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5234:     any.</p>
                   5235: 
                   5236:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5237: 
                   5238:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5239: 
                   5240:     <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>",
                   5241:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5242:     body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   5243:     row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   5244:     cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
                   5245:     "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
                   5246:     table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
                   5247:     to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
                   5248: 
                   5249:    </dd>
                   5250: 
                   5251:    <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
                   5252:    <dd>
                   5253: 
                   5254:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5255:     element in scope">has an <code>option</code> element in
                   5256:     scope</a>, then act as if an end tag with the tag name "option"
                   5257:     had been seen.</p>
                   5258: 
                   5259:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5260:     any.</p>
                   5261: 
                   5262:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5263: 
                   5264:    </dd>
                   5265: 
                   5266:    <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
                   5267:    <dd>
                   5268: 
                   5269:     <!-- the parsing rules for ruby really don't match IE much at all,
                   5270:          but in practice the markup used is very simple and so strict
                   5271:          compatibility with IE isn't required. For example, as defined
                   5272:          here we get very, very different behaviour than IE for
                   5273:          pathological cases like:
                   5274: 
                   5275:            <ruby><ol><li><p>a<rt>b
                   5276:            <ruby>a<rt>b<p>c
                   5277: 
                   5278:          But in practice most ruby markup falls into these cases:
                   5279: 
                   5280:            <ruby>a<rt>b</ruby>
                   5281:            <ruby>a<rp>b<rt>c<rp>d</ruby>
                   5282:            <ruby>a<rt>b</rt></ruby>
                   5283:            <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
                   5284: 
                   5285:     -->
                   5286: 
                   5287:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5288:     element in scope">has a <code>ruby</code> element in scope</a>,
                   5289:     then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
                   5290:     node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
                   5291:     <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
                   5292:     node</a> up to the node immediately before the bottommost
                   5293:     <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
                   5294:     elements</a>.</p>
                   5295: 
                   5296:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5297: 
                   5298:    </dd>
                   5299: 
                   5300:    <dt>An end tag whose tag name is "br"</dt>
                   5301:    <dd>
                   5302:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
                   5303:     the tag name "br" had been seen. Ignore the end tag token.</p>
                   5304:    </dd>
                   5305: 
                   5306:    <dt>A start tag whose tag name is "math"</dt>
                   5307:    <dd>
                   5308: 
                   5309:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5310:     any.</p>
                   5311: 
                   5312:     <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
                   5313:     fixes the case of MathML attributes that are not all
                   5314:     lowercase.)</p>
                   5315: 
                   5316:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5317:     fixes the use of namespaced attributes, in particular XLink.)</p>
                   5318: 
                   5319:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5320:     <a href="#mathml-namespace">MathML namespace</a>.</p>
                   5321: 
                   5322:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5323:     the following change would be implied, except we'd have to do it
                   5324:     even in the face of a self-closed tag:
                   5325:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5326:     -->
                   5327: 
                   5328:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5329:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5330:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5331:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5332: 
                   5333:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5334:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5335:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5336:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5337:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5338:     foreign content">in foreign content</a>".</p>
                   5339: 
                   5340:    </dd>
                   5341: 
                   5342:    <dt>A start tag whose tag name is "svg"</dt>
                   5343:    <dd>
                   5344: 
                   5345:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5346:     any.</p>
                   5347: 
                   5348:     <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
                   5349:     the case of SVG attributes that are not all lowercase.)</p>
                   5350: 
                   5351:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5352:     fixes the use of namespaced attributes, in particular XLink in
                   5353:     SVG.)</p>
                   5354: 
                   5355:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5356:     <a href="#svg-namespace">SVG namespace</a>.</p>
                   5357: 
                   5358:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5359:     the following change would be implied, except we'd have to do it
                   5360:     even in the face of a self-closed tag:
                   5361:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5362:     -->
                   5363: 
                   5364:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5365:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5366:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5367:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5368: 
                   5369:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5370:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5371:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5372:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5373:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5374:     foreign content">in foreign content</a>".</p>
                   5375: 
                   5376:    </dd>
                   5377: 
                   5378:    <dt>A start <!--or end--> tag whose tag name is one of: "caption",
                   5379:    "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
                   5380:    "thead", "tr"</dt>
                   5381:    <!--<dt>An end tag whose tag name is one of: "area", "base",
                   5382:    "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
                   5383:    "img", "input", "isindex", "keygen", "link", "meta", "noembed",
                   5384:    "noframes", "param", "script", "select", "source", "spacer",
                   5385:    "style", "table", "textarea", "title", "wbr"</dt>-->
                   5386:    <!--<dt>An end tag whose tag name is "noscript", if the
                   5387:    <span>scripting flag</span> is enabled</dt>-->
                   5388:    <dd>
                   5389:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5390:     <!-- end tags are commented out because since they can never end
                   5391:     up on the stack anyway, the default end tag clause will
                   5392:     automatically handle them. we don't want to have text in the spec
                   5393:     that is just an optimisation, as that detracts from the spec
                   5394:     itself -->
                   5395:    </dd>
                   5396: 
                   5397:    <dt>Any other start tag</dt>
                   5398:    <dd>
                   5399: 
                   5400:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5401:     any.</p>
                   5402: 
                   5403:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5404: 
                   5405:     <p class="note">This element will be a <a href="#phrasing">phrasing</a>
                   5406:     element.</p>
                   5407: 
                   5408:    </dd>
                   5409: 
                   5410:    <dt>Any other end tag</dt>
                   5411:    <dd>
                   5412: 
                   5413:     <p>Run the following steps:</p>
                   5414: 
                   5415:     <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   5416:      node</a> (the bottommost node of the stack).</p></li>
                   5417: 
                   5418:      <li><p>If <var title="">node</var> has the same tag name as
                   5419:      the end tag token, then:</p>
                   5420: 
                   5421:       <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5422: 
                   5423:        <li><p>If the tag name of the end tag token does not match
                   5424:        the tag name of the <a href="#current-node">current node</a>, this is a
                   5425:        <a href="#parse-error">parse error</a>.</p></li>
                   5426: 
                   5427:        <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
                   5428:        to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
                   5429: 
                   5430:       </ol></li>
                   5431: 
                   5432:      <li><p>Otherwise, if <var title="">node</var> is in neither the
                   5433:      <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
                   5434:      category, then this is a <a href="#parse-error">parse error</a>; ignore the
                   5435:      token, and abort these steps.</p></li>
                   5436: 
                   5437:      <li><p>Set <var title="">node</var> to the previous entry in the
                   5438:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   5439: 
                   5440:      <li><p>Return to step 2.</p></li>
                   5441: 
                   5442:     </ol></dd>
                   5443: 
1.91      mike     5444:   </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     5445: 
                   5446:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.91      mike     5447:   mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>", tokens must be
1.1       mike     5448:   handled as follows:</p>
                   5449: 
                   5450:   <dl class="switch"><dt>A character token</dt>
                   5451:    <dd>
                   5452: 
                   5453:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   5454:     character</a> into the <a href="#current-node">current node</a>.</p>
                   5455: 
                   5456:    </dd>
                   5457: 
                   5458:    <dt>An end-of-file token</dt>
                   5459:    <dd>
                   5460: 
                   5461:     <!-- can't be the fragment case -->
                   5462:     <p><a href="#parse-error">Parse error</a>.</p>
                   5463: 
                   5464:     <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
                   5465:     element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
                   5466:     executed"</a>.</p>
                   5467: 
                   5468:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5469:     elements</a>.</p>
                   5470: 
                   5471:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5472:     insertion mode</a> and reprocess the current token.</p>
                   5473: 
                   5474:    </dd>
                   5475: 
                   5476:    <dt>An end tag whose tag name is "script"</dt>
                   5477:    <dd>
                   5478: 
                   5479:     <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
                   5480:     (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
                   5481: 
                   5482:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5483:     elements</a>.</p>
                   5484: 
                   5485:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5486:     insertion mode</a>.</p>
                   5487: 
                   5488:     <p>Let the <var title="">old insertion point</var> have the
                   5489:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   5490:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   5491:     input character</a>.</p>
                   5492: 
                   5493:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5494:     one.</p>
                   5495: 
                   5496:     <p><a href="semantics.html#running-a-script" title="running a script">Run</a> the <var title="">script</var>. This might cause some script to execute,
1.159     mike     5497:     which might cause <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters
1.1       mike     5498:     to be inserted into the tokenizer</a>, and might cause the
                   5499:     tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
                   5500: 
                   5501:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5502:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   5503:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5504: 
                   5505:     <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
                   5506:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   5507:     might be the "undefined" value.)</p>
                   5508: 
                   5509:     <p id="scriptTagParserResumes">At this stage, if there is a
                   5510:     <a href="semantics.html#pending-external-script">pending external script</a>, then:</p>
                   5511: 
                   5512:     <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
                   5513: 
                   5514:      <dd>
                   5515: 
                   5516:       <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
                   5517:       processing of any nested invocations of the tokenizer, yielding
                   5518:       control back to the caller. (Tokenization will resume when the
                   5519:       caller returns to the "outer" tree construction stage.)</p>
                   5520: 
                   5521:       <p class="note">The tree construction stage of this particular
                   5522:       parser is <a href="#nestedParsing">being called reentrantly</a>,
1.159     mike     5523:       say from a call to <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>.</p>
1.1       mike     5524: 
                   5525:      </dd>
                   5526: 
                   5527: 
                   5528:      <dt>Otherwise:</dt>
                   5529: 
                   5530:      <dd>
                   5531: 
                   5532:       <p>Follow these steps:</p>
                   5533: 
                   5534:       <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-external-script">pending
                   5535:        external script</a>. There is no longer a <a href="semantics.html#pending-external-script">pending
                   5536:        external script</a>.</p></li>
                   5537: 
                   5538:        <li><p><a href="browsers.html#pause">Pause</a> until the script has <a href="semantics.html#completed-loading">completed
                   5539:        loading</a>.</p></li>
                   5540: 
                   5541:        <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
                   5542:        <a href="#next-input-character">next input character</a>.</p></li>
                   5543: 
                   5544:        <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
                   5545:        by one (it should be zero before this step, so this sets it to
                   5546:        one).</p></li>
                   5547: 
                   5548:        <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute the
                   5549:        script</a>.</p></li>
                   5550: 
                   5551:        <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
                   5552:        by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
                   5553:        zero (which it always should be at this point), then set the
                   5554:        <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5555: 
                   5556:        </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
                   5557:        again.</p></li>
                   5558: 
                   5559:        <li><p>If there is once again a <a href="semantics.html#pending-external-script">pending external
                   5560:        script</a>, then repeat these steps from step 1.</p></li>
                   5561: 
                   5562:       </ol></dd>
                   5563: 
                   5564:     </dl></dd>
                   5565: 
                   5566:    <dt>Any other end tag</dt>
                   5567:    <dd>
                   5568: 
                   5569:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5570:     elements</a>.</p>
                   5571: 
                   5572:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5573:     insertion mode</a>.</p>
                   5574: 
                   5575:    </dd>
                   5576: 
                   5577:   </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>
                   5578: 
                   5579:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
                   5580:   mode: in table">in table</a>", tokens must be handled as follows:</p>
                   5581: 
                   5582:   <dl class="switch"><dt>A character token</dt>
                   5583:    <dd>
                   5584: 
                   5585:      <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
                   5586:      be an empty list of tokens.</p>
                   5587: 
                   5588:      <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   5589:      <a href="#insertion-mode">insertion mode</a>.</p>
                   5590: 
                   5591:      <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
                   5592:      reprocess the token.</p>
                   5593: 
                   5594:    </dd>
                   5595: 
                   5596:    <dt>A comment token</dt>
                   5597:    <dd>
                   5598:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   5599:     node</a> with the <code title="">data</code> attribute set to
                   5600:     the data given in the comment token.</p>
                   5601:    </dd>
                   5602: 
                   5603:    <dt>A DOCTYPE token</dt>
                   5604:    <dd>
                   5605:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5606:    </dd>
                   5607: 
                   5608:    <dt>A start tag whose tag name is "caption"</dt>
                   5609:    <dd>
                   5610: 
                   5611:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5612:     below.)</p>
                   5613: 
                   5614:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5615:     formatting elements</a>.</p>
                   5616: 
                   5617:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5618:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
                   5619: 
                   5620:    </dd>
                   5621: 
                   5622:    <dt>A start tag whose tag name is "colgroup"</dt>
                   5623:    <dd>
                   5624: 
                   5625:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5626:     below.)</p>
                   5627: 
                   5628:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5629:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
                   5630:     group</a>".</p>
                   5631: 
                   5632:    </dd>
                   5633: 
                   5634:    <dt>A start tag whose tag name is "col"</dt>
                   5635:    <dd>
                   5636:     <p>Act as if a start tag token with the tag name "colgroup"
                   5637:     had been seen, then reprocess the current token.</p>
                   5638:    </dd>
                   5639: 
                   5640:    <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
                   5641:    <dd>
                   5642: 
                   5643:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5644:     below.)</p>
                   5645: 
                   5646:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5647:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5648:     body</a>".</p>
                   5649: 
                   5650:    </dd>
                   5651: 
                   5652:    <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
                   5653:    <dd>
                   5654:     <p>Act as if a start tag token with the tag name "tbody" had
                   5655:     been seen, then reprocess the current token.</p>
                   5656:    </dd>
                   5657: 
                   5658:    <dt>A start tag whose tag name is "table"</dt>
                   5659:    <dd>
                   5660: 
                   5661:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
                   5662:     the tag name "table" had been seen, then, if that token wasn't
                   5663:     ignored, reprocess the current token.</p>
                   5664: 
                   5665:     <p class="note">The fake end tag token here can only be
                   5666:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5667: 
                   5668:    </dd>
                   5669: 
                   5670:    <dt>An end tag whose tag name is "table"</dt>
                   5671:    <dd>
                   5672: 
                   5673:     <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
                   5674:     scope</a> with the same tag name as the token, this is a
                   5675:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5676:     case</a>)</p>
                   5677: 
                   5678:     <p>Otherwise:</p>
                   5679: 
                   5680:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
                   5681:     element has been popped from the stack.</p>
                   5682: 
                   5683:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   5684: 
                   5685:    </dd>
                   5686: 
                   5687:    <dt>An end tag whose tag name is one of: "body", "caption",
                   5688:    "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
                   5689:    "thead", "tr"</dt>
                   5690:    <dd>
                   5691:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5692:    </dd>
                   5693: 
                   5694:    <dt>A start tag whose tag name is one of: "style", "script"</dt>
                   5695:    <dd>
                   5696: 
                   5697:     <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
                   5698:     mode</a>.</p>
                   5699: 
                   5700:    </dd>
                   5701: 
                   5702:    <dt>A start tag whose tag name is "input"</dt>
                   5703:    <dd>
                   5704: 
                   5705:     <p>If the token does not have an attribute with the name "type",
                   5706:     or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   5707:     case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
                   5708:     else" entry below.</p>
                   5709: 
                   5710:     <p>Otherwise:</p>
                   5711: 
                   5712:     <p><a href="#parse-error">Parse error</a>.</p>
                   5713: 
                   5714:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5715: 
                   5716:     <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
                   5717:     open elements</a>.</p>
                   5718: 
                   5719:    </dd>
                   5720: 
                   5721:    <dt>An end-of-file token</dt>
                   5722:    <dd>
                   5723: 
                   5724:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     5725:     <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1       mike     5726:     error</a>.</p>
                   5727: 
                   5728:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   5729:     the <a href="#fragment-case">fragment case</a>.</p>
                   5730: 
                   5731:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   5732: 
                   5733:    </dd>
                   5734: 
                   5735:    <dt>Anything else</dt>
                   5736:    <dd>
                   5737: 
                   5738:     <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
                   5739:     rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   5740:     body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
                   5741:     <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   5742:     <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
                   5743:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
                   5744:     into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
                   5745: 
                   5746:    </dd>
                   5747: 
                   5748:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
                   5749:   back to a table context</dfn>, it means that the UA must, while
                   5750:   the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-table-element">table</a></code>
1.159     mike     5751:   element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1       mike     5752:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   5753: 
                   5754:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     5755:   <code><a href="semantics.html#the-html-element-0">html</a></code> element after this process is a <a href="#fragment-case">fragment
1.1       mike     5756:   case</a>.</p>
                   5757: 
                   5758: 
                   5759: 
                   5760:   <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>
                   5761: 
                   5762:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
                   5763:   mode: in table text">in table text</a>", tokens must be handled
                   5764:   as follows:</p>
                   5765: 
                   5766:   <dl class="switch"><dt>A character token</dt>
                   5767:    <dd>
                   5768: 
                   5769:     <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
                   5770:     tokens</a></var> list.</p>
                   5771: 
                   5772:    </dd>
                   5773: 
                   5774: 
                   5775:    <dt>Anything else</dt>
                   5776:    <dd>
                   5777: 
                   5778:     <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
                   5779:     tokens</a></var> list are character tokens that are not one of U+0009
                   5780:     CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
                   5781:     (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
                   5782:     reprocess those character tokens using the rules given in the
                   5783:     "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
                   5784:     table">in table</a>" insertion mode.</p>
                   5785: 
                   5786:     <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
                   5787:     characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
                   5788:     tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
                   5789: 
                   5790:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5791:     insertion mode</a> and reprocess the token.</p>
                   5792: 
                   5793:    </dd>
                   5794: 
                   5795:   </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>
                   5796: 
                   5797:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
                   5798:   mode: in caption">in caption</a>", tokens must be handled as follows:</p>
                   5799: 
                   5800:   <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
                   5801:    <dd>
                   5802: 
                   5803:     <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
                   5804:     scope</a> with the same tag name as the token, this is a
                   5805:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5806:     case</a>)</p>
                   5807: 
                   5808:     <p>Otherwise:</p>
                   5809: 
                   5810:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   5811: 
                   5812:     <p>Now, if the <a href="#current-node">current node</a> is not a
                   5813:     <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
                   5814:     error</a>.</p>
                   5815: 
                   5816:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
                   5817:     element has been popped from the stack.</p>
                   5818: 
                   5819:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   5820:     the last marker</a>.</p>
                   5821: 
                   5822:     <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>
                   5823: 
                   5824:    </dd>
                   5825: 
                   5826:    <dt>A start tag whose tag name is one of: "caption", "col",
                   5827:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   5828:    <dt>An end tag whose tag name is "table"</dt>
                   5829:    <dd>
                   5830: 
                   5831:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   5832:     name "caption" had been seen, then, if that token wasn't
                   5833:     ignored, reprocess the current token.</p>
                   5834: 
                   5835:     <p class="note">The fake end tag token here can only be
                   5836:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5837: 
                   5838:    </dd>
                   5839: 
                   5840:    <dt>An end tag whose tag name is one of: "body", "col",
                   5841:    "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
                   5842:    "tr"</dt>
                   5843:    <dd>
                   5844:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5845:    </dd>
                   5846: 
                   5847:    <dt>Anything else</dt>
                   5848:    <dd>
                   5849:     <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
                   5850:     mode</a>.</p>
                   5851:    </dd>
                   5852: 
                   5853:   </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>
                   5854: 
                   5855:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
                   5856:   mode: in column group">in column group</a>", tokens must be handled as follows:</p>
                   5857: 
                   5858:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   5859:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   5860:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   5861:    <dd>
                   5862:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   5863:     the <a href="#current-node">current node</a>.</p>
                   5864:    </dd>
                   5865: 
                   5866:    <dt>A comment token</dt>
                   5867:    <dd>
                   5868:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   5869:     node</a> with the <code title="">data</code> attribute set to
                   5870:     the data given in the comment token.</p>
                   5871:    </dd>
                   5872: 
                   5873:    <dt>A DOCTYPE token</dt>
                   5874:    <dd>
                   5875:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5876:    </dd>
                   5877: 
                   5878:    <dt>A start tag whose tag name is "html"</dt>
                   5879:    <dd>
                   5880:     <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
                   5881:     mode</a>.</p>
                   5882:    </dd>
                   5883: 
                   5884:    <dt>A start tag whose tag name is "col"</dt>
                   5885:    <dd>
                   5886: 
                   5887:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5888:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5889:     elements</a>.</p>
                   5890: 
                   5891:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5892:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5893: 
                   5894:    </dd>
                   5895: 
                   5896:    <dt>An end tag whose tag name is "colgroup"</dt>
                   5897:    <dd>
                   5898: 
                   5899:     <p>If the <a href="#current-node">current node</a> is the root
1.159     mike     5900:     <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1       mike     5901:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   5902:     case</a>)</p>
                   5903: 
                   5904:     <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
                   5905:     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
                   5906:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   5907:     "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   5908: 
                   5909:    </dd>
                   5910: 
                   5911:    <dt>An end tag whose tag name is "col"</dt>
                   5912:    <dd>
                   5913:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5914:    </dd>
                   5915: 
                   5916:    <dt>An end-of-file token</dt>
                   5917:    <dd>
                   5918: 
1.159     mike     5919:     <p>If the <a href="#current-node">current node</a> is the root <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1       mike     5920:     element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
                   5921:     case</a>)</p>
                   5922: 
                   5923:     <p>Otherwise, act as described in the "anything else" entry
                   5924:     below.</p>
                   5925: 
                   5926:    </dd>
                   5927: 
                   5928:    <dt>Anything else</dt>
                   5929:    <dd>
                   5930: 
                   5931:     <p>Act as if an end tag with the tag name "colgroup" had been
                   5932:     seen, and then, if that token wasn't ignored, reprocess the
                   5933:     current token.</p>
                   5934: 
                   5935:     <p class="note">The fake end tag token here can only be
                   5936:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5937: 
                   5938:    </dd>
                   5939: 
                   5940:   </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>
                   5941: 
                   5942:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
                   5943:   mode: in table body">in table body</a>", tokens must be handled as follows:</p>
                   5944: 
                   5945:   <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
                   5946:    <dd>
                   5947: 
                   5948:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   5949:     context</a>. (See below.)</p>
                   5950: 
                   5951:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   5952:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
                   5953:     in row">in row</a>".</p>
                   5954: 
                   5955:    </dd>
                   5956: 
                   5957:    <dt>A start tag whose tag name is one of: "th", "td"</dt>
                   5958:    <dd>
                   5959:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
                   5960:     the tag name "tr" had been seen, then reprocess the current
                   5961:     token.</p>
                   5962:    </dd>
                   5963: 
                   5964:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   5965:    "thead"</dt>
                   5966:    <dd>
                   5967: 
                   5968:     <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
                   5969:     scope</a> with the same tag name as the token, this is a
                   5970:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   5971: 
                   5972:     <p>Otherwise:</p>
                   5973: 
                   5974:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   5975:     context</a>. (See below.)</p>
                   5976: 
                   5977:     <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
                   5978:     open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   5979:     to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   5980: 
                   5981:    </dd>
                   5982: 
                   5983:    <dt>A start tag whose tag name is one of: "caption", "col",
                   5984:    "colgroup", "tbody", "tfoot", "thead"</dt>
                   5985:    <dt>An end tag whose tag name is "table"</dt>
                   5986:    <dd>
                   5987: 
                   5988:     <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
                   5989:     <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
                   5990:     element in table scope</a>, this is a <a href="#parse-error">parse
                   5991:     error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5992:     case</a>)</p>
                   5993: 
                   5994:     <p>Otherwise:</p>
                   5995: 
                   5996:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   5997:     context</a>. (See below.)</p>
                   5998: 
                   5999:     <p>Act as if an end tag with the same tag name as the
                   6000:     <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
                   6001:     been seen, then reprocess the current token.</p>
                   6002: 
                   6003:    </dd>
                   6004: 
                   6005:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6006:    "col", "colgroup", "html", "td", "th", "tr"</dt>
                   6007:    <dd>
                   6008:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6009:    </dd>
                   6010: 
                   6011:    <dt>Anything else</dt>
                   6012:    <dd>
                   6013:     <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
                   6014:     mode</a>.</p>
                   6015:    </dd>
                   6016: 
                   6017:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
                   6018:   back to a table body context</dfn>, it means that the UA must,
                   6019:   while the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
1.159     mike     6020:   <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1       mike     6021:   element, pop elements from the <a href="#stack-of-open-elements">stack of open
                   6022:   elements</a>.</p>
                   6023: 
                   6024:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     6025:   <code><a href="semantics.html#the-html-element-0">html</a></code> element after this process is a <a href="#fragment-case">fragment
1.1       mike     6026:   case</a>.</p>
                   6027: 
                   6028: 
                   6029:   <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>
                   6030: 
                   6031:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   6032:   mode: in row">in row</a>", tokens must be handled as follows:</p>
                   6033: 
                   6034:   <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
                   6035:    <dd>
                   6036: 
                   6037:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   6038:     context</a>. (See below.)</p>
                   6039: 
                   6040:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   6041:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
                   6042:     in cell">in cell</a>".</p>
                   6043: 
                   6044:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   6045:     formatting elements</a>.</p>
                   6046: 
                   6047:    </dd>
                   6048: 
                   6049:    <dt>An end tag whose tag name is "tr"</dt>
                   6050:    <dd>
                   6051: 
                   6052:     <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
                   6053:     scope</a> with the same tag name as the token, this is a
                   6054:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6055:     case</a>)</p>
                   6056: 
                   6057:     <p>Otherwise:</p>
                   6058: 
                   6059:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   6060:     context</a>. (See below.)</p>
                   6061: 
                   6062:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   6063:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   6064:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   6065:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   6066:     body</a>".</p>
                   6067: 
                   6068:    </dd>
                   6069: 
                   6070:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6071:    "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
                   6072:    <dt>An end tag whose tag name is "table"</dt>
                   6073:    <dd>
                   6074: 
                   6075:     <p>Act as if an end tag with the tag name "tr" had been seen,
                   6076:     then, if that token wasn't ignored, reprocess the current
                   6077:     token.</p>
                   6078: 
                   6079:     <p class="note">The fake end tag token here can only be
                   6080:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6081: 
                   6082:    </dd>
                   6083: 
                   6084:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   6085:    "thead"</dt>
                   6086:    <dd>
                   6087: 
                   6088:     <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
                   6089:     scope</a> with the same tag name as the token, this is a
                   6090:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   6091: 
                   6092:     <p>Otherwise, act as if an end tag with the tag name "tr" had
                   6093:     been seen, then reprocess the current token.</p>
                   6094: 
                   6095:    </dd>
                   6096: 
                   6097:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6098:    "col", "colgroup", "html", "td", "th"</dt>
                   6099:    <dd>
                   6100:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6101:    </dd>
                   6102: 
                   6103:    <dt>Anything else</dt>
                   6104:    <dd>
                   6105:     <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
                   6106:     mode</a>.</p>
                   6107:    </dd>
                   6108: 
                   6109:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
                   6110:   back to a table row context</dfn>, it means that the UA must,
                   6111:   while the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tr-element">tr</a></code>
1.159     mike     6112:   element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1       mike     6113:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6114: 
                   6115:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     6116:   <code><a href="semantics.html#the-html-element-0">html</a></code> element after this process is a <a href="#fragment-case">fragment
1.1       mike     6117:   case</a>.</p>
                   6118: 
                   6119: 
                   6120:   <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>
                   6121: 
                   6122:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
                   6123:   mode: in cell">in cell</a>", tokens must be handled as follows:</p>
                   6124: 
                   6125:   <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
                   6126:    <dd>
                   6127: 
                   6128:     <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
                   6129:     scope</a> with the same tag name as that of the token, then
                   6130:     this is a <a href="#parse-error">parse error</a> and the token must be
                   6131:     ignored.</p>
                   6132: 
                   6133:     <p>Otherwise:</p>
                   6134: 
                   6135:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   6136: 
                   6137:     <p>Now, if the <a href="#current-node">current node</a> is not an element
                   6138:     with the same tag name as the token, then this is a
                   6139:     <a href="#parse-error">parse error</a>.</p>
                   6140: 
                   6141:     <p>Pop elements from this stack until an element with the same
                   6142:     tag name as the token has been popped from the stack.</p>
                   6143: 
                   6144:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   6145:     the last marker</a>.</p>
                   6146: 
                   6147:     <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
                   6148:     <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
                   6149:     this point.)</p>
                   6150: 
                   6151:    </dd>
                   6152: 
                   6153:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6154:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   6155:    <dd>
                   6156: 
                   6157:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
                   6158:     <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
                   6159:     a <code>td</code> or <code>th</code> element in table
                   6160:     scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
                   6161:     the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6162: 
                   6163:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6164:     reprocess the current token.</p>
                   6165: 
                   6166:    </dd>
                   6167: 
                   6168:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6169:    "col", "colgroup", "html"</dt>
                   6170:    <dd>
                   6171:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6172:    </dd>
                   6173: 
                   6174:    <dt>An end tag whose tag name is one of: "table", "tbody",
                   6175:    "tfoot", "thead", "tr"</dt>
                   6176:    <dd>
                   6177: 
                   6178:     <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
                   6179:     scope</a> with the same tag name as that of the token
                   6180:     (which can only happen for "tbody", "tfoot" and "thead", or,
                   6181:     in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
                   6182:     error</a> and the token must be ignored.</p>
                   6183: 
                   6184:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6185:     reprocess the current token.</p>
                   6186: 
                   6187:    </dd>
                   6188: 
                   6189:    <dt>Anything else</dt>
                   6190:    <dd>
                   6191:     <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
                   6192:     mode</a>.</p>
                   6193:    </dd>
                   6194: 
                   6195:   </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
                   6196:   mean to run the following algorithm:</p>
                   6197: 
                   6198:   <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>
                   6199:    element in table scope</a>, then act as if an end tag token
                   6200:    with the tag name "td" had been seen.</p></li>
                   6201: 
                   6202:    <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
                   6203:    <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
                   6204:    <code>th</code> element in table scope</a>; act as if an end
                   6205:    tag token with the tag name "th" had been seen.</p></li>
                   6206: 
                   6207:   </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
                   6208:   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
                   6209:   the same time, nor can it have neither when the <a href="#insertion-mode">insertion
                   6210:   mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   6211:   cell</a>".</p>
                   6212: 
                   6213: 
                   6214:   <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>
                   6215: 
                   6216:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
                   6217:   mode: in select">in select</a>", tokens must be handled as follows:</p>
                   6218: 
                   6219:   <dl class="switch"><dt>A character token</dt>
                   6220:    <dd>
                   6221:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6222:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6223:    </dd>
                   6224: 
                   6225:    <dt>A comment token</dt>
                   6226:    <dd>
                   6227:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6228:     node</a> with the <code title="">data</code> attribute set to
                   6229:     the data given in the comment token.</p>
                   6230:    </dd>
                   6231: 
                   6232:    <dt>A DOCTYPE token</dt>
                   6233:    <dd>
                   6234:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6235:    </dd>
                   6236: 
                   6237:    <dt>A start tag whose tag name is "html"</dt>
                   6238:    <dd>
                   6239:     <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
                   6240:     mode</a>.</p>
                   6241:    </dd>
                   6242: 
                   6243:    <dt>A start tag whose tag name is "option"</dt>
                   6244:    <dd>
                   6245: 
                   6246:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6247:     element, act as if an end tag with the tag name "option" had
                   6248:     been seen.</p>
                   6249: 
                   6250:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6251: 
                   6252:    </dd>
                   6253: 
                   6254:    <dt>A start tag whose tag name is "optgroup"</dt>
                   6255:    <dd>
                   6256: 
                   6257:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6258:     element, act as if an end tag with the tag name "option" had
                   6259:     been seen.</p>
                   6260: 
                   6261:     <p>If the <a href="#current-node">current node</a> is an
                   6262:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
                   6263:     tag name "optgroup" had been seen.</p>
                   6264: 
                   6265:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6266: 
                   6267:    </dd>
                   6268: 
                   6269:    <dt>An end tag whose tag name is "optgroup"</dt>
                   6270:    <dd>
                   6271: 
                   6272:     <p>First, if the <a href="#current-node">current node</a> is an
                   6273:     <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
                   6274:     it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
                   6275:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
                   6276:     the tag name "option" had been seen.</p>
                   6277: 
                   6278:     <p>If the <a href="#current-node">current node</a> is an
                   6279:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
                   6280:     <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
                   6281:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   6282: 
                   6283:    </dd>
                   6284: 
                   6285:    <dt>An end tag whose tag name is "option"</dt>
                   6286:    <dd>
                   6287: 
                   6288:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6289:     element, then pop that node from the <a href="#stack-of-open-elements">stack of open
                   6290:     elements</a>. Otherwise, this is a <a href="#parse-error">parse
                   6291:     error</a>; ignore the token.</p>
                   6292: 
                   6293:    </dd>
                   6294: 
                   6295:    <dt>An end tag whose tag name is "select"</dt>
                   6296:    <dd>
                   6297: 
                   6298:     <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
                   6299:     scope</a> with the same tag name as the token, this is a
                   6300:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6301:     case</a>)</p>
                   6302: 
                   6303:     <p>Otherwise:</p>
                   6304: 
                   6305:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   6306:     until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
                   6307:     stack.</p>
                   6308: 
                   6309:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   6310: 
                   6311:    </dd>
                   6312: 
                   6313:    <dt>A start tag whose tag name is "select"</dt>
                   6314:    <dd>
                   6315: 
                   6316:     <p><a href="#parse-error">Parse error</a>. Act as if the token had been
                   6317:     an end tag with the tag name "select" instead.</p>
                   6318: 
                   6319:    </dd>
                   6320: 
                   6321:    <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
                   6322:    <dd>
1.73      mike     6323: 
                   6324:     <p><a href="#parse-error">Parse error</a>.</p>
                   6325: 
1.124     mike     6326:     <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>
                   6327:     element in table scope</a>, ignore the token. (<a href="#fragment-case">fragment
                   6328:     case</a>)</p>
1.73      mike     6329: 
                   6330:     <p>Otherwise, act as if an end tag with the tag name "select" had
                   6331:     been seen, and reprocess the token.</p>
                   6332: 
1.1       mike     6333:    </dd>
                   6334: 
                   6335:    <dt>A start tag token whose tag name is "script"</dt>
                   6336:    <dd>
                   6337:     <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
                   6338:     mode</a>.</p>
                   6339:    </dd>
                   6340: 
                   6341:    <dt>An end-of-file token</dt>
                   6342:    <dd>
                   6343: 
                   6344:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     6345:     <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1       mike     6346:     error</a>.</p>
                   6347: 
                   6348:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6349:     the <a href="#fragment-case">fragment case</a>.</p>
                   6350: 
                   6351:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6352: 
                   6353:    </dd>
                   6354: 
                   6355:    <dt>Anything else</dt>
                   6356:    <dd>
                   6357:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6358:    </dd>
                   6359: 
                   6360:   </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>
                   6361: 
                   6362:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
                   6363:   mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
                   6364: 
                   6365:   <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
                   6366:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6367:    <dd>
                   6368:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   6369:     name "select" had been seen, and reprocess the token.</p>
                   6370:    </dd>
                   6371: 
                   6372:    <dt>An end tag whose tag name is one of: "caption", "table",
                   6373:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6374:    <dd>
                   6375: 
                   6376:     <p><a href="#parse-error">Parse error</a>.</p>
                   6377: 
                   6378:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
                   6379:     element in table scope</a> with the same tag name as that
                   6380:     of the token, then act as if an end tag with the tag name
                   6381:     "select" had been seen, and reprocess the token. Otherwise,
                   6382:     ignore the token.</p>
                   6383: 
                   6384:    </dd>
                   6385: 
                   6386:    <dt>Anything else</dt>
                   6387:    <dd>
                   6388:     <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
                   6389:     mode</a>.</p>
                   6390:    </dd>
                   6391: 
1.168     mike     6392:   </dl><h5 id="parsing-main-inforeign"><span class="secno">9.2.5.21 </span>The "<dfn title="insertion mode: in foreign content">in foreign content</dfn>" insertion mode</h5>
1.1       mike     6393: 
                   6394:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
                   6395:   mode: in foreign content">in foreign content</a>", tokens must be
                   6396:   handled as follows:</p>
                   6397: 
                   6398:   <dl class="switch"><dt>A character token</dt>
                   6399:    <dd>
                   6400: 
                   6401:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6402:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6403: 
                   6404:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   6405:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   6406:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   6407:     flag</a> to "not ok".</p>
                   6408: 
                   6409:    </dd>
                   6410: 
                   6411:    <dt>A comment token</dt>
                   6412:    <dd>
                   6413:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6414:     node</a> with the <code title="">data</code> attribute set to
                   6415:     the data given in the comment token.</p>
                   6416:    </dd>
                   6417: 
                   6418:    <dt>A DOCTYPE token</dt>
                   6419:    <dd>
                   6420:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6421:    </dd>
                   6422: 
                   6423:    <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>
                   6424:    <dd>
                   6425: 
                   6426:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6427:     elements</a>.</p>
                   6428: 
                   6429:     <p>Let the <var title="">old insertion point</var> have the
                   6430:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   6431:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   6432:     input character</a>.</p>
                   6433: 
                   6434:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6435:     one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
                   6436: 
                   6437:     <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
                   6438:     the <code title="">script</code> element</a> according to the SVG
1.187     mike     6439:     rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
1.1       mike     6440: 
1.159     mike     6441:     <p class="note">Even if this causes <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters to be inserted into the
1.1       mike     6442:     tokenizer</a>, the parser will not be executed reentrantly,
                   6443:     since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
                   6444: 
                   6445:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6446:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   6447:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   6448: 
                   6449:     <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
                   6450:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   6451:     might be the "undefined" value.)</p>
                   6452: 
                   6453:    </dd>
                   6454: 
                   6455:    <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>
                   6456:    <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>
                   6457:    <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>
                   6458:    <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>
                   6459:    <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>
                   6460:    <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>
                   6461:    <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>
                   6462:    <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>
                   6463:    <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>
                   6464:    <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>
                   6465:    <dt>An end tag</dt>
                   6466:    <dd>
                   6467: 
                   6468:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
                   6469:     <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6470: 
                   6471:     <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
                   6472:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   6473:     content</a>", but there is no element in scope that has a
                   6474:     namespace other than the <a href="#html-namespace-0">HTML namespace</a><!-- XXX this
                   6475:     isn't well-defined; it means check to see if the bottom-most HTML
                   6476:     element on the stack is in scope -->, switch the <a href="#insertion-mode">insertion
                   6477:     mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6478: 
                   6479:    </dd>
                   6480: 
                   6481:    <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
                   6482:    "blockquote", "body"<!--by inspection-->, "br", "center", "code",
                   6483:    "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
                   6484:    uniformly throughout the parser -->, "em", "embed", "h1", "h2",
                   6485:    "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
                   6486:    completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
                   6487:    "li", "listing"<!-- so that pre and listing can be handled
                   6488:    uniformly throughout the parser -->, "menu", "meta", "nobr",
                   6489:    "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
                   6490:    the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
                   6491:    "span", "strong", "strike"<!-- so that s and strike can be handled
                   6492:    uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
                   6493:    "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt>
                   6494:    <!-- this list was determined empirically by studying over
                   6495:    6,000,000,000 pages that were specifically not XML pages -->
                   6496:    <dt>A start tag whose tag name is "font", if the token has
                   6497:    any attributes named "color", "face", or "size"</dt>
                   6498:    <!-- the attributes here are required so that SVG <font> will go
                   6499:    through as SVG but legacy <font>s won't -->
                   6500:    <dt>An end-of-file token</dt>
                   6501:    <dd>
                   6502: 
                   6503:     <p><a href="#parse-error">Parse error</a>.</p>
                   6504: 
                   6505:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
                   6506:     the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
                   6507:     namespace</a>.</p>
                   6508: 
                   6509:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
                   6510:     insertion mode</a>, and reprocess the token.</p>
                   6511: 
                   6512:    </dd>
                   6513: 
                   6514:    <dt>Any other start tag</dt>
                   6515:    <dd>
                   6516: 
                   6517:     <p>If the <a href="#current-node">current node</a> is an element in the
                   6518:     <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
                   6519:     attributes</a> for the token. (This fixes the case of MathML
                   6520:     attributes that are not all lowercase.)</p>
                   6521: 
                   6522:     <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6523:     namespace</a>, and the token's tag name is one of the ones in
                   6524:     the first column of the following table, change the tag name to
                   6525:     the name given in the corresponding cell in the second
                   6526:     column. (This fixes the case of SVG elements that are not all
                   6527:     lowercase.)</p>
                   6528: 
                   6529:     <table><thead><tr><th> Tag name </th><th> Element name
                   6530:      </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
                   6531:       </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
                   6532:       </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
                   6533:       </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
                   6534:       </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
                   6535:       </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
                   6536:       </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
                   6537:       </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
                   6538:       </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
                   6539:       </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
                   6540:       </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
                   6541:       </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
                   6542:       </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
                   6543:       </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
                   6544:       </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
                   6545:       </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
                   6546:       </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
                   6547:       </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
                   6548:       </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
                   6549:       </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
                   6550:       </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
                   6551:       </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
                   6552:       </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
                   6553:       </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
                   6554:       </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
                   6555:       </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
                   6556:       </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
                   6557:       </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
                   6558:       </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
                   6559:       </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
                   6560:       </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
                   6561:       </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
                   6562:       </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   6563:       </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
                   6564:       </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
                   6565:       <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
                   6566:       </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
                   6567:     </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6568:     namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
                   6569:     token. (This fixes the case of SVG attributes that are not all
                   6570:     lowercase.)</p>
                   6571: 
                   6572:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   6573:     fixes the use of namespaced attributes, in particular XLink in
                   6574:     SVG.)</p>
                   6575: 
                   6576:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   6577:     same namespace as the <a href="#current-node">current node</a>.</p>
                   6578: 
                   6579:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   6580:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6581:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   6582:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   6583: 
                   6584:    </dd>
                   6585: 
                   6586:   </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>
                   6587: 
                   6588:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
                   6589:   mode: after body">after body</a>", tokens must be handled as follows:</p>
                   6590: 
                   6591:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6592:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6593:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6594:    <dd>
                   6595:     <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
                   6596:     mode</a>.</p>
                   6597:    </dd>
                   6598: 
                   6599:    <dt>A comment token</dt>
                   6600:    <dd>
                   6601:     <p>Append a <code>Comment</code> node to the first element in
1.159     mike     6602:     the <a href="#stack-of-open-elements">stack of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1       mike     6603:     element), with the <code title="">data</code> attribute set to
                   6604:     the data given in the comment token.</p>
                   6605:    </dd>
                   6606: 
                   6607:    <dt>A DOCTYPE token</dt>
                   6608:    <dd>
                   6609:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6610:    </dd>
                   6611: 
                   6612:    <dt>A start tag whose tag name is "html"</dt>
                   6613:    <dd>
                   6614:     <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
                   6615:     mode</a>.</p>
                   6616:    </dd>
                   6617: 
                   6618:    <dt>An end tag whose tag name is "html"</dt>
                   6619:    <dd>
                   6620: 
                   6621:     <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
                   6622:     fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
                   6623:     error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6624: 
                   6625:     <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
                   6626:     body</a>".</p>
                   6627: 
                   6628:    </dd>
                   6629: 
                   6630:    <dt>An end-of-file token</dt>
                   6631:    <dd>
                   6632:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6633:    </dd>
                   6634: 
                   6635:    <dt>Anything else</dt>
                   6636:    <dd>
                   6637: 
                   6638:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
                   6639:     mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   6640:     body</a>" and reprocess the token.</p>
                   6641: 
                   6642:    </dd>
                   6643: 
                   6644:   </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>
                   6645: 
                   6646:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
                   6647:   mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
                   6648: 
                   6649:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6650:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6651:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6652:    <dd>
                   6653:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6654:     the <a href="#current-node">current node</a>.</p>
                   6655:    </dd>
                   6656: 
                   6657:    <dt>A comment token</dt>
                   6658:    <dd>
                   6659:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6660:     node</a> with the <code title="">data</code> attribute set to
                   6661:     the data given in the comment token.</p>
                   6662:    </dd>
                   6663: 
                   6664:    <dt>A DOCTYPE token</dt>
                   6665:    <dd>
                   6666:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6667:    </dd>
                   6668: 
                   6669:    <dt>A start tag whose tag name is "html"</dt>
                   6670:    <dd>
                   6671:     <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
                   6672:     mode</a>.</p>
                   6673:    </dd>
                   6674: 
                   6675:    <dt>A start tag whose tag name is "frameset"</dt>
                   6676:    <dd>
                   6677:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6678:    </dd>
                   6679: 
                   6680:    <dt>An end tag whose tag name is "frameset"</dt>
                   6681:    <dd>
                   6682: 
                   6683:     <p>If the <a href="#current-node">current node</a> is the root
1.159     mike     6684:     <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1       mike     6685:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   6686:     case</a>)</p>
                   6687: 
                   6688:     <p>Otherwise, pop the <a href="#current-node">current node</a> from the
                   6689:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6690: 
                   6691:     <p>If the parser was <em>not</em> originally created as part
                   6692:     of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
                   6693:     (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5       mike     6694:     node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1       mike     6695:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
                   6696:     frameset</a>".</p>
                   6697: 
                   6698:    </dd>
                   6699: 
                   6700:    <dt>A start tag whose tag name is "frame"</dt>
                   6701:    <dd>
                   6702: 
                   6703:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
                   6704:     Immediately pop the <a href="#current-node">current node</a> off the
                   6705:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6706: 
                   6707:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   6708:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   6709: 
                   6710:    </dd>
                   6711: 
                   6712:    <dt>A start tag whose tag name is "noframes"</dt>
                   6713:    <dd>
                   6714:     <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
                   6715:     mode</a>.</p>
                   6716:    </dd>
                   6717: 
                   6718:    <dt>An end-of-file token</dt>
                   6719:    <dd>
                   6720: 
                   6721:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     6722:     <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1       mike     6723:     error</a>.</p>
                   6724: 
                   6725:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6726:     the <a href="#fragment-case">fragment case</a>.</p>
                   6727: 
                   6728:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6729: 
                   6730:    </dd>
                   6731: 
                   6732:    <dt>Anything else</dt>
                   6733:    <dd>
                   6734:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6735:    </dd>
                   6736: 
                   6737:   </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>
                   6738: 
                   6739:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
                   6740:   mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
                   6741: 
                   6742:   <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
                   6743:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6744:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6745:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6746:    <dd>
                   6747:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6748:     the <a href="#current-node">current node</a>.</p>
                   6749:    </dd>
                   6750: 
                   6751:    <dt>A comment token</dt>
                   6752:    <dd>
                   6753:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6754:     node</a> with the <code title="">data</code> attribute set to
                   6755:     the data given in the comment token.</p>
                   6756:    </dd>
                   6757: 
                   6758:    <dt>A DOCTYPE token</dt>
                   6759:    <dd>
                   6760:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6761:    </dd>
                   6762: 
                   6763:    <dt>A start tag whose tag name is "html"</dt>
                   6764:    <dd>
                   6765:     <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
                   6766:     mode</a>.</p>
                   6767:    </dd>
                   6768: 
                   6769:    <dt>An end tag whose tag name is "html"</dt>
                   6770:    <dd>
                   6771:     <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
                   6772:     frameset</a>".</p>
                   6773:    </dd>
                   6774: 
                   6775:    <dt>A start tag whose tag name is "noframes"</dt>
                   6776:    <dd>
                   6777:     <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
                   6778:     mode</a>.</p>
                   6779:    </dd>
                   6780: 
                   6781:    <dt>An end-of-file token</dt>
                   6782:    <dd>
                   6783:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6784:    </dd>
                   6785: 
                   6786:    <dt>Anything else</dt>
                   6787:    <dd>
                   6788:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6789:    </dd>
                   6790: 
                   6791:   </dl><p class="XXX">This doesn't handle UAs that don't support
                   6792:   frames, or that do support frames but want to show the NOFRAMES
                   6793:   content. Supporting the former is easy; supporting the latter is
                   6794:   harder.</p>
                   6795: 
                   6796: 
                   6797:   <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>
                   6798: 
                   6799:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
                   6800:   mode: after after body">after after body</a>", tokens must be handled as follows:</p>
                   6801: 
                   6802:   <dl class="switch"><dt>A comment token</dt>
                   6803:    <dd>
                   6804:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   6805:     object with the <code title="">data</code> attribute set to the
                   6806:     data given in the comment token.</p>
                   6807:    </dd>
                   6808: 
                   6809:    <dt>A DOCTYPE token</dt>
                   6810:    <dt>A character token that is one of U+0009 CHARACTER
                   6811:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6812:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6813:    <dt>A start tag whose tag name is "html"</dt>
                   6814:    <dd>
                   6815:     <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
                   6816:     mode</a>.</p>
                   6817:    </dd>
                   6818: 
                   6819:    <dt>An end-of-file token</dt>
                   6820:    <dd>
                   6821:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6822:    </dd>
                   6823: 
                   6824:    <dt>Anything else</dt>
                   6825:    <dd>
                   6826:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   6827:     to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
                   6828:     reprocess the token.</p>
                   6829:    </dd>
                   6830: 
                   6831:   </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>
                   6832: 
                   6833:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
                   6834:   mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
                   6835: 
                   6836:   <dl class="switch"><dt>A comment token</dt>
                   6837:    <dd>
                   6838:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   6839:     object with the <code title="">data</code> attribute set to the
                   6840:     data given in the comment token.</p>
                   6841:    </dd>
                   6842: 
                   6843:    <dt>A DOCTYPE token</dt>
                   6844:    <dt>A character token that is one of U+0009 CHARACTER
                   6845:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6846:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6847:    <dt>A start tag whose tag name is "html"</dt>
                   6848:    <dd>
                   6849:     <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
                   6850:     mode</a>.</p>
                   6851:    </dd>
                   6852: 
                   6853:    <dt>An end-of-file token</dt>
                   6854:    <dd>
                   6855:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6856:    </dd>
                   6857: 
                   6858:    <dt>A start tag whose tag name is "noframes"</dt>
                   6859:    <dd>
                   6860:     <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
                   6861:     mode</a>.</p>
                   6862:    </dd>
                   6863: 
                   6864:    <dt>Anything else</dt>
                   6865:    <dd>
                   6866:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6867:    </dd>
                   6868: 
                   6869:   </dl><h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4>
                   6870: 
                   6871:   <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
                   6872:   the document, the user agent must follow the steps in this
                   6873:   section.</p>
                   6874: 
1.10      mike     6875:   <!-- this happens as part of one of the tasks that runs the parser -->
1.1       mike     6876: 
1.10      mike     6877:   <p>First, the user agent must set the <a href="dom.html#current-document-readiness">current document
                   6878:   readiness</a> to "interactive" and the <a href="#insertion-point">insertion
                   6879:   point</a> to undefined.</p>
                   6880: 
                   6881:   <p>Then, the user agent must then make a list of all the scripts
                   6882:   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
                   6883:   document has finished parsing</a>, the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that
                   6884:   will execute asynchronously</a>, and the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts
                   6885:   that will execute as soon as possible</a>. This is the <dfn id="list-of-scripts-pending-after-the-parser-stopped">list
                   6886:   of scripts pending after the parser stopped</dfn>.</p>
                   6887: 
                   6888:   <p>The rules for <a href="semantics.html#when-a-script-completes-loading">when a script completes loading</a> start
                   6889:   applying (script execution is no longer managed by the parser).</p>
1.1       mike     6890: 
                   6891:   <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
                   6892:   execute as soon as possible</a> have <a href="semantics.html#completed-loading">completed
                   6893:   loading</a>, or if the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that will execute
                   6894:   asynchronously</a> is not empty and the first script in that list
                   6895:   has <a href="semantics.html#completed-loading">completed loading</a>, then the user agent must act as
                   6896:   if those scripts just completed loading, following the rules given
                   6897:   for that in the <code><a href="semantics.html#script">script</a></code> element definition.</p>
                   6898: 
1.10      mike     6899:   <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
                   6900:   has finished parsing</a> is not empty, and the first item in this
                   6901:   list has already <a href="semantics.html#completed-loading">completed loading</a>, then the user agent
                   6902:   must act as if that script just finished loading.</p>
                   6903: 
                   6904:   <p class="note">By this point, there will be no scripts that have
                   6905:   loaded but have not yet been executed.</p>
                   6906: 
                   6907:   <hr><!-- async --><p>Once all the scripts on the <a href="#list-of-scripts-pending-after-the-parser-stopped">list of scripts pending after
                   6908:   the parser stopped</a> have <a href="semantics.html#completed-loading">completed loading</a> and
                   6909:   been <a href="semantics.html#executing-a-script-block" title="executing a script block">executed</a>, the
                   6910:   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
                   6911:   event</a> called <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
                   6912:   <code>Document</code>. (If the list is empty, this happens
                   6913:   immediately.)</p>
1.1       mike     6914: 
1.10      mike     6915:   <hr><!-- async --><p>Once everything that <dfn id="delay-the-load-event" title="delay the load event">delays the
1.1       mike     6916:   load event</dfn> of the document has completed, the user agent must
                   6917:   run the following steps:</p>
                   6918: 
                   6919:   <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
                   6920:    readiness</a> to "complete".</li>
                   6921: 
                   6922:    <li>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
                   6923:    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
                   6924:    simple event</a> called <code title="event-load"><a href="video.html#event-load">load</a></code> at
                   6925:    the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
                   6926:    its <code title="dom-event-target">target</code> set to the
                   6927:    <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
                   6928:    <code><a href="browsers.html#window">Window</a></code> object).</li>
                   6929: 
                   6930:    <li>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
                   6931:    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
                   6932:    <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
                   6933:    <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
                   6934:    current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
                   6935:    must bubble but not be cancelable and has no default action.</li>
                   6936: 
1.228     mike     6937:   </ol><p>The <a href="browsers.html#task-source">task source</a> for these <span title="concept-tasks">tasks</span> is the <a href="browsers.html#dom-manipulation-task-source">DOM manipulation
                   6938:   task source</a>.</p>
1.1       mike     6939: 
                   6940:   <!-- XXX make sure things "delay the load event", e.g. applet and
                   6941:   object element's frame contents -->
                   6942: 
                   6943:   <p class="XXX">delaying the load event for things like image
                   6944:   loads allows for intranet port scans (even without
                   6945:   javascript!). Should we really encode that into the spec?</p>
                   6946: 
                   6947: 
                   6948: <!--XXX need to handle
                   6949: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#2354
                   6950: 2354           // Don't open transient styles if it makes the stack deep, bug 58917.
                   6951: -->
                   6952: 
                   6953: <!--XXX
                   6954: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/nsHTMLTokenizer.cpp#749
                   6955: -->
                   6956: 
                   6957: <!--
                   6958: see also  CTextToken::ConsumeCharacterData()  for CDATA parsing?
                   6959: 
                   6960: 1212                      1  Here's a tricky case from bug 22596:  <h5><li><h5>
                   6961: 1213                         How do we know that the 2nd <h5> should close the <LI> rather than nest inside the <LI>?
                   6962: 1214                         (Afterall, the <h5> is a legal child of the <LI>).
                   6963: 1215
                   6964: 1216                         The way you know is that there is no root between the two, so the <h5> binds more
                   6965: 1217                         tightly to the 1st <h5> than to the <LI>.
                   6966: 1218                      2. Also, bug 6148 shows this case: <SPAN><DIV><SPAN>
                   6967: 1219                         From this case we learned not to execute this logic if the parent is a block.
                   6968: 1220
                   6969: 1221                      3. Fix for 26583
                   6970: 1222                         Ex. <A href=foo.html><B>foo<A href-bar.html>bar</A></B></A>  <- A legal HTML
                   6971: 1223                         In the above example clicking on "foo" or "bar" should link to
                   6972: 1224                         foo.html or bar.html respectively. That is, the inner <A> should be informed
                   6973: 1225                         about the presence of an open <A> above <B>..so that the inner <A> can close out
                   6974: 1226                         the outer <A>. The following code does it for us.
                   6975: 1227
                   6976: 1228                      4. Fix for 27865 [ similer to 22596 ]. Ex: <DL><DD><LI>one<DD><LI>two
                   6977:  - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1211
                   6978: 
                   6979: 815             // Here's a problem.  If theTag is legal in here, we don't move it
                   6980: 816             // out.  So if we're moving stuff out of here, the parent of theTag
                   6981: 817             // gets closed at this point.  But some things are legal
                   6982: 818             // _everywhere_ and hence would effectively close out misplaced
                   6983: 819             // content in tables.  This is undesirable, so treat them as
                   6984: 820             // illegal here so they'll be shipped out with their parents and
                   6985: 821             // siblings.  See bug 40855 for an explanation (that bug was for
                   6986: 822             // comments, but the same issues arise with whitespace, newlines,
                   6987: 823             // noscript, etc).  Script is special, though.  Shipping it out
                   6988: 824             // breaks document.write stuff.  See bug 243064.
                   6989:  - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#825
                   6990: 
                   6991: 
                   6992: 1326     /**************************************************************************************
                   6993: 1327      *
                   6994: 1328      * Now a little code to deal with bug #49687 (crash when layout stack gets too deep)
                   6995: 1329      * I've also opened this up to any container (not just inlines): re bug 55095
                   6996: 1330      * Improved to handle bug 55980 (infinite loop caused when DEPTH is exceeded and
                   6997: 1331      * </P> is encountered by itself (<P>) is continuously produced.
                   6998: 1332      *
                   6999: 1333      **************************************************************************************/
                   7000: 
                   7001: 1912               // Oh boy!! we found a "stray" tag. Nav4.x and IE introduce line break in
                   7002: 1913               // such cases. So, let's simulate that effect for compatibility.
                   7003: 1914               // Ex. <html><body>Hello</P>There</body></html>
                   7004: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1912
                   7005: 
                   7006: http://lxr.mozilla.org/seamonkey/search?string=nested
                   7007: /parser/htmlparser/src/CNavDTD.cpp, line 791 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
                   7008: /parser/htmlparser/src/CNavDTD.cpp, line 792 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
                   7009: /parser/htmlparser/src/CNavDTD.cpp, line 2562 - // Discard nested forms - bug 72639
                   7010: /parser/htmlparser/src/nsElementTable.cpp, line 1453 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
                   7011: /parser/htmlparser/src/nsElementTable.cpp, line 1454 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
                   7012: /parser/htmlparser/src/nsElementTable.cpp, line 1901 - // Ex: <H1><LI><H1><LI>. Inner LI has the potential of getting nested
                   7013: -->
                   7014: 
                   7015: 
                   7016:   <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4>
                   7017: 
                   7018:   <p>When an application uses an <a href="#html-parser">HTML parser</a> in
                   7019:   conjunction with an XML pipeline, it is possible that the
                   7020:   constructed DOM is not compatible with the XML tool chain in certain
                   7021:   subtle ways. For example, an XML toolchain might not be able to
                   7022:   represent attributes with the name <code title="">xmlns</code>,
                   7023:   since they conflict with the Namespaces in XML syntax. There is also
                   7024:   some data that the <a href="#html-parser">HTML parser</a> generates that isn't
                   7025:   included in the DOM itself. This section specifies some rules for
                   7026:   handling these issues.</p>
                   7027: 
                   7028:   <p>If the XML API being used doesn't support DOCTYPEs, the tool may
                   7029:   drop DOCTYPEs altogether.</p>
                   7030: 
                   7031:   <p>If the XML API doesn't support attributes in no namespace that
                   7032:   are named "<code title="">xmlns</code>", attributes whose names
                   7033:   start with "<code title="">xmlns:</code>", or attributes in the
                   7034:   <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
                   7035:   attributes.</p>
                   7036: 
                   7037:   <p>The tool may annotate the output with any namespace declarations
                   7038:   required for proper operation.</p>
                   7039: 
                   7040:   <p>If the XML API being used restricts the allowable characters in
                   7041:   the local names of elements and attributes, then the tool may map
                   7042:   all element and attribute local names that the API wouldn't support
                   7043:   to a set of names that <em>are</em> allowed, by replacing any
                   7044:   character that isn't supported with the uppercase letter U and the
                   7045:   six digits of the character's Unicode code point when expressed in
                   7046:   hexadecimal, using digits 0-9 and capital letters A-F as the
                   7047:   symbols, in increasing numeric order.</p>
                   7048: 
                   7049:   <p class="example">For example, the element name <code title="">foo&lt;bar</code>, which can be output by the <a href="#html-parser">HTML
                   7050:   parser</a>, though it is neither a legal HTML element name nor a
                   7051:   well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
                   7052:   element name (though it's still not legal in HTML by any means).</p>
                   7053: 
                   7054:   <p class="example">As another example, consider the attribute
                   7055:   <code>xlink:href</code>. Used on a MathML element, it becomes, after
                   7056:   being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
                   7057:   attribute with a prefix "<code title="">xlink</code>" and a local
                   7058:   name "<code title="">href</code>". However, used on an HTML element,
                   7059:   it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
                   7060:   might not be accepted by an XML API. It could thus get converted,
                   7061:   becoming "<code title="">xlinkU00003Ahref</code>".</p>
                   7062: 
                   7063:   <p class="note">The resulting names from this conversion
                   7064:   conveniently can't clash with any attribute generated by the
                   7065:   <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
                   7066:   those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
                   7067:   algorithm's table.</p>
                   7068: 
                   7069:   <p>If the XML API restricts comments from having two consecutive
                   7070:   U+002D HYPHEN-MINUS characters (--), the tool may insert a single
                   7071:   U+0020 SPACE character between any such offending characters.</p>
                   7072: 
                   7073:   <p>If the XML API restricts comments from ending in a
                   7074:   U+002D HYPHEN-MINUS character (-), the tool may insert a single
                   7075:   U+0020 SPACE character at the end of such comments.</p>
                   7076: 
                   7077:   <p>If the XML API restricts allowed characters in character data,
                   7078:   the tool may replace any U+000C FORM FEED (FF) character with a
                   7079:   U+0020 SPACE character, and any other literal non-XML character with
                   7080:   a U+FFFD REPLACEMENT CHARACTER.</p>
                   7081: 
                   7082:   <p>If the tool has no way to convey out-of-band information, then
                   7083:   the tool may drop the following information:</p>
                   7084: 
                   7085:   <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
                   7086:    <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>
                   7087: 
                   7088:    <li>The association between form controls and forms that aren't
                   7089:    their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
                   7090:    <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
                   7091: 
                   7092:   </ul><p class="note">The mutations allowed by this section apply
                   7093:   <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
                   7094:   applied. For example, a <code title="">&lt;a::&gt;</code> start tag
                   7095:   will be closed by a <code title="">&lt;/a::&gt;</code> end tag, and
                   7096:   never by a <code title="">&lt;/aU00003AU00003A&gt;</code> end tag, even
                   7097:   if the user agent is using the rules above to then generate an
                   7098:   actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
                   7099: 
                   7100: 
                   7101: 
1.35      mike     7102:   <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     7103: 
                   7104:   <p><i>This section is non-normative.</i></p>
                   7105: 
                   7106:   <p>This section examines some erroneous markup and discusses how
                   7107:   the <a href="#html-parser">HTML parser</a> handles these cases.</p>
                   7108: 
                   7109: 
                   7110:   <h5 id="misnested-tags:-b-i-b-i"><span class="secno">9.2.8.1 </span>Misnested tags: &lt;b&gt;&lt;i&gt;&lt;/b&gt;&lt;/i&gt;</h5>
                   7111: 
                   7112:   <p><i>This section is non-normative.</i></p>
                   7113: 
                   7114:   <p>The most-often discussed example of erroneous markup is as
                   7115:   follows:</p>
                   7116: 
                   7117:   <pre>&lt;p&gt;1&lt;b&gt;2&lt;i&gt;3&lt;/b&gt;4&lt;/i&gt;5&lt;/p&gt;</pre>
                   7118: 
                   7119:   <p>The parsing of this markup is straightforward up to the "3". At
                   7120:   this point, the DOM looks like this:</p>
                   7121: 
1.159     mike     7122:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>Here, the <a href="#stack-of-open-elements">stack of open elements</a> has five elements
                   7123:   on it: <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>,
1.1       mike     7124:   <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
                   7125:   formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
                   7126:   <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>
                   7127: 
                   7128:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
                   7129:   invoked. This is a simple case, in that the <var title="">formatting
                   7130:   element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
                   7131:   <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
1.159     mike     7132:   elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element-0">html</a></code>,
                   7133:   <code><a href="semantics.html#the-body-element-0">body</a></code>, and <code><a href="semantics.html#the-p-element">p</a></code>, while the <a href="#list-of-active-formatting-elements">list of
1.1       mike     7134:   active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
                   7135:   DOM tree is unmodified at this point.</p>
                   7136: 
                   7137:   <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
                   7138:   the active formatting elements</a>, in this case just the
                   7139:   <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
                   7140:   for the "4" text node. After the end tag token for the "i" is also
                   7141:   received, and the "5" text node is inserted, the DOM looks as
                   7142:   follows:</p>
                   7143: 
1.159     mike     7144:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">4</span></li></ul></li><li class="t3"><code>#text</code>: <span title="">5</span></li></ul></li></ul></li></ul></li></ul><h5 id="misnested-tags:-b-p-b-p"><span class="secno">9.2.8.2 </span>Misnested tags: &lt;b&gt;&lt;p&gt;&lt;/b&gt;&lt;/p&gt;</h5>
1.1       mike     7145: 
                   7146:   <p><i>This section is non-normative.</i></p>
                   7147: 
                   7148:   <p>A case similar to the previous one is the following:</p>
                   7149: 
                   7150:   <pre>&lt;b&gt;1&lt;p&gt;2&lt;/b&gt;3&lt;/p&gt;</pre>
                   7151: 
                   7152:   <p>Up to the "2" the parsing here is straightforward:</p>
                   7153: 
1.159     mike     7154:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>The interesting part is when the end tag token with the tag name
1.1       mike     7155:   "b" is parsed.</p>
                   7156: 
                   7157:   <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
1.159     mike     7158:   elements</a> has four elements on it: <code><a href="semantics.html#the-html-element-0">html</a></code>,
                   7159:   <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="text-level-semantics.html#the-b-element">b</a></code>, and <code><a href="semantics.html#the-p-element">p</a></code>. The
1.1       mike     7160:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
                   7161:   <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>
                   7162: 
                   7163:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
                   7164:   in the previous example. However, in this case, there <em>is</em> a
                   7165:   <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
                   7166:   this time the adoption agency algorithm isn't skipped over.</p>
                   7167: 
1.159     mike     7168:   <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1       mike     7169:   element. A conceptual "bookmark" marks the position of the
                   7170:   <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
                   7171:   elements</a>, but since that list has only one element in it,
                   7172:   it won't have much effect.</p>
                   7173: 
                   7174:   <p>As the algorithm progresses, <var title="">node</var> ends up set
                   7175:   to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
                   7176:   node</var> ends up set to the <var title="">furthest block</var>
                   7177:   (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7178: 
                   7179:   <p>The <var title="">last node</var> gets appended (moved) to the
                   7180:   <var title="">common ancestor</var>, so that the DOM looks like:</p>
                   7181: 
1.159     mike     7182:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul><p>A new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created, and the children of the
1.1       mike     7183:   <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
                   7184: 
1.159     mike     7185:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code></li></ul></li></ul></li></ul><ul class="domTree"><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul><p>Finally, the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is appended to the
1.1       mike     7186:   <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
                   7187: 
1.159     mike     7188:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>The <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is removed from the <a href="#list-of-active-formatting-elements">list of
1.1       mike     7189:   active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
                   7190:   elements</a>, so that when the "3" is parsed, it is appended to
                   7191:   the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
                   7192: 
1.159     mike     7193:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li></ul></li></ul><h5 id="unexpected-markup-in-tables"><span class="secno">9.2.8.3 </span>Unexpected markup in tables</h5>
1.1       mike     7194: 
                   7195:   <p><i>This section is non-normative.</i></p>
                   7196: 
                   7197:   <p>Error handling in tables is, for historical reasons, especially
                   7198:   strange. For example, consider the following markup:</p>
                   7199: 
                   7200:   <pre>&lt;table&gt;<strong>&lt;b&gt;</strong>&lt;tr&gt;&lt;td&gt;aaa&lt;/td&gt;&lt;/tr&gt;<strong>bbb</strong>&lt;/table&gt;ccc</pre>
                   7201: 
                   7202:   <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
                   7203:   directly inside a table like that, and the parser handles this case
                   7204:   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
                   7205:   examining the DOM tree as it stands just after the
                   7206:   <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
                   7207: 
1.159     mike     7208:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code></li></ul></li></ul></li></ul><p>...and then immediately after the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start
1.1       mike     7209:   tag has been seen:</p>
                   7210: 
1.159     mike     7211:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></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
                   7212:   the elements <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>,
1.1       mike     7213:   <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
                   7214:   resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
                   7215:   elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
                   7216:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
                   7217:   table">in table</a>".</p>
                   7218: 
                   7219:   <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
                   7220:   to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
                   7221:   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
                   7222:   then handled in a rather straight-forward manner, taking the parser
                   7223:   through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   7224:   body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   7225:   row</a>" insertion modes, after which the DOM looks as
                   7226:   follows:</p>
                   7227: 
1.159     mike     7228:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code></li></ul></li></ul></li></ul></li></ul></li></ul><p>Here, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
                   7229:   elements <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
1.1       mike     7230:   <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
                   7231:   formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
                   7232:   it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   7233:   mode: in row">in row</a>".</p>
                   7234: 
                   7235:   <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
                   7236:   <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
                   7237:   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
                   7238:   mode</a>).</p>
                   7239: 
1.159     mike     7240:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The marker means that when the "aaa" character tokens are seen,
1.1       mike     7241:   no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
                   7242:   node:</p>
                   7243: 
1.159     mike     7244:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The end tags are handled in a straight-forward manner; after
1.1       mike     7245:   handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
1.159     mike     7246:   elements <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
1.1       mike     7247:   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
                   7248:   elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
                   7249:   marker having been removed by the "td" end tag token); and the
                   7250:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
                   7251:   table body">in table body</a>".</p>
                   7252: 
                   7253:   <p>Thus it is that the "bbb" character tokens are found. These
                   7254:   trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
                   7255:   text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
                   7256:   insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
                   7257:   body">in table body</a>"). The character tokens are collected,
                   7258:   and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
                   7259:   seen, they are processed as a group. Since they are not all spaces,
                   7260:   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,
                   7261:   which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   7262:   body</a>" insertion mode but with <a href="#foster-parent" title="foster
                   7263:   parent">foster parenting</a>.</p>
                   7264: 
                   7265:   <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
                   7266:   active formatting elements are reconstructed</a>, a
                   7267:   <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
                   7268:   parent">foster parented</a>, and then the "bbb" text node is
                   7269:   appended to it:</p>
                   7270: 
1.159     mike     7271:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">bbb</span></li></ul></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The <a href="#stack-of-open-elements">stack of open elements</a> has on it the elements
                   7272:   <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
1.1       mike     7273:   <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
                   7274:   this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
                   7275:   formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
                   7276:   and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
                   7277:   mode: in table body">in table body</a>".</p>
                   7278: 
                   7279:   <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
                   7280:   character">space characters</a> instead of "bbb", then those
                   7281:   <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
                   7282:   appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
                   7283: 
                   7284:   <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
                   7285:   tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
                   7286:   elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   7287:   but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
                   7288:   elements</a>, so the "ccc" character tokens after the table
                   7289:   result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
                   7290:   time after the table:</p>
                   7291: 
1.159     mike     7292:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">bbb</span></li></ul></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">ccc</span></li></ul></li></ul></li></ul></li></ul><h5 id="scripts-that-modify-the-page-as-it-is-being-parsed"><span class="secno">9.2.8.4 </span>Scripts that modify the page as it is being parsed</h5>
1.1       mike     7293: 
                   7294:   <p><i>This section is non-normative.</i></p>
                   7295: 
                   7296:   <p>Consider the following markup, which for this example we will
                   7297:   assume is the document with <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/inner</code>, being rendered as the
1.159     mike     7298:   content of an <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code> in another document with the
1.1       mike     7299:   <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
                   7300: 
                   7301:   <pre>&lt;div id=a&gt;
                   7302:  &lt;script&gt;
                   7303:   var div = document.getElementById('a');
                   7304:   parent.document.body.appendChild(div);
                   7305:  &lt;/script&gt;
                   7306:  &lt;script&gt;
                   7307:   alert(document.URL);
                   7308:  &lt;/script&gt;
                   7309: &lt;/div&gt;
                   7310: &lt;script&gt;
                   7311:  alert(document.URL);
                   7312: &lt;/script&gt;</pre>
                   7313: 
                   7314:   <p>Up to the first "script" end tag, before the script is parsed,
                   7315:   the result is relatively straightforward:</p>
                   7316: 
1.159     mike     7317:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="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="">
1.1       mike     7318:  </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'); &#9166; 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
                   7319:   and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
                   7320: 
1.159     mike     7321:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code></li></ul></li></ul><p>They are, at this point, in the <code>Document</code> of the
1.1       mike     7322:   aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
                   7323:   <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
                   7324:   <code><a href="interactive-elements.html#the-div-element">div</a></code> element</em>.</p>
                   7325: 
                   7326:   <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
                   7327:   is inserted <em>into the outer <code>Document</code>
                   7328:   object</em>.</p>
                   7329: 
                   7330:   <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
                   7331:   the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
                   7332:   object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
1.159     mike     7333:   <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>.</p>
1.1       mike     7334: 
                   7335:   <p class="note">This isn't a security problem since the script that
                   7336:   moves the <code><a href="interactive-elements.html#the-div-element">div</a></code> into the outer <code>Document</code> can
                   7337:   only do so because they have the two <code>Document</code> object
1.159     mike     7338:   have the same <a href="browsers.html#origin">origin</a>.</p>
1.1       mike     7339: 
                   7340:   <p>Thus, the first alert says "http://example.com/outer".</p>
                   7341: 
                   7342:   <p>Once the <code><a href="interactive-elements.html#the-div-element">div</a></code> element's end tag is parsed, the
                   7343:   <code><a href="interactive-elements.html#the-div-element">div</a></code> element is popped off the stack, and so the next
                   7344:   <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
                   7345: 
1.159     mike     7346:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="semantics.html#script">script</a></code><ul><li class="t3"><code>#text</code>: <span title="">alert(document.URL);</span></li></ul></li></ul></li></ul></li></ul><p>This second alert will say "http://example.com/inner".</p>
1.1       mike     7347: 
                   7348: 
                   7349: 
1.215     mike     7350:   <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3>
1.1       mike     7351: 
                   7352:   <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
                   7353: 
                   7354:   <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
                   7355: 
                   7356:   <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
                   7357: 
                   7358:   <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
                   7359: 
                   7360:   <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
                   7361: 
                   7362:   <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
                   7363: 
                   7364:   <hr><p>Data mining tools and other user agents that perform operations
1.83      mike     7365:   on <code><a href="iana-considerations.html#text-html">text/html</a></code> content without running scripts,
1.1       mike     7366:   evaluating CSS or XPath expressions, or otherwise exposing the
                   7367:   resulting DOM to arbitrary content, may "support namespaces" by just
                   7368:   asserting that their DOM node analogues are in certain namespaces,
                   7369:   without actually exposing the above strings.</p>
                   7370: 
                   7371: 
                   7372: 
                   7373: 
                   7374:   <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3>
                   7375: 
                   7376:   <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
                   7377:   algorithm</dfn>. The algorithm takes as input a DOM
                   7378:   <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
                   7379:   exception.</p>
                   7380: 
                   7381:   <p class="note">This algorithm serializes the <em>children</em> of
                   7382:   the node being serialized, not the node itself.</p>
                   7383: 
                   7384:   <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
                   7385:    the empty string.</p></li>
                   7386: 
                   7387:    <li>
                   7388: 
                   7389:     <p>For each child node of <var title="">the node</var>, in
                   7390:     <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
                   7391: 
                   7392:     </p><ol><li><p>Let <var title="">current node</var> be the child node
                   7393:      being processed.</p></li>
                   7394: 
                   7395:      <li>
                   7396: 
                   7397:       <p>Append the appropriate string from the following list to
                   7398:       <var title="">s</var>:</p>
                   7399: 
                   7400:       <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
                   7401: 
                   7402:        <dd>
                   7403: 
                   7404:         <p>Append a U+003C LESS-THAN SIGN (<code title="">&lt;</code>)
                   7405:         character, followed by the element's tag name. (For nodes
                   7406:         created by the <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
                   7407:         lowercase.)</p>
                   7408: 
                   7409:         <p>For each attribute that the element has, append a U+0020
                   7410:         SPACE character, the attribute's name (which, for attributes
                   7411:         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
                   7412:         U+003D EQUALS SIGN (<code title="">=</code>) character, a
                   7413:         U+0022 QUOTATION MARK (<code title="">"</code>)
                   7414:         character, the attribute's value, <a href="#escapingString" title="escaping a
                   7415:         string">escaped as described below</a> in <i>attribute
                   7416:         mode</i>, and a second U+0022 QUOTATION MARK (<code title="">"</code>) character.</p>
                   7417: 
                   7418:         <p>While the exact order of attributes is UA-defined, and may
                   7419:         depend on factors such as the order that the attributes were
                   7420:         given in the original markup, the sort order must be stable,
                   7421:         such that consecutive invocations of this algorithm serialize an
                   7422:         element's attributes in the same order.</p>
                   7423: 
                   7424:         <p>Append a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>)
                   7425:         character.</p>
                   7426: 
                   7427:         <p>If <var title="">current node</var> is an
1.5       mike     7428:         <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     7429:         <code>bgsound</code>, <code><a href="semantics.html#the-br-element">br</a></code>, <code><a href="tabular-data.html#the-col-element">col</a></code>,
1.159     mike     7430:         <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>, <code><a href="obsolete.html#frame">frame</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>,
                   7431:         <code><a href="text-level-semantics.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="forms.html#the-keygen-element">keygen</a></code>,
                   7432:         <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#meta">meta</a></code>, <code><a href="text-level-semantics.html#the-param-element">param</a></code>,
1.5       mike     7433:         <code><a href="obsolete.html#spacer">spacer</a></code>, or <code>wbr</code> element, then
1.1       mike     7434:         continue on to the next child node at this point.</p> <!--
                   7435:         also, i guess: image and isindex, but we don't list those
                   7436:         because we don't consider those "elements", more "macros", and
                   7437:         thus we should never serialize them -->
                   7438: 
                   7439:         <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42      mike     7440:         <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     7441:         a U+000A LINE FEED (LF) character.</p>
                   7442: 
                   7443:         <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
                   7444:         serialization algorithm</a> on the <var title="">current
                   7445:         node</var> element (thus recursing into this algorithm for
                   7446:         that element), followed by a U+003C LESS-THAN SIGN (<code title="">&lt;</code>) character, a U+002F SOLIDUS (<code title="">/</code>) character, the element's tag name again,
                   7447:         and finally a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>) character.</p>
                   7448: 
                   7449:        </dd>
                   7450: 
                   7451: 
                   7452:        <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
                   7453:        node</dt>
                   7454: 
                   7455:        <dd>
                   7456: 
1.19      mike     7457:         <p>If the parent of <var title="">current node</var> is a
1.42      mike     7458:         <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="semantics.html#script">script</a></code>, <code><a href="obsolete.html#xmp">xmp</a></code>,
1.159     mike     7459:         <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>,
1.222     mike     7460:         <code><a href="obsolete.html#noframes">noframes</a></code>, or <code><a href="obsolete.html#plaintext">plaintext</a></code> element, or
                   7461:         if the parent of <var title="">current node</var> is
                   7462:         <code><a href="semantics.html#the-noscript-element">noscript</a></code> element and <a href="browsers.html#concept-n-script" title="concept-n-script">scripting is enabled</a> for the
                   7463:         node, then append the value of <var title="">current
                   7464:         node</var>'s <code title="">data</code> IDL attribute
                   7465:         literally.</p>
1.1       mike     7466: 
                   7467:         <p>Otherwise, append the value of <var title="">current
1.192     mike     7468:         node</var>'s <code title="">data</code> IDL attribute, <a href="#escapingString" title="escaping a string">escaped as described
1.1       mike     7469:         below</a>.</p>
                   7470: 
                   7471:        </dd>
                   7472: 
                   7473: 
                   7474:        <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
                   7475: 
                   7476:        <dd>
                   7477: 
                   7478:         <p>Append the literal string <code>&lt;!--</code> (U+003C
                   7479:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
1.192     mike     7480:         U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1       mike     7481:         attribute, followed by the literal string <code>--&gt;</code>
                   7482:         (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
                   7483:         SIGN).</p>
                   7484: 
                   7485:        </dd>
                   7486: 
                   7487: 
                   7488:        <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
                   7489: 
                   7490:        <dd>
                   7491: 
                   7492:         <p>Append the literal string <code>&lt;?</code> (U+003C
                   7493:         LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
1.192     mike     7494:         of <var title="">current node</var>'s <code title="">target</code> IDL attribute, followed by a single
                   7495:         U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1       mike     7496:         attribute, followed by a single U+003E GREATER-THAN SIGN
                   7497:         character ('&gt;').</p>
                   7498: 
                   7499:        </dd>
                   7500: 
                   7501: 
                   7502:        <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
                   7503: 
                   7504:        <dd>
                   7505: 
                   7506:         <p>Append the literal string <code>&lt;!DOCTYPE</code> (U+003C
                   7507:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
                   7508:         LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
                   7509:         LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
                   7510:         LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
                   7511:         LETTER E), followed by a space (U+0020 SPACE), followed by the
1.192     mike     7512:         value of <var title="">current node</var>'s <code title="">name</code> IDL attribute, followed by the literal
1.1       mike     7513:         string <code>&gt;</code> (U+003E GREATER-THAN SIGN).</p>
                   7514: 
                   7515:        </dd>
                   7516: 
                   7517: 
                   7518:       </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
                   7519:       occur as children of elements. If, despite this, they somehow do
                   7520:       occur, this algorithm must raise an
                   7521:       <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
                   7522: 
                   7523:      </li>
                   7524: 
                   7525:     </ol></li>
                   7526: 
                   7527:    <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
                   7528: 
                   7529:   </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
                   7530:   purposes of the algorithm above) consists of replacing any
                   7531:   occurrences of the "<code title="">&amp;</code>" character by the
                   7532:   string "<code title="">&amp;amp;</code>", any occurrences of the
                   7533:   U+00A0 NO-BREAK SPACE character by the string "<code title="">&amp;nbsp;</code>", and, if the algorithm was invoked in
                   7534:   the <i>attribute mode</i>, any occurrences of the "<code title="">"</code>" character by the string "<code title="">&amp;quot;</code>", or if it was not, any occurrences of
                   7535:   the "<code title="">&lt;</code>" character by the string "<code title="">&amp;lt;</code>", any occurrences of the "<code title="">&gt;</code>" character by the string "<code title="">&amp;gt;</code>".</p>
                   7536: 
                   7537:   <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
                   7538:   agent, and are therefore not covered in the algorithm above.</p>
                   7539: 
                   7540:   <p class="note">It is possible that the output of this algorithm, if
                   7541:   parsed with an <a href="#html-parser">HTML parser</a>, will not return the
                   7542:   original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
                   7543:   element to which a <code title="">Comment</code> node has been
                   7544:   appended is serialized and the output is then reparsed, the comment
                   7545:   will end up being displayed in the text field. Similarly, if, as a
                   7546:   result of DOM manipulation, an element contains a comment that
                   7547:   contains the literal string "<code title="">--&gt;</code>", then
                   7548:   when the result of serializing the element is parsed, the comment
                   7549:   will be truncated at that point and the rest of the comment will be
                   7550:   interpreted as markup. More examples would be making a
                   7551:   <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
                   7552:   "<code>&lt;/script&gt;</code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
                   7553:   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
                   7554:   <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
                   7555:   tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7556: 
                   7557: 
                   7558:   <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3>
                   7559: 
                   7560:   <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
                   7561:   algorithm</dfn>. The algorithm optionally takes as input an
                   7562:   <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
                   7563:   parser, as well as <var title="">input</var>, a string to parse, and
                   7564:   returns a list of zero or more nodes.</p>
                   7565: 
                   7566:   <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
                   7567:   in the parser section are parts that only occur if the parser was
                   7568:   created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
                   7569:   with such markings for informational purposes only; such markings
                   7570:   have no normative weight. If it is possible for a condition
                   7571:   described as a <a href="#fragment-case">fragment case</a> to occur even when the
                   7572:   parser wasn't created for the purposes of handling this algorithm,
                   7573:   then that is an error in the specification.</p>
                   7574: 
                   7575:   <ol><li>
                   7576: 
                   7577:     <p>Create a new <code>Document</code> node, and mark it as being
                   7578:     an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                   7579: 
                   7580:    </li>
                   7581: 
                   7582:    <li>
                   7583: 
                   7584:     <p>If there is a <var title="">context</var> element, and the
                   7585:     <code>Document</code> of the <var title="">context</var> element
                   7586:     is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
                   7587:     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
                   7588:     the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
                   7589:     mode</a>, then let the <code>Document</code> be in
                   7590:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
                   7591:     <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
                   7592: 
                   7593:    </li>
                   7594: 
                   7595:    <li>
                   7596: 
                   7597:     <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
                   7598:     the just created <code>Document</code> node.</p>
                   7599: 
                   7600:    </li>
                   7601: 
                   7602:    <li>
                   7603: 
                   7604:     <p>If there is a <var title="">context</var> element, run these
                   7605:     substeps:</p>
                   7606: 
                   7607:     <ol><li>
                   7608: 
                   7609:       <p>Set the <a href="#html-parser">HTML parser</a>'s <a href="#tokenization">tokenization</a>
                   7610:       stage's <a href="#content-model-flag">content model flag</a> according to the <var title="">context</var> element, as follows:</p>
                   7611: 
1.159     mike     7612:       <dl class="switch"><dt>If it is a <code><a href="semantics.html#the-title-element-0">title</a></code> or <code><a href="forms.html#the-textarea-element">textarea</a></code>
1.1       mike     7613:        element</dt>
                   7614: 
                   7615:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7616:        the RCDATA state.</dd>
                   7617: 
                   7618: 
                   7619:        <dt>If it is a <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="semantics.html#script">script</a></code>,
1.159     mike     7620:        <code><a href="obsolete.html#xmp">xmp</a></code>, <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>, or
1.5       mike     7621:        <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1       mike     7622: 
                   7623:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
1.91      mike     7624:        the RAWTEXT state.</dd>
1.1       mike     7625: 
                   7626: 
                   7627:        <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
                   7628: 
                   7629:        <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, set the
1.91      mike     7630:        <a href="#content-model-flag">content model flag</a> to the RAWTEXT
1.1       mike     7631:        state. Otherwise, set the <a href="#content-model-flag">content model flag</a> to the
                   7632:        PCDATA state.</dd>
                   7633: 
                   7634: 
1.42      mike     7635:        <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1       mike     7636: 
                   7637:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7638:        PLAINTEXT.</dd>
                   7639: 
                   7640: 
                   7641:        <dt>Otherwise</dt>
                   7642: 
                   7643:        <dd>Leave the <a href="#content-model-flag">content model flag</a> in the PCDATA
                   7644:        state.</dd>
                   7645: 
                   7646:       </dl></li>
                   7647: 
                   7648:      <li>
                   7649: 
1.159     mike     7650:       <p>Let <var title="">root</var> be a new <code><a href="semantics.html#the-html-element-0">html</a></code> element
1.1       mike     7651:       with no attributes.</p>
                   7652: 
                   7653:      </li>
                   7654: 
                   7655:      <li>
                   7656: 
                   7657:       <p>Append the element <var title="">root</var> to the
                   7658:       <code>Document</code> node created above.</p>
                   7659: 
                   7660:      </li>
                   7661: 
                   7662:      <li>
                   7663: 
                   7664:       <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
                   7665:       it contains just the single element <var title="">root</var>.</p>
                   7666: 
                   7667:      </li>
                   7668: 
                   7669:      <li>
                   7670: 
                   7671:       <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
                   7672:       parser's insertion mode appropriately</a>.</p>
                   7673: 
                   7674:       <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
                   7675: 
                   7676:      </li>
                   7677: 
                   7678:      <li>
                   7679: 
                   7680:       <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
                   7681:       to the nearest node to the <var title="">context</var> element
                   7682:       that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
                   7683:       ancestor chain, and including the element itself, if it is a
                   7684:       <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
                   7685:       <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
                   7686: 
                   7687:      </li>
                   7688: 
                   7689:     </ol></li>
                   7690: 
                   7691:    <li>
                   7692: 
                   7693:     <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
                   7694:     parser</a> just created the <var title="">input</var>. The
                   7695:     encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   7696:     <i>irrelevant</i>.</p>
                   7697: 
                   7698:    </li>
                   7699: 
                   7700:    <li>
                   7701: 
                   7702:     <p>Start the parser and let it run until it has consumed all the
                   7703:     characters just inserted into the input stream.</p>
                   7704: 
                   7705:    </li>
                   7706: 
                   7707:    <li>
                   7708: 
                   7709:     <p>If there is a <var title="">context</var> element, return the
                   7710:     child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
                   7711:     order</a>.</p>
                   7712: 
                   7713:     <p>Otherwise, return the children of the <code>Document</code>
                   7714:     object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
                   7715: 
                   7716:    </li>
                   7717: 
1.123     mike     7718:   </ol></div></body></html>

Webmaster