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

1.2       mike        1: <!DOCTYPE HTML>
1.12      mike        2: <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; }
                    100:    .note { color: green; background: transparent; font-family: sans-serif; }
                    101:    .warning { color: red; background: transparent; }
                    102:    .note, .warning { font-weight: bolder; font-style: italic; }
                    103:    p.note, div.note { padding: 0.5em 2em; }
                    104:    span.note { padding: 0 2em; }
                    105:    .note p:first-child, .warning p:first-child { margin-top: 0; }
                    106:    .note p:last-child, .warning p:last-child { margin-bottom: 0; }
                    107:    .warning:before { font-style: normal; }
                    108:    p.note:before { content: 'Note: '; }
                    109:    p.warning:before { content: '\26A0 Warning! '; }
                    110: 
                    111:    .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
                    112:    .bookkeeping { font-size: 0.8em; margin: 2em 0; }
                    113:    .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
                    114: 
                    115:    h4 { position: relative; z-index: 3; }
                    116:    h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
                    117:    .element {
                    118:      background: #EEEEFF;
                    119:      color: black;
                    120:      margin: 0 0 1em 0.15em;
                    121:      padding: 0 1em 0.25em 0.75em;
                    122:      border-left: solid #9999FF 0.25em;
                    123:      position: relative;
                    124:      z-index: 1;
                    125:    }
                    126:    .element:before {
                    127:      position: absolute;
                    128:      z-index: 2;
                    129:      top: 0;
                    130:      left: -1.15em;
                    131:      height: 2em;
                    132:      width: 0.9em;
                    133:      background: #EEEEFF;
                    134:      content: ' ';
                    135:      border-style: none none solid solid;
                    136:      border-color: #9999FF;
                    137:      border-width: 0.25em;
                    138:    }
                    139: 
                    140:    .example {
                    141:      display: block;
                    142:      color: #222222;
                    143:      background: #FCFCFC;
                    144:      border-left: double;
                    145:      margin-left: 2em;
                    146:      padding-left: 1em;
                    147:    }
                    148: 
                    149:    .tall-and-narrow {
                    150:      font-size: 0.6em;
                    151:      column-width: 25em;
                    152:      column-gap: 1em;
                    153:      -moz-column-width: 25em;
                    154:      -moz-column-gap: 1em;
                    155:      -webkit-column-width: 25em;
                    156:      -webkit-column-gap: 1em;
                    157:    }
                    158: 
                    159:    ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
                    160:    ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
                    161:    ul.domTree li li { list-style: none; }
                    162:    ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    163:    ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    164:    ul.domTree span { font-style: italic; font-family: serif; }
                    165:    ul.domTree .t1 code { color: purple; font-weight: bold; }
                    166:    ul.domTree .t2 { font-style: normal; font-family: monospace; }
                    167:    ul.domTree .t2 .name { color: black; font-weight: bold; }
                    168:    ul.domTree .t2 .value { color: blue; font-weight: normal; }
                    169:    ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
                    170:    ul.domTree .t7 code, .domTree .t8 code { color: green; }
                    171:    ul.domTree .t10 code { color: teal; }
                    172: 
1.2       mike      173:   </style><link href="data:text/css," rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D" rel="alternate stylesheet" title="Highlight implementation requirements"><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css"><!-- ZZZ ED vs WD -->
                    174:   <script src="link-fixup.js"></script>
                    175:   <link href="comms.html" title="8 Communication" rel="prev">
                    176:   <link href="spec.html#contents" title="Table of contents" rel="index">
1.1       mike      177:   <link href="named-character-references.html" title="9.6 Named character references" rel="next">
1.16      mike      178:   </head><body onload="fixBrokenLink(); fixBrokenLink()"><div class="head">
1.1       mike      179:    <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
1.4       mike      180:    <h1>HTML 5</h1>
1.1       mike      181:    <h2 class="no-num no-toc" id="a-vocabulary-and-associated-apis-for-html-and-xhtml">A vocabulary and associated APIs for HTML and XHTML</h2>
1.97      mike      182:    </div>
                    183: 
                    184:   <nav>
1.1       mike      185:    <a href="comms.html">&#8592; 8 Communication</a> &#8211;
1.2       mike      186:    <a href="spec.html#contents">Table of contents</a> &#8211;
1.1       mike      187:    <a href="named-character-references.html">9.6 Named character references &#8594;</a>
1.100   ! mike      188:   </nav><p>This is revision 1.2767.</p>
1.97      mike      189: 
1.11      mike      190: 
1.97      mike      191:   <h2 id="syntax"><span class="secno">9 </span><dfn>The HTML syntax</dfn></h2>
1.1       mike      192: 
1.97      mike      193:   <p class="note">This section only describes the rules for
1.83      mike      194:   <code><a href="iana-considerations.html#text-html">text/html</a></code> resources. Rules for XML resources are
1.1       mike      195:   discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.97      mike      196:   syntax</a>".</p>
                    197: 
                    198: 
                    199:   <h3 id="writing"><span class="secno">9.1 </span>Writing HTML documents</h3>
                    200: 
                    201:   <div class="impl">
1.1       mike      202: 
                    203:   <p><i>This section only applies to documents, authoring tools, and
                    204:   markup generators. In particular, it does not apply to conformance
                    205:   checkers; conformance checkers must use the requirements given in
                    206:   the next section ("parsing HTML documents").</i></p>
                    207: 
1.97      mike      208:   </div>
                    209: 
                    210:   <p>Documents must consist of the following parts, in the given
                    211:   order:</p>
                    212: 
                    213:   <ol><li>Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.</li>
1.1       mike      214: 
                    215:    <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    216:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    217: 
                    218:    <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
                    219: 
                    220:    </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    221:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    222: 
                    223:    <li>The root element, in the form of an <code><a href="semantics.html#the-html-element">html</a></code> <a href="#syntax-elements" title="syntax-elements">element</a>.</li>
                    224: 
                    225:    <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    226:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    227: 
                    228:   </ol><p>The various types of content mentioned above are described in the
1.97      mike      229:   next few sections.</p>
                    230: 
                    231:   <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      232:   declarations</a> are to be serialized, as discussed in the
1.97      mike      233:   section on that topic.</p>
                    234: 
                    235:   <div class="note">
1.1       mike      236: 
                    237:    <p>Space characters before the root <code><a href="semantics.html#the-html-element">html</a></code> element, and
                    238:    space characters at the start of the <code><a href="semantics.html#the-html-element">html</a></code> element and
                    239:    before the <code><a href="semantics.html#the-head-element">head</a></code> element, will be dropped when the
                    240:    document is parsed; space characters <em>after</em> the root
                    241:    <code><a href="semantics.html#the-html-element">html</a></code> element will be parsed as if they were at the end
                    242:    of the <code><a href="semantics.html#the-body-element">body</a></code> element. Thus, space characters around the
                    243:    root element do not round-trip.</p>
                    244: 
                    245:    <p>It is suggested that newlines be inserted after the DOCTYPE,
                    246:    after any comments that are before the root element, after the
                    247:    <code><a href="semantics.html#the-html-element">html</a></code> element's start tag (if it is not <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>), and after any comments
                    248:    that are inside the <code><a href="semantics.html#the-html-element">html</a></code> element but before the
                    249:    <code><a href="semantics.html#the-head-element">head</a></code> element.</p>
                    250: 
1.97      mike      251:   </div>
                    252: 
                    253:   <p>Many strings in the HTML syntax (e.g. the names of elements and
1.1       mike      254:   their attributes) are case-insensitive, but only for characters in
                    255:   the ranges U+0041 .. U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
                    256:   LETTER Z) and U+0061 .. U+007A (LATIN SMALL LETTER A to LATIN SMALL
                    257:   LETTER Z). For convenience, in this section this is just referred to
1.97      mike      258:   as "case-insensitive".</p>
                    259: 
                    260: 
                    261:   <h4 id="the-doctype"><span class="secno">9.1.1 </span>The DOCTYPE</h4>
                    262: 
                    263:   <p>A <dfn id="syntax-doctype" title="syntax-doctype">DOCTYPE</dfn> is a mostly useless,
                    264:   but required, header.</p>
                    265: 
                    266:   <p class="note">DOCTYPEs are required for legacy reasons. When
1.1       mike      267:   omitted, browsers tend to use a different rendering mode that is
                    268:   incompatible with some specifications. Including the DOCTYPE in a
                    269:   document ensures that the browser makes a best-effort attempt at
1.97      mike      270:   following the relevant specifications.</p>
                    271: 
                    272:   <p>A DOCTYPE must consist of the following characters, in this
                    273:   order:</p>
                    274: 
                    275:   <ol class="brief"><li>A U+003C LESS-THAN SIGN (<code>&lt;</code>) character.</li>
1.1       mike      276:    <li>A U+0021 EXCLAMATION MARK (<code>!</code>) character.</li>
                    277:    <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>
                    278:    <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    279:    <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>
                    280:    <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> (defined below).</li>
                    281:    <li>Zero or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    282:    <li>A U+003E GREATER-THAN SIGN (<code>&gt;</code>) character.</li>
                    283:   </ol><p class="note">In other words, <code>&lt;!DOCTYPE HTML&gt;</code>,
1.97      mike      284:   case-insensitively.</p>
                    285: 
                    286:   <p>For the purposes of HTML generators that cannot output HTML
1.1       mike      287:   markup with the short DOCTYPE "<code title="">&lt;!DOCTYPE
                    288:   HTML&gt;</code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
                    289:   into the DOCTYPE (in the position defined above). This string must
1.97      mike      290:   consist of:</p>
                    291: 
                    292:   <ol class="brief"><li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.1       mike      293:    <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>
                    294:    <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    295:    <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
                    296:    <li>The literal string "<code title="">about:legacy-compat</code>".</li>
                    297:    <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>
                    298:   </ol><p class="note">In other words, <code>&lt;!DOCTYPE HTML SYSTEM
                    299:   "about:legacy-compat"&gt;</code> or <code>&lt;!DOCTYPE HTML SYSTEM
                    300:   'about:legacy-compat'&gt;</code>, case-insensitively except for the bit
1.97      mike      301:   in quotes.</p>
                    302: 
                    303:   <p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1       mike      304:   the document is generated from a system that cannot output the
1.97      mike      305:   shorter string.</p>
                    306: 
                    307: 
                    308: 
                    309:   <h4 id="elements-0"><span class="secno">9.1.2 </span>Elements</h4>
                    310: 
                    311:   <p>There are five different kinds of <dfn id="syntax-elements" title="syntax-elements">elements</dfn>: void elements, raw text
1.1       mike      312:   elements, RCDATA elements, foreign elements, and normal
1.97      mike      313:   elements.</p>
                    314: 
                    315:   <dl><dt><dfn id="void-elements">Void elements</dfn></dt>
1.1       mike      316: 
                    317:    <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>,
                    318:    <code><a href="tabular-data.html#the-col-element">col</a></code>, <code><a href="interactive-elements.html#the-command">command</a></code>, <code><a href="embedded-content-0.html#the-embed-element">embed</a></code>,
                    319:    <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="embedded-content-0.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>,
                    320:    <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>,
                    321:    <code><a href="embedded-content-0.html#the-param-element">param</a></code>, <code><a href="video.html#the-source-element">source</a></code></dd>
                    322: 
1.91      mike      323:    <dt>Raw text elements</dt>
1.1       mike      324: 
                    325:    <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      326:    noscript don't count as raw text for syntax purposes -->
1.1       mike      327: 
                    328:    <dt>RCDATA elements</dt>
                    329: 
                    330:    <dd><code><a href="forms.html#the-textarea-element">textarea</a></code>, <code><a href="semantics.html#the-title-element">title</a></code></dd>
                    331: 
                    332:    <dt>Foreign elements</dt>
                    333: 
                    334:    <dd>Elements from the <a href="#mathml-namespace">MathML namespace</a>
                    335:    and the <a href="#svg-namespace">SVG namespace</a>.</dd>
                    336: 
                    337:    <dt>Normal elements</dt>
                    338: 
                    339:    <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
                    340:    elements.</dd>
                    341: 
                    342:   </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.91      mike      343:   and end of elements in the markup. Raw text, RCDATA, and normal
1.1       mike      344:   elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to
                    345:   indicate where they begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end
                    346:   tag</a> to indicate where they end. The start and end tags of
                    347:   certain normal elements can be <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>, as described
                    348:   later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
                    349:   elements</a> only have a start tag; end tags must not be
                    350:   specified for void elements. Foreign elements must either have a
                    351:   start tag and an end tag, or a start tag that is marked as
1.97      mike      352:   self-closing, in which case they must not have an end tag.</p>
                    353: 
                    354:   <p>The contents of the element must be placed between just after the
1.1       mike      355:   start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
                    356:   in certain cases</a>) and just before the end tag (which again,
                    357:   <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
                    358:   cases</a>). The exact allowed contents of each individual element
                    359:   depends on the content model of that element, as described earlier
                    360:   in this specification. Elements must not contain content that their
                    361:   content model disallows. In addition to the restrictions placed on
                    362:   the contents by those content models, however, the five types of
1.97      mike      363:   elements have additional <em>syntactic</em> requirements.</p>
                    364: 
                    365:   <p><a href="#void-elements">Void elements</a> can't have any contents (since there's
1.1       mike      366:   no end tag, no content can be put between the start tag and the end
1.97      mike      367:   tag).</p>
                    368: 
                    369:   <p>Raw text elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1       mike      370:   though it has <a href="#cdata-rcdata-restrictions">restrictions</a>
1.97      mike      371:   described below.</p>
                    372: 
                    373:   <p>RCDATA elements can have <a href="#syntax-text" title="syntax-text">text</a>
1.1       mike      374:   and <a href="#syntax-charref" title="syntax-charref">character references</a>, but
                    375:   the text must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
                    376:   There are also <a href="#cdata-rcdata-restrictions">further
1.97      mike      377:   restrictions</a> described below.</p>
                    378: 
                    379:   <p>Foreign elements whose start tag is marked as self-closing can't
1.1       mike      380:   have any contents (since, again, as there's no end tag, no content
                    381:   can be put between the start tag and the end tag). Foreign elements
                    382:   whose start tag is <em>not</em> marked as self-closing can have
                    383:   <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
                    384:   contain the character U+003C LESS-THAN SIGN (<code>&lt;</code>) or
                    385:   an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.97      mike      386:   ampersand</a>.</p>
                    387: 
                    388:   <p>Normal elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1       mike      389:   <a href="#syntax-charref" title="syntax-charref">character references</a>, other
                    390:   <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
                    391:   contain the character U+003C LESS-THAN SIGN (<code>&lt;</code>) or
                    392:   an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
                    393:   ampersand</a>. Some normal elements also have <a href="#element-restrictions">yet more restrictions</a> on what
                    394:   content they are allowed to hold, beyond the restrictions imposed by
                    395:   the content model and those described in this paragraph. Those
1.97      mike      396:   restrictions are described below.</p>
                    397: 
                    398:   <p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1       mike      399:   giving the element's name. HTML elements all have names that only
                    400:   use characters in the range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE,
                    401:   U+0061 LATIN SMALL LETTER A .. U+007A LATIN SMALL LETTER Z, U+0041
                    402:   LATIN CAPITAL LETTER A .. U+005A LATIN CAPITAL LETTER Z, and U+002D
                    403:   HYPHEN-MINUS (<code>-</code>). In the HTML syntax, tag names may be
                    404:   written with any mix of lower- and uppercase letters that, when
                    405:   converted to all-lowercase, matches the element's tag name; tag
1.97      mike      406:   names are case-insensitive.</p>
                    407: 
                    408: 
                    409:   <h5 id="start-tags"><span class="secno">9.1.2.1 </span>Start tags</h5>
                    410: 
                    411:   <p><dfn id="syntax-start-tag" title="syntax-start-tag">Start tags</dfn> must have the
                    412:   following format:</p>
                    413: 
                    414:   <ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.1       mike      415:    SIGN (<code>&lt;</code>).</li>
                    416: 
                    417:    <li>The next few characters of a start tag must be the element's
                    418:    <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
                    419: 
                    420:    <li>If there are to be any attributes in the next step, there must
                    421:    first be one or more <a href="infrastructure.html#space-character" title="space character">space
                    422:    characters</a>.</li>
                    423: 
                    424:    <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
                    425:    below. Attributes may be separated from each other by one or more
                    426:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    427: 
                    428:    <li>After the attributes, there may be one or more <a href="infrastructure.html#space-character" title="space character">space characters</a>. (Some attributes
                    429:    are required to be followed by a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes section</a> below.)</li>
                    430: 
                    431:    <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
                    432:    or if the element is a foreign element, then there may be a single
                    433:    U+002F SOLIDUS (<code>/</code>) character. This character has no
                    434:    effect on void elements, but on foreign elements it marks the start
                    435:    tag as self-closing.</li>
                    436: 
                    437:    <li>Finally, start tags must be closed by a U+003E GREATER-THAN
                    438:    SIGN (<code>&gt;</code>) character.</li>
                    439: 
1.97      mike      440:   </ol><h5 id="end-tags"><span class="secno">9.1.2.2 </span>End tags</h5>
                    441: 
                    442:   <p><dfn id="syntax-end-tag" title="syntax-end-tag">End tags</dfn> must have the
                    443:   following format:</p>
                    444: 
                    445:   <ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.1       mike      446:    SIGN (<code>&lt;</code>).</li>
                    447: 
                    448:    <li>The second character of an end tag must be a U+002F SOLIDUS
                    449:    (<code>/</code>).</li>
                    450: 
                    451:    <li>The next few characters of an end tag must be the element's
                    452:    <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
                    453: 
                    454:    <li>After the tag name, there may be one or more <a href="infrastructure.html#space-character" title="space
                    455:    character">space characters</a>.</li>
                    456: 
                    457:    <li>Finally, end tags must be closed by a U+003E GREATER-THAN
                    458:    SIGN (<code>&gt;</code>) character.</li>
                    459: 
1.97      mike      460:   </ol><h5 id="attributes"><span class="secno">9.1.2.3 </span>Attributes</h5>
                    461: 
                    462:   <p><dfn id="syntax-attributes" title="syntax-attributes">Attributes</dfn> for an element
                    463:   are expressed inside the element's start tag.</p>
                    464: 
                    465:   <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      466:   one or more characters other than the <a href="infrastructure.html#space-character" title="space
                    467:   character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
                    468:   MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
                    469:   (&gt;), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters,
                    470:   the control characters, and any characters that are not defined by
                    471:   Unicode. In the HTML syntax, attribute names may be written with any
                    472:   mix of lower- and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.97      mike      473:   case-insensitive</a> match for the attribute's name.</p>
                    474: 
                    475:   <p><dfn id="syntax-attribute-value" title="syntax-attribute-value">Attribute values</dfn> are a
1.1       mike      476:   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.97      mike      477:   additional restriction that the text cannot contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.</p>
                    478: 
                    479:   <p>Attributes can be specified in four different ways:</p>
                    480: 
                    481:   <dl><dt>Empty attribute syntax</dt>
1.1       mike      482: 
                    483:    <dd>
                    484: 
                    485:     <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
                    486:     name</a>.</p>
                    487: 
                    488:     <div class="example">
                    489: 
                    490:      <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
                    491:      the empty attribute syntax:</p>
                    492: 
                    493:      <pre>&lt;input <em>disabled</em>&gt;</pre>
                    494: 
                    495:     </div>
                    496: 
                    497:     <p>If an attribute using the empty attribute syntax is to be
                    498:     followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    499:     character</a> separating the two.</p>
                    500: 
                    501:    </dd>
                    502: 
1.2       mike      503:    <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1       mike      504: 
                    505:    <dd>
                    506: 
                    507:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    508:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    509:     characters</a>, followed by a single U+003D EQUALS SIGN
                    510:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    511:     character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    512:     addition to the requirements given above for attribute values,
                    513:     must not contain any literal <a href="infrastructure.html#space-character" title="space character">space
                    514:     characters</a>, any U+0022 QUOTATION MARK (<code>"</code>)
                    515:     characters, U+0027 APOSTROPHE (<code>'</code>) characters,
                    516:     U+003D EQUALS SIGN (<code>=</code>) characters, U+003C LESS-THAN
                    517:     SIGN (<code>&lt;</code>) characters, or U+003E GREATER-THAN SIGN
                    518:     (<code>&gt;</code>) characters, and must not be the empty
                    519:     string.</p>
                    520: 
                    521:     <div class="example">
                    522: 
                    523:      <p>In the following example, the <code title="attr-input-value"><a href="forms.html#attr-input-value">value</a></code> attribute is given
                    524:      with the unquoted attribute value syntax:</p>
                    525: 
                    526:      <pre>&lt;input <em>value=yes</em>&gt;</pre>
                    527: 
                    528:     </div>
                    529: 
                    530:     <p>If an attribute using the unquoted attribute syntax is to be
                    531:     followed by another attribute or by one of the optional U+002F
                    532:     SOLIDUS (<code>/</code>) characters allowed in step 6 of the <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> syntax above, then there
                    533:     must be a <a href="infrastructure.html#space-character">space character</a> separating the two.</p>
                    534: 
                    535:    </dd>
                    536: 
                    537:    <dt>Single-quoted attribute value syntax</dt>
                    538: 
                    539:    <dd>
                    540: 
                    541:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    542:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    543:     characters</a>, followed by a single U+003D EQUALS SIGN
                    544:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    545:     character">space characters</a>, followed by a single U+0027
                    546:     APOSTROPHE (<code>'</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    547:     addition to the requirements given above for attribute values,
                    548:     must not contain any literal U+0027 APOSTROPHE (<code>'</code>)
                    549:     characters, and finally followed by a second single U+0027
                    550:     APOSTROPHE (<code>'</code>) character.</p>
                    551: 
                    552:     <div class="example">
                    553: 
                    554:      <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
                    555:      single-quoted attribute value syntax:</p>
                    556: 
                    557:      <pre>&lt;input <em>type='checkbox'</em>&gt;</pre>
                    558: 
                    559:     </div>
                    560: 
                    561:     <p>If an attribute using the single-quoted attribute syntax is to
                    562:     be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    563:     character</a> separating the two.</p>
                    564: 
                    565:    </dd>
                    566: 
                    567:    <dt>Double-quoted attribute value syntax</dt>
                    568: 
                    569:    <dd>
                    570: 
                    571:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    572:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    573:     characters</a>, followed by a single U+003D EQUALS SIGN
                    574:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    575:     character">space characters</a>, followed by a single U+0022
                    576:     QUOTATION MARK (<code>"</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    577:     addition to the requirements given above for attribute values,
                    578:     must not contain any literal U+0022 QUOTATION MARK
                    579:     (<code>"</code>) characters, and finally followed by a second
                    580:     single U+0022 QUOTATION MARK (<code>"</code>) character.</p>
                    581: 
                    582:     <div class="example">
                    583: 
                    584:      <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
                    585:      double-quoted attribute value syntax:</p>
                    586: 
                    587:      <pre>&lt;input <em>name="be evil"</em>&gt;</pre>
                    588: 
                    589:     </div>
                    590: 
                    591:     <p>If an attribute using the double-quoted attribute syntax is to
                    592:     be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    593:     character</a> separating the two.</p>
                    594: 
                    595:    </dd>
                    596: 
                    597:   </dl><p>There must never be two or more attributes on the same start tag
                    598:   whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.97      mike      599:   each other.</p>
                    600: 
                    601: 
                    602:   <h5 id="optional-tags"><span class="secno">9.1.2.4 </span>Optional tags</h5>
                    603: 
                    604:   <p>Certain tags can be <dfn id="syntax-tag-omission" title="syntax-tag-omission">omitted</dfn>.</p>
                    605: 
                    606:   <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      607:   is not present; it is implied, but it is still there. An HTML
                    608:   document always has a root <code><a href="semantics.html#the-html-element">html</a></code> element, even if the
                    609:   string <code title="">&lt;html&gt;</code> doesn't appear anywhere in
1.97      mike      610:   the markup.</p>
                    611: 
                    612:   <!-- <html> -->
                    613:   <p>An <code><a href="semantics.html#the-html-element">html</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
                    614:   first thing inside the <code><a href="semantics.html#the-html-element">html</a></code> element is not a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
                    615: 
                    616:   <!-- </html> -->
                    617:   <p>An <code><a href="semantics.html#the-html-element">html</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      618:   tag</a> may be omitted if the <code><a href="semantics.html#the-html-element">html</a></code> element is not
1.97      mike      619:   immediately followed by a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
                    620: 
                    621:   <!-- <head> -->
                    622:   <p>A <code><a href="semantics.html#the-head-element">head</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted <!--if the
1.1       mike      623:   element is empty, or--> if the first thing inside the
1.97      mike      624:   <code><a href="semantics.html#the-head-element">head</a></code> element is an element.</p>
                    625: 
                    626:   <!-- </head> -->
                    627:   <p>A <code><a href="semantics.html#the-head-element">head</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      628:   tag</a> may be omitted if the <code><a href="semantics.html#the-head-element">head</a></code> element is not
1.97      mike      629:   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>
                    630: 
                    631:   <!-- <body> -->
                    632:   <p>A <code><a href="semantics.html#the-body-element">body</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.1       mike      633:   element is empty, or if the first thing inside the <code><a href="semantics.html#the-body-element">body</a></code>
                    634:   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
                    635:   inside the <code><a href="semantics.html#the-body-element">body</a></code> element is a <code><a href="semantics.html#script">script</a></code> or
                    636:   <code><a href="semantics.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
                    637:   tag is present, the parser makes <style> and <script> elements
                    638:   between </head> and <body> end up in the <head> instead of implying
1.97      mike      639:   the <body> --></p>
                    640: 
                    641:   <!-- </body> -->
                    642:   <p>A <code><a href="semantics.html#the-body-element">body</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      643:   tag</a> may be omitted if the <code><a href="semantics.html#the-body-element">body</a></code> element is not
1.97      mike      644:   immediately followed by a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
                    645: 
                    646:   <!-- </li> -->
                    647:   <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      648:   tag</a> may be omitted if the <code><a href="semantics.html#the-li-element">li</a></code> element is
                    649:   immediately followed by another <code><a href="semantics.html#the-li-element">li</a></code> element or if there
1.97      mike      650:   is no more content in the parent element.</p>
                    651: 
                    652:   <!-- </dt> -->
                    653:   <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      654:   tag</a> may be omitted if the <code><a href="semantics.html#the-dt-element">dt</a></code> element is
                    655:   immediately followed by another <code><a href="semantics.html#the-dt-element">dt</a></code> element or a
1.97      mike      656:   <code><a href="semantics.html#the-dd-element">dd</a></code> element.</p>
                    657: 
                    658:   <!-- </dd> -->
                    659:   <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      660:   tag</a> may be omitted if the <code><a href="semantics.html#the-dd-element">dd</a></code> element is
                    661:   immediately followed by another <code><a href="semantics.html#the-dd-element">dd</a></code> element or a
                    662:   <code><a href="semantics.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.97      mike      663:   parent element.</p>
                    664: 
                    665:   <!-- </p> -->
                    666:   <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      667:   tag</a> may be omitted if the <code><a href="semantics.html#the-p-element">p</a></code> element is
                    668:   immediately followed by an <code><a href="semantics.html#the-address-element">address</a></code>,
                    669:   <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      670:   <!--v2DATAGRID <code>datagrid</code>,--> <code><a href="semantics.html#the-dialog-element">dialog</a></code>,
                    671:   <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>,
                    672:   <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>,
                    673:   <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>,
                    674:   <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>,
                    675:   <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>,
                    676:   <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      677:   <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>,
                    678:   element, or if there is no more content in the parent element and
1.97      mike      679:   the parent element is not an <code><a href="text-level-semantics.html#the-a-element">a</a></code> element.</p>
                    680: 
                    681:   <!-- </rt> -->
                    682:   <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      683:   tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element is
                    684:   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.97      mike      685:   element, or if there is no more content in the parent element.</p>
                    686: 
                    687:   <!-- </rp> -->
                    688:   <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      689:   tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element is
                    690:   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.97      mike      691:   element, or if there is no more content in the parent element.</p>
                    692: 
                    693:   <!-- </optgroup> (the text assumes <optgroup> can only be inside a
1.1       mike      694:   <select>; commented out text below can handle the non-<select> case
1.97      mike      695:   if we ever allow it) -->
                    696:   <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      697:   <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
                    698:   <code>select</code> element and--> is immediately followed by
                    699:   another <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
                    700:   that are ancestors of the <code>optgroup</code> element, up to and
                    701:   including the first ancestor element that is not an
                    702:   <code>optgroup</code> element, have no more content--> there is no
1.97      mike      703:   more content in the parent element.</p>
                    704:   <!-- so e.g. the max number of </optgroup>s are omitted here:
1.1       mike      705:    <select><optgroup></select>
                    706:    <p id=x><optgroup></optgroup>x</p>
                    707:    <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
                    708:    <p><optgroup id=x><optgroup></optgroup>x</p>
                    709:    <p><optgroup><optgroup id=x>x</p>
1.97      mike      710:   -->
                    711: 
                    712:   <!-- </option> -->
                    713:   <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      714:   tag</a> may be omitted if the <code><a href="forms.html#the-option-element">option</a></code> element is
                    715:   immediately followed by another <code><a href="forms.html#the-option-element">option</a></code> element, or if
                    716:   it is immediately followed by an <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or
1.97      mike      717:   if there is no more content in the parent element.</p>
                    718: 
                    719:   <!-- <colgroup> -->
                    720:   <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      721:   first thing inside the <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is a
                    722:   <code><a href="tabular-data.html#the-col-element">col</a></code> element, and if the element is not immediately
                    723:   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.97      mike      724:   omitted if the element is empty.)</p>
                    725: 
                    726:   <!-- </colgroup> -->
                    727:   <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      728:   <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.97      mike      729:   <a href="infrastructure.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
                    730: 
                    731:   <!-- </thead> -->
                    732:   <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      733:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-thead-element">thead</a></code> element is
                    734:   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.97      mike      735:   element.</p>
                    736: 
                    737:   <!-- <tbody> -->
                    738:   <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      739:   first thing inside the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is a
                    740:   <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, and if the element is not immediately
                    741:   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
                    742:   <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
                    743:   tag</a> has been omitted. (It can't be omitted if the element is
1.97      mike      744:   empty.)</p>
                    745: 
                    746:   <!-- </tbody> -->
                    747:   <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      748:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is
                    749:   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.97      mike      750:   element, or if there is no more content in the parent element.</p>
                    751: 
                    752:   <!-- </tfoot> -->
                    753:   <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      754:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element is
                    755:   immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, or if there is
1.97      mike      756:   no more content in the parent element.</p>
                    757: 
                    758:   <!-- </tr> -->
                    759:   <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      760:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
                    761:   immediately followed by another <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, or if there
1.97      mike      762:   is no more content in the parent element.</p>
                    763: 
                    764:   <!-- </td> -->
                    765:   <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      766:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-td-element">td</a></code> element is
                    767:   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.97      mike      768:   element, or if there is no more content in the parent element.</p>
                    769: 
                    770:   <!-- </th> -->
                    771:   <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      772:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-th-element">th</a></code> element is
                    773:   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.97      mike      774:   element, or if there is no more content in the parent element.</p>
                    775: 
                    776:   <p><strong>However</strong>, a <a href="#syntax-start-tag" title="syntax-start-tag">start
                    777:   tag</a> must never be omitted if it has any attributes.</p>
                    778: 
                    779: 
                    780:   <h5 id="element-restrictions"><span class="secno">9.1.2.5 </span>Restrictions on content models</h5>
                    781: 
                    782:   <p>For historical reasons, certain elements have extra restrictions
                    783:   beyond even the restrictions given by their content model.</p>
                    784: 
                    785:   <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      786:   elements, even though these elements are technically allowed inside
                    787:   <code><a href="tabular-data.html#the-table-element">table</a></code> elements according to the content models
                    788:   described in this specification. (If a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
                    789:   put inside a <code><a href="tabular-data.html#the-table-element">table</a></code> in the markup, it will in fact imply
1.97      mike      790:   a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag before it.)</p>
                    791: 
                    792:   <p>A single U+000A LINE FEED (LF) character may be placed
1.1       mike      793:   immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
                    794:   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>
                    795:   elements. This does not affect the processing of the element. The
                    796:   otherwise optional U+000A LINE FEED (LF) character <em>must</em> be
                    797:   included if the element's contents start with that character
                    798:   (because otherwise the leading newline in the contents would be
1.97      mike      799:   treated like the optional newline, and ignored).</p>
                    800: 
                    801:   <div class="example">
1.1       mike      802:    <p>The following two <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
                    803:    <pre>&lt;pre&gt;Hello&lt;/pre&gt;</pre>
                    804:    <pre>&lt;pre&gt;<br>Hello&lt;/pre&gt;</pre>
1.97      mike      805:   </div>
                    806: 
                    807: 
                    808:   <h5 id="cdata-rcdata-restrictions"><span class="secno">9.1.2.6 </span>Restrictions on the contents of raw text and RCDATA elements</h5>
                    809: 
                    810:   <p>The text in raw text and RCDATA elements must not contain any
1.1       mike      811:   occurrences of the string "<code title="">&lt;/</code>" (U+003C
                    812:   LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that
                    813:   case-insensitively match the tag name of the element followed by one
                    814:   of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM
                    815:   FEED (FF), U+0020 SPACE, U+003E GREATER-THAN SIGN (&gt;), or U+002F
1.97      mike      816:   SOLIDUS (/), unless that string is part of an <a href="#syntax-escape" title="syntax-escape">escaping text span</a>.</p>
                    817: 
                    818:   <p>An <dfn id="syntax-escape" title="syntax-escape">escaping text span</dfn> is a span
1.1       mike      819:   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
                    820:   not itself in an <a href="#syntax-escape" title="syntax-escape">escaping text
                    821:   span</a>, and ends at the next <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span end</a>. There
                    822:   cannot be any <a href="#syntax-charref" title="syntax-charref">character
                    823:   references</a> inside an <a href="#syntax-escape" title="syntax-escape">escaping
                    824:   text span</a> &#8212; sequences of characters that would look
                    825:   like <a href="#syntax-charref" title="syntax-charref">character references</a> do not
1.97      mike      826:   have special meaning.</p>
                    827: 
                    828:   <p>An <dfn id="syntax-escape-start" title="syntax-escape-start">escaping text span
1.1       mike      829:   start</dfn> is a part of <a href="#syntax-text" title="syntax-text">text</a> that
                    830:   consists of the four character sequence "<code title="">&lt;!--</code>" (U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
1.97      mike      831:   MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS).</p>
                    832: 
                    833:   <p>An <dfn id="syntax-escape-end" title="syntax-escape-end">escaping text span end</dfn> is
1.1       mike      834:   a part of <a href="#syntax-text" title="syntax-text">text</a> that consists of the
                    835:   three character sequence "<code title="">--&gt;</code>" (U+002D
                    836:   HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN) whose
1.97      mike      837:   U+003E GREATER-THAN SIGN (&gt;).</p>
                    838: 
                    839:   <p>An <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span
1.1       mike      840:   start</a> may share its U+002D HYPHEN-MINUS characters with its
                    841:   corresponding <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span
1.97      mike      842:   end</a>.</p>
                    843: 
                    844:   <p>The text in raw text elements and RCDATA elements must not have
1.91      mike      845:   an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a>
                    846:   that is not followed by an <a href="#syntax-escape-end" title="syntax-escape-end">escaping
1.97      mike      847:   text span end</a>.</p>
                    848: 
                    849: 
                    850:   <h4 id="text-0"><span class="secno">9.1.3 </span>Text</h4>
                    851: 
                    852:   <p><dfn id="syntax-text" title="syntax-text">Text</dfn> is allowed inside elements,
1.1       mike      853:   attributes, and comments. Text must consist of Unicode characters.
                    854:   Text must not contain U+0000 characters. Text must not contain
                    855:   permanently undefined Unicode characters. Text must not contain
                    856:   control characters other than <a href="infrastructure.html#space-character" title="space character">space
                    857:   characters</a>. Extra constraints are placed on what is and what
                    858:   is not allowed in text based on where the text is to be put, as
1.97      mike      859:   described in the other sections.</p>
                    860: 
                    861: 
                    862:   <h5 id="newlines"><span class="secno">9.1.3.1 </span>Newlines</h5>
                    863: 
                    864:   <p><dfn id="syntax-newlines" title="syntax-newlines">Newlines</dfn> in HTML may be
1.1       mike      865:   represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A
                    866:   LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR),
1.97      mike      867:   U+000A LINE FEED (LF) characters in that order.</p>
                    868: 
                    869: 
                    870:   <h4 id="character-references"><span class="secno">9.1.4 </span>Character references</h4>
                    871: 
                    872:   <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      873:   to escape characters that couldn't otherwise legally be included in
1.97      mike      874:   <a href="#syntax-text" title="syntax-text">text</a>.</p>
                    875: 
                    876:   <p>Character references must start with a U+0026 AMPERSAND
1.1       mike      877:   (<code>&amp;</code>). Following this, there are three possible kinds
1.97      mike      878:   of character references:</p>
                    879: 
                    880:   <dl><dt>Named character references</dt>
1.1       mike      881: 
                    882:    <dd>The ampersand must be followed by one of the names given in the
                    883:    <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
                    884:    case. The name must be one that is terminated by a U+003B SEMICOLON
                    885:    (<code title="">;</code>) character.</dd>
                    886: 
                    887: 
                    888:    <dt>Decimal numeric character reference</dt>
                    889: 
                    890:    <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
                    891:    (<code>#</code>) character, followed by one or more digits in the
                    892:    range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, representing a
                    893:    base-ten integer that itself is a Unicode code point that is
                    894:    not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
                    895:    0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
                    896:    a U+003B SEMICOLON character (<code title="">;</code>).</dd>
                    897: 
                    898: 
                    899:    <dt>Hexadecimal numeric character reference</dt>
                    900: 
                    901:    <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
                    902:    (<code>#</code>) character, which must be followed by either a
                    903:    U+0078 LATIN SMALL LETTER X or a U+0058 LATIN CAPITAL LETTER X
                    904:    character, which must then be followed by one or more digits in the
                    905:    range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, U+0061 LATIN SMALL
                    906:    LETTER A .. U+0066 LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL
                    907:    LETTER A .. U+0046 LATIN CAPITAL LETTER F, representing a
                    908:    base-sixteen integer that itself is a Unicode code point that is
                    909:    not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
                    910:    0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
                    911:    a U+003B SEMICOLON character (<code title="">;</code>).</dd>
                    912: 
                    913:   </dl><p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
                    914:   ampersand</dfn> is a U+0026 AMPERSAND (<code>&amp;</code>) character
                    915:   that is followed by some <a href="#syntax-text" title="syntax-text">text</a> other
                    916:   than a <a href="infrastructure.html#space-character">space character</a>, a U+003C LESS-THAN SIGN
                    917:   character ('&lt;'), or another U+0026 AMPERSAND (<code>&amp;</code>)
1.97      mike      918:   character.</p>
                    919: 
                    920: 
                    921:   <h4 id="cdata-sections"><span class="secno">9.1.5 </span>CDATA sections</h4>
                    922: 
                    923:   <p><dfn id="syntax-cdata" title="syntax-cdata">CDATA sections</dfn> must start with
1.1       mike      924:   the character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
                    925:   MARK, U+005B LEFT SQUARE BRACKET, U+0043 LATIN CAPITAL LETTER C,
                    926:   U+0044 LATIN CAPITAL LETTER D, U+0041 LATIN CAPITAL LETTER A, U+0054
                    927:   LATIN CAPITAL LETTER T, U+0041 LATIN CAPITAL LETTER A, U+005B LEFT
                    928:   SQUARE BRACKET (<code title="">&lt;![CDATA[</code>). Following this
                    929:   sequence, the CDATA section may have <a href="#syntax-text" title="syntax-text">text</a>, with the additional restriction
                    930:   that the text must not contain the three character sequence U+005D
                    931:   RIGHT SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E
                    932:   GREATER-THAN SIGN (<code title="">]]&gt;</code>). Finally, the CDATA
                    933:   section must be ended by the three character sequence U+005D RIGHT
                    934:   SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E GREATER-THAN
1.97      mike      935:   SIGN (<code title="">]]&gt;</code>).</p>
                    936: 
                    937: 
                    938:   <h4 id="comments"><span class="secno">9.1.6 </span>Comments</h4>
                    939: 
                    940:   <p><dfn id="syntax-comments" title="syntax-comments">Comments</dfn> must start with the
1.1       mike      941:   four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
                    942:   MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title="">&lt;!--</code>). Following this sequence, the comment may
                    943:   have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
                    944:   restriction that the text must not start with a single U+003E
                    945:   GREATER-THAN SIGN ('&gt;') character, nor start with a U+002D
                    946:   HYPHEN-MINUS (<code title="">-</code>) character followed by a
                    947:   U+003E GREATER-THAN SIGN ('&gt;') character, nor contain two
                    948:   consecutive U+002D HYPHEN-MINUS (<code title="">-</code>)
                    949:   characters, nor end with a U+002D HYPHEN-MINUS (<code title="">-</code>) character. Finally, the comment must be ended by
                    950:   the three character sequence U+002D HYPHEN-MINUS, U+002D
1.97      mike      951:   HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--&gt;</code>).</p>
                    952: 
                    953: 
                    954:   <div class="impl">
1.1       mike      955: 
                    956:   <h3 id="parsing"><span class="secno">9.2 </span>Parsing HTML documents</h3>
                    957: 
                    958:   <p><i>This section only applies to user agents, data mining tools,
                    959:   and conformance checkers.</i></p>
                    960: 
                    961:   <p class="note">The rules for parsing XML documents into DOM trees
                    962:   are covered by the next section, entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
                    963:   syntax</a>".</p>
                    964: 
                    965:   <p>For <a href="dom.html#html-documents">HTML documents</a>, user agents must use the parsing
                    966:   rules described in this section to generate the DOM trees. Together,
                    967:   these rules define what is referred to as the <dfn id="html-parser">HTML
                    968:   parser</dfn>.</p>
                    969: 
                    970:   <div class="note">
                    971: 
                    972:    <p>While the HTML syntax described in this specification bears a
                    973:    close resemblance to SGML and XML, it is a separate language with
                    974:    its own parsing rules.</p>
                    975: 
                    976:    <p>Some earlier versions of HTML (in particular from HTML&#160;2 to
                    977:    HTML&#160;4) were based on SGML and used SGML parsing rules. However, few
                    978:    (if any) web browsers ever implemented true SGML parsing for HTML
                    979:    documents; the only user agents to strictly handle HTML as an SGML
                    980:    application have historically been validators. The resulting
                    981:    confusion &#8212; with validators claiming documents to have one
                    982:    representation while widely deployed Web browsers interoperably
                    983:    implemented a different representation &#8212; has wasted decades
                    984:    of productivity. This version of HTML thus returns to a non-SGML
                    985:    basis.</p>
                    986: 
                    987:    <p>Authors interested in using SGML tools in their authoring
                    988:    pipeline are encouraged to use XML tools and the XML serialization
                    989:    of HTML.</p>
                    990: 
                    991:   </div>
                    992: 
                    993:   <p>This specification defines the parsing rules for HTML documents,
                    994:   whether they are syntactically correct or not. Certain points in the
                    995:   parsing algorithm are said to be <dfn id="parse-error" title="parse error">parse
                    996:   errors</dfn>. The error handling for parse errors is well-defined:
                    997:   user agents must either act as described below when encountering
                    998:   such problems, or must abort processing at the first error that they
                    999:   encounter for which they do not wish to apply the rules described
                   1000:   below.</p>
                   1001: 
                   1002:   <p>Conformance checkers must report at least one parse error
                   1003:   condition to the user if one or more parse error conditions exist in
                   1004:   the document and must not report parse error conditions if none
                   1005:   exist in the document. Conformance checkers may report more than one
                   1006:   parse error condition if more than one parse error conditions exist
                   1007:   in the document. Conformance checkers are not required to recover
                   1008:   from parse errors.</p>
                   1009: 
                   1010:   <p class="note">Parse errors are only errors with the
                   1011:   <em>syntax</em> of HTML. In addition to checking for parse errors,
                   1012:   conformance checkers will also verify that the document obeys all
                   1013:   the other conformance requirements described in this
                   1014:   specification.</p>
                   1015: 
                   1016:   <p>For the purposes of conformance checkers, if a resource is
                   1017:   determined to be in <a href="#syntax">the HTML syntax</a>, then it is an
                   1018:   <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                   1019: 
                   1020: 
                   1021:   <h4 id="overview-of-the-parsing-model"><span class="secno">9.2.1 </span>Overview of the parsing model</h4>
                   1022: 
                   1023:   <p>The input to the HTML parsing process consists of a stream of
                   1024:   Unicode characters, which is passed through a
                   1025:   <a href="#tokenization">tokenization</a> stage followed by a <a href="#tree-construction">tree
                   1026:   construction</a> stage. The output is a <code>Document</code>
                   1027:   object.</p>
                   1028: 
                   1029:   <p class="note">Implementations that <a href="infrastructure.html#non-scripted">do not
                   1030:   support scripting</a> do not have to actually create a DOM
                   1031:   <code>Document</code> object, but the DOM tree in such cases is
                   1032:   still used as the model for the rest of the specification.</p>
                   1033: 
                   1034:   <p>In the common case, the data handled by the tokenization stage
                   1035:   comes from the network, but <a href="dom.html#dynamic-markup-insertion" title="dynamic markup
                   1036:   insertion">it can also come from script</a>, e.g. using the <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code> API.</p>
                   1037: 
                   1038:   <p><img alt="" src="images/parsing-model-overview.png"></p>
                   1039: 
                   1040:   <p id="nestedParsing">There is only one set of states for the
                   1041:   tokenizer stage and the tree construction stage, but the tree
                   1042:   construction stage is reentrant, meaning that while the tree
                   1043:   construction stage is handling one token, the tokenizer might be
                   1044:   resumed, causing further tokens to be emitted and processed before
                   1045:   the first token's processing is complete.</p>
                   1046: 
                   1047:   <div class="example">
                   1048: 
                   1049:    <p>In the following example, the tree construction stage will be
                   1050:    called upon to handle a "p" start tag token while handling the
                   1051:    "script" start tag token:</p>
                   1052: 
                   1053:    <pre>...
                   1054: &lt;script&gt;
                   1055:  document.write('&lt;p&gt;');
                   1056: &lt;/script&gt;
                   1057: ...</pre>
                   1058: 
                   1059:   </div>
                   1060: 
                   1061:   <p>To handle these cases, parsers have a <dfn id="script-nesting-level">script nesting
                   1062:   level</dfn>, which must be initially set to zero, and a <dfn id="parser-pause-flag">parser
                   1063:   pause flag</dfn>, which must be initially set to false.</p>
                   1064: 
                   1065: 
                   1066: 
                   1067:   <h4 id="the-input-stream"><span class="secno">9.2.2 </span>The <dfn>input stream</dfn></h4>
                   1068: 
                   1069:   <p>The stream of Unicode characters that comprises the input to the
                   1070:   tokenization stage will be initially seen by the user agent as a
                   1071:   stream of bytes (typically coming over the network or from the local
                   1072:   file system). The bytes encode the actual characters according to a
                   1073:   particular <em>character encoding</em>, which the user agent must
                   1074:   use to decode the bytes into characters.</p>
                   1075: 
                   1076:   <p class="note">For XML documents, the algorithm user agents must
                   1077:   use to determine the character encoding is given by the XML
                   1078:   specification. This section does not apply to XML documents. <a href="references.html#references">[XML]</a></p>
                   1079: 
                   1080: 
                   1081:   <h5 id="determining-the-character-encoding"><span class="secno">9.2.2.1 </span>Determining the character encoding</h5>
                   1082: 
                   1083:   <p>In some cases, it might be impractical to unambiguously determine
                   1084:   the encoding before parsing the document. Because of this, this
                   1085:   specification provides for a two-pass mechanism with an optional
                   1086:   pre-scan. Implementations are allowed, as described below, to apply
                   1087:   a simplified parsing algorithm to whatever bytes they have available
                   1088:   before beginning to parse the document. Then, the real parser is
                   1089:   started, using a tentative encoding derived from this pre-parse and
                   1090:   other out-of-band metadata. If, while the document is being loaded,
                   1091:   the user agent discovers an encoding declaration that conflicts with
                   1092:   this information, then the parser can get reinvoked to perform a
                   1093:   parse of the document with the real encoding.</p>
                   1094: 
                   1095:   <p id="documentEncoding">User agents must use the following
                   1096:   algorithm (the <dfn id="encoding-sniffing-algorithm">encoding sniffing algorithm</dfn>) to determine
                   1097:   the character encoding to use when decoding a document in the first
                   1098:   pass. This algorithm takes as input any out-of-band metadata
                   1099:   available to the user agent (e.g. the <a href="infrastructure.html#content-type" title="Content-Type">Content-Type metadata</a> of the document)
                   1100:   and all the bytes available so far, and returns an encoding and a
                   1101:   <dfn id="concept-encoding-confidence" title="concept-encoding-confidence">confidence</dfn>. The
                   1102:   confidence is either <i>tentative</i>, <i>certain</i>, or
                   1103:   <i>irrelevant</i>. The encoding used, and whether the confidence in
                   1104:   that encoding is <i>tentative</i> or <i>certain</i>, is <a href="#meta-charset-during-parse">used during the parsing</a> to
                   1105:   determine whether to <a href="#change-the-encoding">change the encoding</a>. If no
                   1106:   encoding is necessary, e.g. because the parser is operating on a
                   1107:   stream of Unicode characters and doesn't have to use an encoding at
                   1108:   all, then the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   1109:   <i>irrelevant</i>.</p>
                   1110: 
                   1111:   <ol><li><p>If the transport layer specifies an encoding, and it is
                   1112:    supported, return that encoding with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1113:    <i>certain</i>, and abort these steps.</p></li>
                   1114: 
                   1115:    <li><p>The user agent may wait for more bytes of the resource to be
                   1116:    available, either in this step or at any later step in this
                   1117:    algorithm. For instance, a user agent might wait 500ms or 512
                   1118:    bytes, whichever came first. In general preparsing the source to
                   1119:    find the encoding improves performance, as it reduces the need to
                   1120:    throw away the data structures used when parsing upon finding the
                   1121:    encoding information. However, if the user agent delays too long to
                   1122:    obtain data to determine the encoding, then the cost of the delay
                   1123:    could outweigh any performance improvements from the
                   1124:    preparse.</p></li>
                   1125: 
                   1126:    <li><p>For each of the rows in the following table, starting with
                   1127:    the first one and going down, if there are as many or more bytes
                   1128:    available than the number of bytes in the first column, and the
                   1129:    first bytes of the file match the bytes given in the first column,
                   1130:    then return the encoding given in the cell in the second column of
                   1131:    that row, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1132:    <i>certain</i>, and abort these steps:</p>
                   1133: 
                   1134:     <!-- this table is present in several forms in this file; keep them in sync -->
                   1135:     <table><thead><tr><th>Bytes in Hexadecimal
                   1136:        </th><th>Encoding
                   1137:      </th></tr></thead><tbody><!-- nobody uses this
                   1138:       <tr>
                   1139:        <td>00 00 FE FF
                   1140:        <td>UTF-32BE
                   1141:       <tr>
                   1142:        <td>FF FE 00 00
                   1143:        <td>UTF-32LE
                   1144: --><tr><td>FE FF
                   1145:        </td><td>UTF-16BE
                   1146:       </td></tr><tr><td>FF FE
                   1147:        </td><td>UTF-16LE
                   1148:       </td></tr><tr><td>EF BB BF
                   1149:        </td><td>UTF-8
                   1150: <!-- nobody uses this
                   1151:       <tr>
                   1152:        <td>DD 73 66 73
                   1153:        <td>UTF-EBCDIC
                   1154: -->
                   1155:     </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
                   1156:    (BOMs).</p></li>
                   1157: 
                   1158:    <li><p>Otherwise, the user agent will have to search for explicit
                   1159:    character encoding information in the file itself. This should
                   1160:    proceed as follows:
                   1161: 
                   1162:     </p><p>Let <var title="">position</var> be a pointer to a byte in the
                   1163:     input stream, initially pointing at the first byte. If at any
                   1164:     point during these substeps the user agent either runs out of
                   1165:     bytes or decides that scanning further bytes would not be
                   1166:     efficient, then skip to the next step of the overall character
                   1167:     encoding detection algorithm. User agents may decide that scanning
                   1168:     <em>any</em> bytes is not efficient, in which case these substeps
                   1169:     are entirely skipped.</p>
                   1170: 
                   1171:     <p>Now, repeat the following "two" steps until the algorithm
                   1172:     aborts (either because user agent aborts, as described above, or
                   1173:     because a character encoding is found):</p>
                   1174: 
                   1175:     <ol><li><p>If <var title="">position</var> points to:</p>
                   1176: 
                   1177:       <dl class="switch"><dt>A sequence of bytes starting with: 0x3C 0x21 0x2D 0x2D (ASCII '&lt;!--')</dt>
                   1178:        <dd>
                   1179: 
                   1180:         <p>Advance the <var title="">position</var> pointer so that it
                   1181:         points at the first 0x3E byte which is preceded by two 0x2D
                   1182:         bytes (i.e. at the end of an ASCII '--&gt;' sequence) and comes
                   1183:         after the 0x3C byte that was found. (The two 0x2D bytes can be
                   1184:         the same as the those in the '&lt;!--' sequence.)</p>
                   1185: 
                   1186:        </dd>
                   1187: 
                   1188:        <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>
                   1189:        <dd>
                   1190: 
                   1191:         <ol><li><p>Advance the <var title="">position</var> pointer so
                   1192:          that it points at the next 0x09, 0x0A, 0x0C, 0x0D, 0x20, or
                   1193:          0x2F byte (the one in sequence of characters matched
                   1194:          above).</p></li>
                   1195: 
                   1196:          <li><p><a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">Get
                   1197:          an attribute</a> and its value. If no attribute was
                   1198:          sniffed, then skip this inner set of steps, and jump to the
                   1199:          second step in the overall "two step" algorithm.</p></li>
                   1200: 
                   1201:          <li><p>If the attribute's name is neither "<code title="">charset</code>" nor "<code title="">content</code>",
                   1202:          then return to step 2 in these inner steps.</p></li>
                   1203: 
                   1204:          <li><p>If the attribute's name is "<code title="">charset</code>", let <var title="">charset</var> be
                   1205:          the attribute's value, interpreted as a character
                   1206:          encoding.</p></li>
                   1207: 
                   1208:          <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
                   1209:          extracting an encoding from a Content-Type</a>, giving the
                   1210:          attribute's value as the string to parse. If an encoding is
                   1211:          returned, let <var title="">charset</var> be that
                   1212:          encoding. Otherwise, return to step 2 in these inner
                   1213:          steps.</p></li>
                   1214: 
                   1215:          <li><p>If <var title="">charset</var> is a UTF-16 encoding,
                   1216:          change the value of <var title="">charset</var> to
                   1217:          UTF-8.</p></li>
                   1218: 
                   1219:          <li><p>If <var title="">charset</var> is a supported
                   1220:          character encoding, then return the given encoding, with
                   1221:          <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1222:          <i>tentative</i>, and abort all these steps.</p></li>
                   1223: 
                   1224:          <li><p>Otherwise, return to step 2 in these inner
                   1225:          steps.</p></li>
                   1226: 
                   1227:         </ol></dd>
                   1228: 
                   1229:        <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>
                   1230:        <dd>
                   1231: 
                   1232:         <ol><li><p>Advance the <var title="">position</var> pointer so
                   1233:          that it points at the next 0x09 (ASCII TAB), 0x0A (ASCII LF),
                   1234:          0x0C (ASCII FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E
                   1235:          (ASCII '&gt;') byte.</p></li>
                   1236: 
                   1237:          <li><p>Repeatedly <a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
                   1238:          attribute</a> until no further attributes can be found,
                   1239:          then jump to the second step in the overall "two step"
                   1240:          algorithm.</p></li>
                   1241: 
                   1242:         </ol></dd>
                   1243: 
                   1244:        <dt>A sequence of bytes starting with: 0x3C 0x21 (ASCII '&lt;!')</dt>
                   1245:        <dt>A sequence of bytes starting with: 0x3C 0x2F (ASCII '&lt;/')</dt>
                   1246:        <dt>A sequence of bytes starting with: 0x3C 0x3F (ASCII '&lt;?')</dt>
                   1247:        <dd>
                   1248: 
                   1249:         <p>Advance the <var title="">position</var> pointer so that it
                   1250:         points at the first 0x3E byte (ASCII '&gt;') that comes after the
                   1251:         0x3C byte that was found.</p>
                   1252: 
                   1253:        </dd>
                   1254: 
                   1255:        <dt>Any other byte</dt>
                   1256:        <dd>
                   1257: 
                   1258:         <p>Do nothing with that byte.</p>
                   1259: 
                   1260:        </dd>
                   1261: 
                   1262:       </dl></li>
                   1263: 
                   1264:      <li>Move <var title="">position</var> so it points at the next
                   1265:      byte in the input stream, and return to the first step of this
                   1266:      "two step" algorithm.</li>
                   1267: 
                   1268:     </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
                   1269:     attribute</dfn>, it means doing this:</p>
                   1270: 
                   1271:     <ol><li><p>If the byte at <var title="">position</var> is one of 0x09
                   1272:      (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII FF), 0x0D (ASCII CR),
                   1273:      0x20 (ASCII space), or 0x2F (ASCII '/') then advance <var title="">position</var> to the next byte and redo this
                   1274:      substep.</p></li>
                   1275: 
                   1276:      <li><p>If the byte at <var title="">position</var> is 0x3E (ASCII
                   1277:      '&gt;'), then abort the "get an attribute" algorithm. There isn't
                   1278:      one.</p></li>
                   1279: 
                   1280:      <li><p>Otherwise, the byte at <var title="">position</var> is the
                   1281:      start of the attribute name. Let <var title="">attribute
                   1282:      name</var> and <var title="">attribute value</var> be the empty
                   1283:      string.</p></li>
                   1284: 
                   1285:      <li><p><i>Attribute name</i>: Process the byte at <var title="">position</var> as follows:</p>
                   1286: 
                   1287:       <dl class="switch"><dt>If it is 0x3D (ASCII '='), and the <var title="">attribute
                   1288:        name</var> is longer than the empty string</dt>
                   1289: 
                   1290:        <dd>Advance <var title="">position</var> to the next byte and
                   1291:        jump to the step below labeled <i>value</i>.</dd>
                   1292: 
                   1293:        <dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
                   1294:        FF), 0x0D (ASCII CR), or 0x20 (ASCII space)</dt>
                   1295: 
                   1296:        <dd>Jump to the step below labeled <i>spaces</i>.</dd>
                   1297: 
                   1298:        <dt>If it is 0x2F (ASCII '/') or 0x3E (ASCII '&gt;')</dt>
                   1299: 
                   1300:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1301:        name is the value of <var title="">attribute name</var>, its
                   1302:        value is the empty string.</dd>
                   1303: 
                   1304:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1305:        'Z')</dt>
                   1306: 
                   1307:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1308:        name</var> (where <var title="">b</var> is the value of the
                   1309:        byte at <var title="">position</var>).</dd>
                   1310: 
                   1311:        <dt>Anything else</dt>
                   1312: 
                   1313:        <dd>Append the Unicode character with the same code point as the
                   1314:        value of the byte at <var title="">position</var>) to <var title="">attribute name</var>. (It doesn't actually matter how
                   1315:        bytes outside the ASCII range are handled here, since only
                   1316:        ASCII characters can contribute to the detection of a character
                   1317:        encoding.)</dd>
                   1318: 
                   1319:       </dl></li>
                   1320: 
                   1321:      <li><p>Advance <var title="">position</var> to the next byte and
                   1322:      return to the previous step.</p></li>
                   1323: 
                   1324:      <li><p><i>Spaces</i>: If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
                   1325:      LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
                   1326:      advance <var title="">position</var> to the next byte, then,
                   1327:      repeat this step.</p></li>
                   1328: 
                   1329:      <li><p>If the byte at <var title="">position</var> is
                   1330:      <em>not</em> 0x3D (ASCII '='), abort the "get an attribute"
                   1331:      algorithm. The attribute's name is the value of <var title="">attribute name</var>, its value is the empty
                   1332:      string.</p></li>
                   1333: 
                   1334:      <li><p>Advance <var title="">position</var> past the 0x3D (ASCII
                   1335:      '=') byte.</p></li>
                   1336: 
                   1337:      <li><p><i>Value:</i> If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
                   1338:      LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
                   1339:      advance <var title="">position</var> to the next byte, then,
                   1340:      repeat this step.</p></li>
                   1341: 
                   1342:      <li><p>Process the byte at <var title="">position</var> as
                   1343:      follows:</p>
                   1344: 
                   1345:       <dl class="switch"><dt>If it is 0x22 (ASCII '"') or 0x27 ("'")</dt>
                   1346: 
                   1347:        <dd>
                   1348: 
                   1349:         <ol><li>Let <var title="">b</var> be the value of the byte at
                   1350:          <var title="">position</var>.</li>
                   1351: 
                   1352:          <li>Advance <var title="">position</var> to the next
                   1353:          byte.</li>
                   1354: 
                   1355:          <li>If the value of the byte at <var title="">position</var>
                   1356:          is the value of <var title="">b</var>, then advance <var title="">position</var> to the next byte and abort the "get
                   1357:          an attribute" algorithm. The attribute's name is the value of
                   1358:          <var title="">attribute name</var>, and its value is the
                   1359:          value of <var title="">attribute value</var>.</li>
                   1360: 
                   1361:          <li>Otherwise, if the value of the byte at <var title="">position</var> is in the range 0x41 (ASCII 'A') to
                   1362:          0x5A (ASCII 'Z'), then append a Unicode character to <var title="">attribute value</var> whose code point is 0x20 more
                   1363:          than the value of the byte at <var title="">position</var>.</li>
                   1364: 
                   1365:          <li>Otherwise, append a Unicode character to <var title="">attribute value</var> whose code point is the same as
                   1366:          the value of the byte at <var title="">position</var>.</li>
                   1367: 
                   1368:          <li>Return to the second step in these substeps.</li>
                   1369: 
                   1370:         </ol></dd>
                   1371: 
                   1372:        <dt>If it is 0x3E (ASCII '&gt;')</dt>
                   1373: 
                   1374:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1375:        name is the value of <var title="">attribute name</var>, its
                   1376:        value is the empty string.</dd>
                   1377: 
                   1378: 
                   1379:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1380:        'Z')</dt>
                   1381: 
                   1382:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1383:        value</var> (where <var title="">b</var> is the value of the
                   1384:        byte at <var title="">position</var>). Advance <var title="">position</var> to the next byte.</dd>
                   1385: 
                   1386:        <dt>Anything else</dt>
                   1387: 
                   1388:        <dd>Append the Unicode character with the same code point as the
                   1389:        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>
                   1390: 
                   1391:       </dl></li>
                   1392: 
                   1393:      <li><p>Process the byte at <var title="">position</var> as
                   1394:      follows:</p>
                   1395: 
                   1396:       <dl class="switch"><dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
                   1397:        FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E (ASCII
                   1398:        '&gt;')</dt>
                   1399: 
                   1400:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1401:        name is the value of <var title="">attribute name</var> and its
                   1402:        value is the value of <var title="">attribute value</var>.</dd>
                   1403: 
                   1404:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1405:        'Z')</dt>
                   1406: 
                   1407:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1408:        value</var> (where <var title="">b</var> is the value of the
                   1409:        byte at <var title="">position</var>).</dd>
                   1410: 
                   1411:        <dt>Anything else</dt>
                   1412: 
                   1413:        <dd>Append the Unicode character with the same code point as the
                   1414:        value of the byte at <var title="">position</var>) to <var title="">attribute value</var>.</dd>
                   1415: 
                   1416:       </dl></li>
                   1417: 
                   1418:      <li><p>Advance <var title="">position</var> to the next byte and
                   1419:      return to the previous step.</p></li>
                   1420: 
                   1421:     </ol><p>For the sake of interoperability, user agents should not use a
                   1422:     pre-scan algorithm that returns different results than the one
                   1423:     described above. (But, if you do, please at least let us know, so
                   1424:     that we can improve this algorithm and benefit everyone...)</p>
                   1425: 
                   1426:    </li>
                   1427: 
                   1428:    <li><p>If the user agent has information on the likely encoding for
                   1429:    this page, e.g. based on the encoding of the page when it was last
                   1430:    visited, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1431:    <i>tentative</i>, and abort these steps.</p></li>
                   1432: 
                   1433:    <li><p>The user agent may attempt to autodetect the character
                   1434:    encoding from applying frequency analysis or other algorithms to
                   1435:    the data stream. If autodetection succeeds in determining a
                   1436:    character encoding, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1437:    <i>tentative</i>, and abort these steps. <a href="references.html#references">[UNIVCHARDET]</a></p></li> <!--
                   1438:    http://www.mozilla.org/projects/intl/UniversalCharsetDetection.html
                   1439:    -->
                   1440: 
                   1441:    <li><p>Otherwise, return an implementation-defined or
                   1442:    user-specified default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1443:    <i>tentative</i>. In non-legacy environments, the more
                   1444:    comprehensive <code title="">UTF-8</code> encoding is
                   1445:    recommended. Due to its use in legacy content, <code title="">windows-1252</code> is recommended as a default in
                   1446:    predominantly Western demographics instead. Since these encodings
                   1447:    can in many cases be distinguished by inspection, a user agent may
                   1448:    heuristically decide which to use as a default.</p></li>
                   1449: 
                   1450:   </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
                   1451:   be set to the value returned from this algorithm, at the same time
                   1452:   as the user agent uses the returned value to select the decoder to
                   1453:   use for the input stream.</p>
                   1454: 
                   1455: 
                   1456: 
                   1457:   <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.2 </span>Preprocessing the input stream</h5>
                   1458: 
                   1459:   <p>Given an encoding, the bytes in the input stream must be
                   1460:   converted to Unicode characters for the tokenizer, as described by
                   1461:   the rules for that encoding, except that the leading U+FEFF BYTE
                   1462:   ORDER MARK character, if any, must not be stripped by the encoding
                   1463:   layer (it is stripped by the rule below).</p> <!-- this is to
                   1464:   prevent two leading BOMs from being both stripped, once by the
                   1465:   decoder, and once by the parser -->
                   1466: 
                   1467:   <p>Bytes or sequences of bytes in the original byte stream that
                   1468:   could not be converted to Unicode characters must be converted to
                   1469:   U+FFFD REPLACEMENT CHARACTER code points.</p>
                   1470: 
                   1471:   <p class="note">Bytes or sequences of bytes in the original byte
                   1472:   stream that did not conform to the encoding specification
                   1473:   (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
                   1474:   errors that conformance checkers are expected to report.</p>
                   1475: 
                   1476:   <p>Any byte or sequences of bytes in the original byte stream that
                   1477:   is <a href="infrastructure.html#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
                   1478:   error</a>.</p>
                   1479: 
                   1480:   <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
                   1481:   any are present.</p>
                   1482: 
                   1483:   <p>All U+0000 NULL characters in the input must be replaced by
                   1484:   U+FFFD REPLACEMENT CHARACTERs. Any occurrences of such characters is
                   1485:   a <a href="#parse-error">parse error</a>.</p>
                   1486: 
                   1487:   <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
                   1488:   <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
                   1489:   CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
                   1490:   <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+D800
                   1491:   to U+DFFF<!-- surrogates not allowed -->, U+FDD0 to U+FDEF, and
                   1492:   characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF, U+2FFFE,
                   1493:   U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE, U+5FFFF,
                   1494:   U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF, U+9FFFE,
                   1495:   U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE, U+CFFFF,
                   1496:   U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF, U+10FFFE, and
                   1497:   U+10FFFF are <a href="#parse-error" title="parse error">parse errors</a>. (These
                   1498:   are all control characters or permanently undefined Unicode
                   1499:   characters.)</p>
                   1500: 
                   1501:   <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
                   1502:   characters are treated specially. Any CR characters that are
                   1503:   followed by LF characters must be removed, and any CR characters not
                   1504:   followed by LF characters must be converted to LF characters. Thus,
                   1505:   newlines in HTML DOMs are represented by LF characters, and there
                   1506:   are never any CR characters in the input to the
                   1507:   <a href="#tokenization">tokenization</a> stage.</p>
                   1508: 
                   1509:   <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
                   1510:   input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
                   1511:   the <i><a href="#next-input-character">next input character</a></i> is the first character in the
                   1512:   input. The <dfn id="current-input-character">current input character</dfn> is the last character
                   1513:   to have been <i><a href="#consumed">consumed</a></i>.</p>
                   1514: 
                   1515:   <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
                   1516:   character or just before the end of the input stream) where content
                   1517:   inserted using <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code> is actually
                   1518:   inserted. The insertion point is relative to the position of the
                   1519:   character immediately after it, it is not an absolute offset into
                   1520:   the input stream. Initially, the insertion point is
1.10      mike     1521:   undefined.</p>
1.1       mike     1522: 
                   1523:   <p>The "EOF" character in the tables below is a conceptual character
                   1524:   representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
                   1525:   is a <a href="dom.html#script-created-parser">script-created parser</a>, then the end of the
                   1526:   <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
                   1527:   character</dfn> (inserted by the <code title="dom-document-close"><a href="dom.html#dom-document-close">document.close()</a></code> method) is
                   1528:   consumed. Otherwise, the "EOF" character is not a real character in
                   1529:   the stream, but rather the lack of any further characters.</p>
                   1530: 
                   1531: 
                   1532:   <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.3 </span>Changing the encoding while parsing</h5>
                   1533: 
                   1534:   <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
                   1535:   encoding</dfn>, it must run the following steps. This might happen
                   1536:   if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
                   1537:   failed to find an encoding, or if it found an encoding that was not
                   1538:   the actual encoding of the file.</p>
                   1539: 
                   1540:   <ol><li>If the new encoding is identical or equivalent to the encoding
                   1541:    that is already being used to interpret the input stream, then set
                   1542:    the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1543:    <i>certain</i> and abort these steps. This happens when the
                   1544:    encoding information found in the file matches what the
                   1545:    <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
                   1546:    encoding, and in the second pass through the parser if the first
                   1547:    pass found that the encoding sniffing algorithm described in the
                   1548:    earlier section failed to find the right encoding.</li>
                   1549: 
                   1550:    <li>If the encoding that is already being used to interpret the
                   1551:    input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1552:    <i>certain</i> and abort these steps. The new encoding is ignored;
                   1553:    if it was anything but the same encoding, then it would be clearly
                   1554:    incorrect.</li>
                   1555: 
                   1556:    <li>If the new encoding is a UTF-16 encoding, change it to
                   1557:    UTF-8.</li>
                   1558: 
                   1559:    <li>If all the bytes up to the last byte converted by the current
                   1560:    decoder have the same Unicode interpretations in both the current
                   1561:    encoding and the new encoding, and if the user agent supports
                   1562:    changing the converter on the fly, then the user agent may change
                   1563:    to the new converter for the encoding on the fly. Set the
                   1564:    <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
                   1565:    convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1566:    <i>certain</i>, and abort these steps.</li>
                   1567: 
                   1568:    <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
                   1569:    <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
                   1570:    browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
                   1571:    sniffing algorithm</a> and instead just set the encoding to the
                   1572:    new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1573:    <i>certain</i>. Whenever possible, this should be done without
                   1574:    actually contacting the network layer (the bytes should be
                   1575:    re-parsed from memory), even if, e.g., the document is marked as
                   1576:    not being cacheable. If this is not possible and contacting the
                   1577:    network layer would involve repeating a request that uses a method
                   1578:    other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
                   1579:    equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1580:    <i>certain</i> and ignore the new encoding. The resource will be
                   1581:    misinterpreted. User agents may notify the user of the situation,
                   1582:    to aid in application development.</li>
                   1583: 
                   1584:   </ol><h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4>
                   1585: 
                   1586:   <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5>
                   1587: 
                   1588:   <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
                   1589:   the primary operation of the tree construction stage.</p>
                   1590: 
                   1591:   <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
                   1592:   "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
                   1593:   "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
                   1594:   "<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     1595:   "<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     1596:   "<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>",
                   1597:   "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
                   1598:   "<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
                   1599:   table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
                   1600:   foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
                   1601:   body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
                   1602:   frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
                   1603:   frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
                   1604:   after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
                   1605:   frameset</a>" during the course of the parsing, as described in
                   1606:   the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
                   1607:   how tokens are processed and whether CDATA sections are
                   1608:   supported.</p>
                   1609: 
                   1610:   <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
                   1611:   head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   1612:   body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
                   1613:   table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   1614:   body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
                   1615:   "<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
                   1616:   that the other modes defer to them at various times. When the
                   1617:   algorithm below says that the user agent is to do something
                   1618:   "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
                   1619:   mode", where <var title="">m</var> is one of these modes, the user
                   1620:   agent must use the rules described under the <var title="">m</var>
                   1621:   <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
                   1622:   <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>
                   1623:   to a new value.</p>
                   1624: 
                   1625:   <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.91      mike     1626:   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     1627:   <dfn id="original-insertion-mode">original insertion mode</dfn> is also set. This is the
                   1628:   insertion mode to which the tree construction stage will return.</p>
                   1629: 
                   1630:   <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
                   1631:   mode: in foreign content">in foreign content</a>", the
                   1632:   <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
                   1633:   is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1634:   foreign content">in foreign content</a>" mode to handle HTML
                   1635:   (i.e. not foreign) content.</p>
                   1636: 
                   1637:   <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
                   1638:   mode appropriately</dfn>, it means the UA must follow these
                   1639:   steps:</p>
                   1640: 
                   1641:   <ol><li>Let <var title="">last</var> be false.</li>
                   1642: 
                   1643:    <li>Let <var title="">node</var> be the last node in the
                   1644:    <a href="#stack-of-open-elements">stack of open elements</a>.</li>
                   1645: 
                   1646:    <li>If <var title="">node</var> is the first node in the stack of
                   1647:    open elements, then set <var title="">last</var> to true and set
                   1648:    <var title="">node</var> to the <var title="">context</var>
                   1649:    element. (<a href="#fragment-case">fragment case</a>)</li>
                   1650: 
                   1651:    <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
                   1652:    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
                   1653:    steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1654: 
                   1655:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
                   1656:    <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
                   1657:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
                   1658:    mode: in cell">in cell</a>" and abort these steps.</li>
                   1659: 
                   1660:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
                   1661:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
                   1662:    mode: in row">in row</a>" and abort these steps.</li>
                   1663: 
                   1664:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
                   1665:    <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
                   1666:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
                   1667:    table body">in table body</a>" and abort these steps.</li>
                   1668: 
                   1669:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
                   1670:    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
                   1671:    these steps.</li>
                   1672: 
                   1673:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
                   1674:    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
                   1675:    abort these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1676: 
                   1677:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   1678:    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
                   1679:    steps.</li>
                   1680: 
                   1681:    <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
                   1682:    namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then switch the
                   1683:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1684:    foreign content">in foreign content</a>", let the
                   1685:    <a href="#secondary-insertion-mode">secondary insertion mode</a> be "<a href="#parsing-main-inbody" title="insertion
                   1686:    mode: in body">in body</a>", and abort these steps.</li>
                   1687: 
                   1688:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element">head</a></code> element,
                   1689:    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
                   1690:    these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- This is only
                   1691:    here for now in case people think that the spec accidentally
                   1692:    omitted it and try to "fix" it. Note that noscript-in-head is also
                   1693:    handled this way. This is all intentional. The only thing it
                   1694:    doesn't handle is the scripting-disabled fragment parsing case for
                   1695:    a <head> element containing a <noscript> which itself contains
                   1696:    something other than a <link> or a <style> element; you'd expect
                   1697:    that to break out of the <noscript> but it doesn't. This is an edge
                   1698:    case that doesn't affect the spec, since the algorithm for fragment
                   1699:    parsing is only used for innerHTML/outerHTML/insertAdjacentHTML(),
                   1700:    where we know scripting is enabled. (XXX except maybe if innerHTML
                   1701:    is set from another browsing context on a document with designMode
                   1702:    set?) -->
                   1703: 
                   1704:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element">body</a></code> element,
                   1705:    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
                   1706:    steps.</li>
                   1707: 
1.5       mike     1708:    <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.1       mike     1709:    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
                   1710:    these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1711: 
                   1712:    <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element">html</a></code> element,
                   1713:    then: if the <a href="#head-element-pointer"><code title="">head</code> element
                   1714:    pointer</a> is null, switch the <a href="#insertion-mode">insertion mode</a> to
                   1715:    "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
                   1716:    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
                   1717:    case, abort these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- XXX
                   1718:    can the head element pointer ever be non-null when we're going
                   1719:    through these steps? -->
                   1720: 
                   1721:    <li>If <var title="">last</var> is true, then switch the
                   1722:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
                   1723:    body">in body</a>" and abort these steps. (<a href="#fragment-case">fragment
                   1724:    case</a>)</li>
                   1725: 
                   1726:    <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
                   1727:    elements</a>.</li>
                   1728: 
                   1729:    <li>Return to step 3.</li>
                   1730: 
                   1731:   </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5>
                   1732: 
                   1733:   <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
                   1734:   stack grows downwards; the topmost node on the stack is the first
                   1735:   one added to the stack, and the bottommost node of the stack is the
                   1736:   most recently added node in the stack (notwithstanding when the
                   1737:   stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
                   1738: 
                   1739:   <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
                   1740:   html</a>" <a href="#insertion-mode">insertion mode</a> creates the
                   1741:   <code><a href="semantics.html#the-html-element">html</a></code> root element node, which is then added to the
                   1742:   stack.</p>
                   1743: 
                   1744:   <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
                   1745:   elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element">html</a></code>
                   1746:   element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
                   1747:   parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
                   1748:   case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
                   1749:   html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
                   1750: 
                   1751:   <p>The <code><a href="semantics.html#the-html-element">html</a></code> node, however it is created, is the topmost
                   1752:   node of the stack. It never gets popped off the stack.</p>
                   1753: 
                   1754:   <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
                   1755:   stack.</p>
                   1756: 
                   1757:   <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
                   1758:   element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
                   1759:   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
                   1760:   open elements</a> (<a href="#fragment-case">fragment case</a>), then the
                   1761:   <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
                   1762:   of open elements</a> (the <code><a href="semantics.html#the-html-element">html</a></code> element).</p>
                   1763: 
                   1764:   <p>Elements in the stack fall into the following categories:</p>
                   1765: 
                   1766:   <dl><dt><dfn id="special">Special</dfn></dt>
                   1767: 
                   1768:    <dd><p>The following HTML elements have varying levels of special
                   1769:    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>,
                   1770:    <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     1771:    <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.1       mike     1772:    <code><a href="semantics.html#the-blockquote-element">blockquote</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="semantics.html#the-br-element">br</a></code>,
1.5       mike     1773:    <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     1774:    <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
                   1775:    <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>,
                   1776:    <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>,
                   1777:    <code><a href="semantics.html#the-dt-element">dt</a></code>, <code><a href="embedded-content-0.html#the-embed-element">embed</a></code>, <code><a href="forms.html#the-fieldset-element">fieldset</a></code>,
                   1778:    <code><a href="embedded-content-0.html#the-figure-element">figure</a></code>, <code><a href="semantics.html#the-footer-element">footer</a></code>, <code><a href="forms.html#the-form-element">form</a></code>,
                   1779:    <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>,
                   1780:    <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>,
                   1781:    <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h6</a></code>, <code><a href="semantics.html#the-head-element">head</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>,
                   1782:    <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code>, <!--
                   1783:    <code>image</code>, (commented out because this isn't an element
                   1784:    that can end up on the stack, so it doesn't matter) -->
                   1785:    <code><a href="embedded-content-0.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="obsolete.html#isindex-0">isindex</a></code>,
                   1786:    <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>,
                   1787:    <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>,
                   1788:    <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>,
                   1789:    <code><a href="semantics.html#the-ol-element">ol</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>, <code><a href="embedded-content-0.html#the-param-element">param</a></code>,
                   1790:    <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>,
                   1791:    <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>,
                   1792:    <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>,
                   1793:    <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, <code><a href="semantics.html#the-title-element">title</a></code>,
                   1794:    <code><a href="tabular-data.html#the-tr-element">tr</a></code>, <code><a href="semantics.html#the-ul-element">ul</a></code>, and <code>wbr</code>.</p></dd>
1.1       mike     1795: 
                   1796:    <dt><dfn id="scoping">Scoping</dfn></dt>
                   1797:    <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
                   1798:    an element in scope">scopes</a> for various parts of the
1.5       mike     1799:    parsing: <code><a href="obsolete.html#the-applet-element">applet</a></code>, <code><a href="forms.html#the-button-element">button</a></code>,
                   1800:    <code><a href="tabular-data.html#the-caption-element">caption</a></code>, <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="obsolete.html#the-marquee-element-0">marquee</a></code>,
1.1       mike     1801:    <code><a href="embedded-content-0.html#the-object-element">object</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>, <code><a href="tabular-data.html#the-td-element">td</a></code>,
                   1802:    <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
                   1803: 
                   1804:    <dt><dfn id="formatting">Formatting</dfn></dt>
                   1805:    <dd><p>The following HTML elements are those that end up in the
                   1806:    <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     1807:    <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>,
                   1808:    <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>,
                   1809:    <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>,
                   1810:    <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
                   1811:    <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1       mike     1812: 
                   1813:    <dt><dfn id="phrasing">Phrasing</dfn></dt>
                   1814:    <dd><p>All other elements found while parsing an HTML
                   1815:    document.</p></dd>
                   1816: 
                   1817:   </dl><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-scope" title="has an element in scope">have an element in scope</dfn> when
                   1818:   the following algorithm terminates in a match state:</p>
                   1819: 
                   1820:   <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   1821:    node</a> (the bottommost node of the stack).</p></li>
                   1822: 
                   1823:    <li><p>If <var title="">node</var> is the target node, terminate in
                   1824:    a match state.</p></li>
                   1825: 
                   1826:    <li><p>Otherwise, if <var title="">node</var> is one of the
                   1827:    following elements, terminate in a failure state:</p>
1.5       mike     1828:     <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
1.1       mike     1829:      <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
                   1830:      <li><code><a href="semantics.html#the-html-element">html</a></code> in the HTML namespace</li> <!-- (This can only happen if the <var title="">node</var> is the topmost node of the <span>stack of open elements</span>, and prevents the next step from being invoked if there are no more elements in the stack.) -->
                   1831:      <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1832:      <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
                   1833:      <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
                   1834:      <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
1.5       mike     1835:      <li><code><a href="obsolete.html#the-marquee-element-0">marquee</a></code> in the HTML namespace</li>
1.1       mike     1836:      <li><code><a href="embedded-content-0.html#the-object-element">object</a></code> in the HTML namespace</li>
                   1837:      <li><code title="">foreignObject</code> in the SVG namespace</li>
                   1838:     </ul></li>
                   1839: 
                   1840:    <li><p>Otherwise, set <var title="">node</var> to the previous
                   1841:    entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
                   1842:    2. (This will never fail, since the loop will always terminate in
                   1843:    the previous step if the top of the stack &#8212; an
                   1844:    <code><a href="semantics.html#the-html-element">html</a></code> element &#8212; is reached.)</p></li>
                   1845: 
                   1846:   </ol><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-table-scope" title="has an element in table scope">have an element in <em>table
                   1847:   scope</em></dfn> when the following algorithm terminates in a match
                   1848:   state:</p>
                   1849: 
                   1850:   <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   1851:    node</a> (the bottommost node of the stack).</p></li>
                   1852: 
                   1853:    <li><p>If <var title="">node</var> is the target node, terminate in
                   1854:    a match state.</p></li>
                   1855: 
                   1856:    <li><p>Otherwise, if <var title="">node</var> is one of the
                   1857:    following elements, terminate in a failure state:</p>
                   1858:     <ul class="brief"><li><code><a href="semantics.html#the-html-element">html</a></code> in the HTML namespace</li> <!-- (This can only happen if the <var title="">node</var> is the topmost node of the <span>stack of open elements</span>, and prevents the next step from being invoked if there are no more elements in the stack.) -->
                   1859:      <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1860:     </ul></li>
                   1861: 
                   1862:    <li><p>Otherwise, set <var title="">node</var> to the previous
                   1863:    entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
                   1864:    2. (This will never fail, since the loop will always terminate in
                   1865:    the previous step if the top of the stack &#8212; an
                   1866:    <code><a href="semantics.html#the-html-element">html</a></code> element &#8212; is reached.)</p></li>
                   1867: 
                   1868:   </ol><p>Nothing happens if at any time any of the elements in the
                   1869:   <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
                   1870:   or removed from, the <code>Document</code> tree. In particular, the
                   1871:   stack is not changed in this situation. This can cause, amongst
                   1872:   other strange effects, content to be appended to nodes that are no
                   1873:   longer in the DOM.</p>
                   1874: 
                   1875:   <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
                   1876:   the stack is manipulated in a random-access fashion.</p>
                   1877: 
                   1878: 
                   1879:   <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5>
                   1880: 
                   1881:   <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
                   1882:   empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
                   1883: 
                   1884:   <p>The list contains elements in the <a href="#formatting">formatting</a>
                   1885:   category, and scope markers. The scope markers are inserted when
1.5       mike     1886:   entering <code><a href="obsolete.html#the-applet-element">applet</a></code> elements, buttons, <code><a href="embedded-content-0.html#the-object-element">object</a></code>
1.1       mike     1887:   elements, marquees, table cells, and table captions, and are used to
1.5       mike     1888:   prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.1       mike     1889:   elements, buttons, <code><a href="embedded-content-0.html#the-object-element">object</a></code> elements, marquees, and
                   1890:   tables.</p>
                   1891: 
                   1892:   <p class="note">The scope markers are unrelated to the concept of an
                   1893:   element being <a href="#has-an-element-in-scope" title="has an element in scope">in
                   1894:   scope</a>.</p>
                   1895: 
                   1896:   <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1897:   elements</a> is associated with the token for which it was
                   1898:   created, so that further elements can be created for that token if
                   1899:   necessary.</p>
                   1900: 
                   1901:   <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
                   1902:   active formatting elements</dfn>, the UA must perform the following
                   1903:   steps:</p>
                   1904: 
                   1905:   <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1906:    elements</a>, then there is nothing to reconstruct; stop this
                   1907:    algorithm.</li>
                   1908: 
                   1909:    <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
                   1910:    active formatting elements</a> is a marker, or if it is an
                   1911:    element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
                   1912:    there is nothing to reconstruct; stop this algorithm.</li>
                   1913: 
                   1914:    <li>Let <var title="">entry</var> be the last (most recently added)
                   1915:    element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1916:    elements</a>.</li>
                   1917: 
                   1918:    <li>If there are no entries before <var title="">entry</var> in the
                   1919:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
                   1920:    8.</li>
                   1921: 
                   1922:    <li>Let <var title="">entry</var> be the entry one earlier than
                   1923:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1924:    elements</a>.</li>
                   1925: 
                   1926:    <li>If <var title="">entry</var> is neither a marker nor an element
                   1927:    that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
                   1928:    4.</li>
                   1929: 
                   1930:    <li>Let <var title="">entry</var> be the element one later than
                   1931:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1932:    elements</a>.</li>
                   1933: 
                   1934:    <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   1935:    element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
                   1936: 
                   1937:    <li>Append <var title="">new element</var> to the <a href="#current-node">current
                   1938:    node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
                   1939:    elements</a> so that it is the new <a href="#current-node">current
                   1940:    node</a>.</li>
                   1941: 
                   1942:    <li>Replace the entry for <var title="">entry</var> in the list
                   1943:    with an entry for <var title="">new element</var>.</li>
                   1944: 
                   1945:    <li>If the entry for <var title="">new element</var> in the
                   1946:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
                   1947:    entry in the list, return to step 7.</li>
                   1948: 
                   1949:   </ol><p>This has the effect of reopening all the formatting elements that
                   1950:   were opened in the current body, cell, or caption (whichever is
                   1951:   youngest) that haven't been explicitly closed.</p>
                   1952: 
                   1953:   <p class="note">The way this specification is written, the
                   1954:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
                   1955:   elements in chronological order with the least recently added
                   1956:   element first and the most recently added element last (except for
                   1957:   while steps 8 to 11 of the above algorithm are being executed, of
                   1958:   course).</p>
                   1959: 
                   1960:   <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
                   1961:   active formatting elements up to the last marker</dfn>, the UA must
                   1962:   perform the following steps:</p>
                   1963: 
                   1964:   <ol><li>Let <var title="">entry</var> be the last (most recently added)
                   1965:    entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
                   1966: 
                   1967:    <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
                   1968:    formatting elements</a>.</li>
                   1969: 
                   1970:    <li>If <var title="">entry</var> was a marker, then stop the
                   1971:    algorithm at this point. The list has been cleared up to the last
                   1972:    marker.</li>
                   1973: 
                   1974:    <li>Go to step 1.</li>
                   1975: 
                   1976:   </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5>
                   1977: 
                   1978:   <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
                   1979:   pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
                   1980:   pointer</dfn> are both null.</p>
                   1981: 
                   1982:   <p>Once a <code><a href="semantics.html#the-head-element">head</a></code> element has been parsed (whether
                   1983:   implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
                   1984:   element pointer</a> gets set to point to this node.</p>
                   1985: 
                   1986:   <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   1987:   points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
                   1988:   whose end tag has not yet been seen. It is used to make form
                   1989:   controls associate with forms in the face of dramatically bad
                   1990:   markup, for historical reasons.</p>
                   1991: 
                   1992: 
                   1993:   <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5>
                   1994: 
                   1995:   <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
                   1996:   <code>Document</code> with which the parser is associated when the
                   1997:   parser was created, and "disabled" otherwise.</p>
                   1998: 
                   1999:   <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
                   2000:   when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
                   2001:   parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
                   2002:   don't execute in that case.</p>
                   2003: 
                   2004:   <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
                   2005:   created. It is set to "not ok" after certain tokens are seen.</p>
                   2006: 
                   2007: 
                   2008:   <h4 id="tokenization"><span class="secno">9.2.4 </span><dfn>Tokenization</dfn></h4>
                   2009: 
                   2010:   <p>Implementations must act as if they used the following state
                   2011:   machine to tokenize HTML. The state machine must start in the
                   2012:   <a href="#data-state">data state</a>. Most states consume a single character,
                   2013:   which may have various side-effects, and either switches the state
                   2014:   machine to a new state to <em>reconsume</em> the same character, or
                   2015:   switches it to a new state (to consume the next character), or
                   2016:   repeats the same state (to consume the next character). Some states
                   2017:   have more complicated behavior and can consume several characters
                   2018:   before switching to another state.</p>
                   2019: 
                   2020:   <p>The exact behavior of certain states depends on a <dfn id="content-model-flag">content
                   2021:   model flag</dfn> that is set after certain tokens are emitted. The
1.91      mike     2022:   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
                   2023:   state. In the RCDATA and RAWTEXT states, a further <dfn id="escape-flag">escape
1.1       mike     2024:   flag</dfn> is used to control the behavior of the tokenizer. It is
                   2025:   either true or false, and initially must be set to the false
                   2026:   state. The <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
                   2027:   elements</a> also affects tokenization.</p>
                   2028: 
                   2029:   <p>The output of the tokenization step is a series of zero or more
                   2030:   of the following tokens: DOCTYPE, start tag, end tag, comment,
                   2031:   character, end-of-file. DOCTYPE tokens have a name, a public
                   2032:   identifier, a system identifier, and a <i>force-quirks
                   2033:   flag</i>. When a DOCTYPE token is created, its name, public
                   2034:   identifier, and system identifier must be marked as missing (which
                   2035:   is a distinct state from the empty string), and the <i>force-quirks
                   2036:   flag</i> must be set to <i>off</i> (its other state is
                   2037:   <i>on</i>). Start and end tag tokens have a tag name, a
                   2038:   <i>self-closing flag</i>, and a list of attributes, each of which
                   2039:   has a name and a value. When a start or end tag token is created,
                   2040:   its <i>self-closing flag</i> must be unset (its other state is that
                   2041:   it be set), and its attributes list must be empty. Comment and
                   2042:   character tokens have data.</p>
                   2043: 
                   2044:   <p>When a token is emitted, it must immediately be handled by the
                   2045:   <a href="#tree-construction">tree construction</a> stage. The tree construction stage
                   2046:   can affect the state of the <a href="#content-model-flag">content model flag</a>, and can
                   2047:   insert additional characters into the stream. (For example, the
                   2048:   <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
                   2049:   using the <a href="dom.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
                   2050:   characters into the stream being tokenized.)</p>
                   2051: 
                   2052:   <p>When a start tag token is emitted with its <i>self-closing
                   2053:   flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
                   2054:   self-closing flag">acknowledged</dfn> when it is processed by the
                   2055:   tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
                   2056: 
                   2057:   <p>When an end tag token is emitted, the <a href="#content-model-flag">content model
                   2058:   flag</a> must be switched to the PCDATA state.</p>
                   2059: 
                   2060:   <p>When an end tag token is emitted with attributes, that is a
                   2061:   <a href="#parse-error">parse error</a>.</p>
                   2062: 
                   2063:   <p>When an end tag token is emitted with its <i>self-closing
                   2064:   flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
                   2065: 
                   2066:   <p>Before each step of the tokenizer, the user agent must first
                   2067:   check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
                   2068:   tokenizer must abort the processing of any nested invocations of the
                   2069:   tokenizer, yielding control back to the caller. If it is false, then
                   2070:   the user agent may then check to see if either one of the scripts in
                   2071:   the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will execute as soon as
                   2072:   possible</a> or the first script in the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts
                   2073:   that will execute asynchronously</a>, has <a href="semantics.html#completed-loading">completed
                   2074:   loading</a>. If one has, then it must be <a href="semantics.html#executing-a-script-block" title="executing a
                   2075:   script block">executed</a> and removed from its list.</p>
                   2076: 
                   2077:   <p>The tokenizer state machine consists of the states defined in the
                   2078:   following subsections.</p>
                   2079: 
                   2080:   <!-- XXX should go through these reordering the entries so that
                   2081:   they're in some consistent order, like, by Unicode, errors last, or
                   2082:   something -->
                   2083: 
                   2084:   <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5>
                   2085: 
                   2086:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2087: 
                   2088:   <dl class="switch"><dt>U+0026 AMPERSAND (&amp;)</dt>
                   2089:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to one of the
                   2090:    PCDATA or RCDATA states and the <a href="#escape-flag">escape flag</a> is
                   2091:    false: switch to the <a href="#character-reference-data-state">character reference data
1.56      mike     2092:    state</a>.</dd>
                   2093:    <dd>Otherwise: treat it as per the "anything else" entry
                   2094:    below.</dd>
1.1       mike     2095: 
                   2096:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2097:    <dd>
                   2098: 
                   2099:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2100:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     2101:     is false, and there are at least three characters before this
                   2102:     one in the input stream, and the last four characters in the
                   2103:     input stream, including this one, are U+003C LESS-THAN SIGN,
                   2104:     U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, and U+002D
                   2105:     HYPHEN-MINUS ("&lt;!--"), then set the <a href="#escape-flag">escape flag</a>
                   2106:     to true.</p>
                   2107: 
                   2108:     <p>In any case, emit the input character as a character
                   2109:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   2110: 
                   2111:    </dd>
                   2112: 
                   2113:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2114:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   2115:    state: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   2116:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2117:    RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     2118:    is false: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   2119:    <dd>Otherwise: treat it as per the "anything else" entry
                   2120:    below.</dd>
                   2121: 
                   2122:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2123:    <dd>
                   2124: 
                   2125:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2126:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape
1.1       mike     2127:     flag</a> is true, and the last three characters in the input
                   2128:     stream including this one are U+002D HYPHEN-MINUS, U+002D
                   2129:     HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("--&gt;"), set the
                   2130:     <a href="#escape-flag">escape flag</a> to false.</p> <!-- no need to check
                   2131:     that there are enough characters, since you can only run into
                   2132:     this if the flag is true in the first place, which requires four
                   2133:     characters. -->
                   2134: 
                   2135:     <p>In any case, emit the input character as a character
                   2136:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   2137: 
                   2138:    </dd>
                   2139: 
                   2140:    <dt>EOF</dt>
                   2141:    <dd>Emit an end-of-file token.</dd>
                   2142: 
                   2143:    <dt>Anything else</dt>
                   2144:    <dd>Emit the input character as a character token. Stay in the
                   2145:    <a href="#data-state">data state</a>.</dd>
                   2146: 
                   2147:   </dl><h5 id="character-reference-data-state"><span class="secno">9.2.4.2 </span><dfn>Character reference data state</dfn></h5>
                   2148: 
                   2149:   <p><i>(This cannot happen if the <a href="#content-model-flag">content model flag</a>
1.91      mike     2150:   is set to the RAWTEXT state.)</i></p>
1.1       mike     2151: 
                   2152:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
                   2153:   <a href="#additional-allowed-character">additional allowed character</a>.</p>
                   2154: 
                   2155:   <p>If nothing is returned, emit a U+0026 AMPERSAND character
                   2156:   token.</p>
                   2157: 
                   2158:   <p>Otherwise, emit the character token that was returned.</p>
                   2159: 
                   2160:   <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
                   2161: 
                   2162: 
                   2163:   <h5 id="tag-open-state"><span class="secno">9.2.4.3 </span><dfn>Tag open state</dfn></h5>
                   2164: 
                   2165:   <p>The behavior of this state depends on the <a href="#content-model-flag">content model
                   2166:   flag</a>.</p>
                   2167: 
                   2168:   <dl><dt>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA
1.91      mike     2169:    or RAWTEXT states</dt>
1.1       mike     2170: 
                   2171:    <dd>
                   2172: 
                   2173:     <p>Consume the <a href="#next-input-character">next input character</a>. If it is a
                   2174:     U+002F SOLIDUS (/) character, switch to the <a href="#close-tag-open-state">close tag open
                   2175:     state</a>. Otherwise, emit a U+003C LESS-THAN SIGN character
                   2176:     token and reconsume the <a href="#current-input-character">current input character</a> in the
                   2177:     <a href="#data-state">data state</a>.</p>
                   2178: 
                   2179:    </dd>
                   2180: 
                   2181:    <dt>If the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   2182:    state</dt>
                   2183: 
                   2184:    <dd>
                   2185: 
                   2186:     <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2187: 
                   2188:     <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2189:      <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
                   2190: 
                   2191:      <dt>U+002F SOLIDUS (/)</dt>
                   2192:      <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
                   2193: 
                   2194:      <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2195:      <dd>Create a new start tag token, set its tag name to the
                   2196:      lowercase version of the input character (add 0x0020 to the
                   2197:      character's code point), then switch to the <a href="#tag-name-state">tag name
                   2198:      state</a>. (Don't emit the token yet; further details will
                   2199:      be filled in before it is emitted.)</dd>
                   2200: 
                   2201:      <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2202:      <dd>Create a new start tag token, set its tag name to the input
                   2203:      character, then switch to the <a href="#tag-name-state">tag name
                   2204:      state</a>. (Don't emit the token yet; further details will
                   2205:      be filled in before it is emitted.)</dd>
                   2206: 
                   2207:      <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2208:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2209:      character token and a U+003E GREATER-THAN SIGN character
                   2210:      token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2211: 
                   2212:      <dt>U+003F QUESTION MARK (?)</dt>
                   2213:      <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2214:      comment state</a>.</dd>
                   2215: 
                   2216:      <dt>Anything else</dt>
                   2217:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2218:      character token and reconsume the <a href="#current-input-character">current input character</a> in the
                   2219:      <a href="#data-state">data state</a>.</dd>
                   2220: 
                   2221:     </dl></dd>
                   2222: 
                   2223:   </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.4 </span><dfn>Close tag open state</dfn></h5>
                   2224: 
                   2225:   <p>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA or
1.91      mike     2226:   RAWTEXT states but no start tag token has ever been emitted by this
1.1       mike     2227:   instance of the tokenizer (<a href="#fragment-case">fragment case</a>), or, if the
1.91      mike     2228:   <a href="#content-model-flag">content model flag</a> is set to the RCDATA or RAWTEXT states
1.1       mike     2229:   and the next few characters do not match the tag name of the last
                   2230:   start tag token emitted (compared in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2231:   case-insensitive</a> manner), or if they do but they are not
                   2232:   immediately followed by one of the following characters:</p>
                   2233: 
                   2234:   <ul class="brief"><li>U+0009 CHARACTER TABULATION</li>
                   2235:    <li>U+000A LINE FEED (LF)</li>
                   2236:    <li>U+000C FORM FEED (FF)</li>
                   2237:    <!--<li>U+000D CARRIAGE RETURN (CR)</li>-->
                   2238:    <li>U+0020 SPACE</li>
                   2239:    <li>U+003E GREATER-THAN SIGN (&gt;)</li>
                   2240:    <li>U+002F SOLIDUS (/)</li>
                   2241:    <li>EOF</li>
                   2242:   </ul><p>...then emit a U+003C LESS-THAN SIGN character token, a U+002F
                   2243:   SOLIDUS character token, and switch to the <a href="#data-state">data state</a>
                   2244:   to process the <a href="#next-input-character">next input character</a>.</p>
                   2245: 
                   2246:   <p>Otherwise, if the <a href="#content-model-flag">content model flag</a> is set to the
                   2247:   PCDATA state, or if the next few characters <em>do</em> match that tag
                   2248:   name, consume the <a href="#next-input-character">next input character</a>:</p>
                   2249: 
                   2250:   <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2251:    <dd>Create a new end tag token, set its tag name to the lowercase
                   2252:    version of the input character (add 0x0020 to the character's
                   2253:    code point), then switch to the <a href="#tag-name-state">tag name
                   2254:    state</a>. (Don't emit the token yet; further details will be
                   2255:    filled in before it is emitted.)</dd>
                   2256: 
                   2257:    <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2258:    <dd>Create a new end tag token, set its tag name to the input
                   2259:    character, then switch to the <a href="#tag-name-state">tag name state</a>. (Don't
                   2260:    emit the token yet; further details will be filled in before it
                   2261:    is emitted.)</dd>
                   2262: 
                   2263:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2264:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
                   2265:    state</a>.</dd>
                   2266: 
                   2267:    <dt>EOF</dt>
                   2268:    <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2269:    character token and a U+002F SOLIDUS character token. Reconsume
                   2270:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2271: 
                   2272:    <dt>Anything else</dt>
                   2273:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2274:    comment state</a>.</dd>
                   2275: 
                   2276:   </dl><h5 id="tag-name-state"><span class="secno">9.2.4.5 </span><dfn>Tag name state</dfn></h5>
                   2277: 
                   2278:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2279: 
                   2280:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2281:    <dt>U+000A LINE FEED (LF)</dt>
                   2282:    <dt>U+000C FORM FEED (FF)</dt>
                   2283:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2284:    <dt>U+0020 SPACE</dt>
                   2285:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2286: 
                   2287:    <dt>U+002F SOLIDUS (/)</dt>
                   2288:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2289: 
                   2290:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2291:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2292:    state</a>.</dd>
                   2293: 
                   2294:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2295:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2296:    (add 0x0020 to the character's code point) to the current tag
                   2297:    token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2298: 
                   2299:    <dt>EOF</dt>
                   2300:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2301:    <a href="#data-state">data state</a>.</dd>
                   2302: 
                   2303:    <dt>Anything else</dt>
                   2304:    <dd>Append the <a href="#current-input-character">current input character</a> to the current tag token's
                   2305:    tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2306: 
                   2307:   </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.6 </span><dfn>Before attribute name state</dfn></h5>
                   2308: 
                   2309:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2310: 
                   2311:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2312:    <dt>U+000A LINE FEED (LF)</dt>
                   2313:    <dt>U+000C FORM FEED (FF)</dt>
                   2314:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2315:    <dt>U+0020 SPACE</dt>
                   2316:    <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2317: 
                   2318:    <dt>U+002F SOLIDUS (/)</dt>
                   2319:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2320: 
                   2321:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2322:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2323:    state</a>.</dd>
                   2324: 
                   2325:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2326:    <dd>Start a new attribute in the current tag token. Set that
                   2327:    attribute's name to the lowercase version of the <a href="#current-input-character">current input
                   2328:    character</a> (add 0x0020 to the character's code point), and its
                   2329:    value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2330:    state</a>.</dd>
                   2331: 
                   2332:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2333:    <dt>U+0027 APOSTROPHE (')</dt>
                   2334:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2335:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2336:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2337:    entry below.</dd>
                   2338: 
                   2339:    <dt>EOF</dt>
                   2340:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2341:    <a href="#data-state">data state</a>.</dd>
                   2342: 
                   2343:    <dt>Anything else</dt>
                   2344:    <dd>Start a new attribute in the current tag token. Set that
                   2345:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2346:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2347:    state</a>.</dd>
                   2348: 
                   2349:   </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.7 </span><dfn>Attribute name state</dfn></h5>
                   2350: 
                   2351:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2352: 
                   2353:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2354:    <dt>U+000A LINE FEED (LF)</dt>
                   2355:    <dt>U+000C FORM FEED (FF)</dt>
                   2356:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2357:    <dt>U+0020 SPACE</dt>
                   2358:    <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2359: 
                   2360:    <dt>U+002F SOLIDUS (/)</dt>
                   2361:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2362: 
                   2363:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2364:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2365: 
                   2366:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2367:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2368:    state</a>.</dd>
                   2369: 
                   2370:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2371:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2372:    (add 0x0020 to the character's code point) to the current
                   2373:    attribute's name. Stay in the <a href="#attribute-name-state">attribute name
                   2374:    state</a>.</dd>
                   2375: 
                   2376:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2377:    <dt>U+0027 APOSTROPHE (')</dt>
                   2378:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2379:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2380:    entry below.</dd>
                   2381: 
                   2382:    <dt>EOF</dt>
                   2383:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2384:    <a href="#data-state">data state</a>.</dd>
                   2385: 
                   2386:    <dt>Anything else</dt>
                   2387:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2388:    name. Stay in the <a href="#attribute-name-state">attribute name state</a>.</dd>
                   2389: 
                   2390:   </dl><p>When the user agent leaves the attribute name state (and before
                   2391:   emitting the tag token, if appropriate), the complete attribute's
                   2392:   name must be compared to the other attributes on the same token;
                   2393:   if there is already an attribute on the token with the exact same
                   2394:   name, then this is a <a href="#parse-error">parse error</a> and the new
                   2395:   attribute must be dropped, along with the value that gets
                   2396:   associated with it (if any).</p>
                   2397: 
                   2398: 
                   2399:   <h5 id="after-attribute-name-state"><span class="secno">9.2.4.8 </span><dfn>After attribute name state</dfn></h5>
                   2400: 
                   2401:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2402: 
                   2403:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2404:    <dt>U+000A LINE FEED (LF)</dt>
                   2405:    <dt>U+000C FORM FEED (FF)</dt>
                   2406:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2407:    <dt>U+0020 SPACE</dt>
                   2408:    <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2409: 
                   2410:    <dt>U+002F SOLIDUS (/)</dt>
                   2411:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2412: 
                   2413:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2414:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2415: 
                   2416:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2417:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2418:    state</a>.</dd>
                   2419: 
                   2420:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2421:    <dd>Start a new attribute in the current tag token. Set that
                   2422:    attribute's name to the lowercase version of the <a href="#current-input-character">current input character</a>
                   2423:    (add 0x0020 to the character's code point), and its value to
                   2424:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2425:    state</a>.</dd>
                   2426: 
                   2427:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2428:    <dt>U+0027 APOSTROPHE (')</dt>
                   2429:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2430:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2431:    entry below.</dd>
                   2432: 
                   2433:    <dt>EOF</dt>
                   2434:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2435:    <a href="#data-state">data state</a>.</dd>
                   2436: 
                   2437:    <dt>Anything else</dt>
                   2438:    <dd>Start a new attribute in the current tag token. Set that
                   2439:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2440:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2441:    state</a>.</dd>
                   2442: 
                   2443:   </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.9 </span><dfn>Before attribute value state</dfn></h5>
                   2444: 
                   2445:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2446: 
                   2447:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2448:    <dt>U+000A LINE FEED (LF)</dt>
                   2449:    <dt>U+000C FORM FEED (FF)</dt>
                   2450:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2451:    <dt>U+0020 SPACE</dt>
                   2452:    <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2453: 
                   2454:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2455:    <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
                   2456: 
                   2457:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2458:    <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
                   2459:    and reconsume this input character.</dd>
                   2460: 
                   2461:    <dt>U+0027 APOSTROPHE (')</dt>
                   2462:    <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
                   2463: 
                   2464:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2465:    <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
                   2466:    the <a href="#data-state">data state</a>.</dd>
                   2467: 
                   2468:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2469:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2470:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2471:    entry below.</dd>
                   2472: 
                   2473:    <dt>EOF</dt>
                   2474:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2475:    <a href="#data-state">data state</a>.</dd>
                   2476: 
                   2477:    <dt>Anything else</dt>
                   2478:    <dd>Append the <a href="#current-input-character">current input character</a> to the current
                   2479:    attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2480:    state</a>.</dd>
                   2481: 
                   2482:   </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.10 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
                   2483: 
                   2484:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2485: 
                   2486:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2487:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2488:    state</a>.</dd>
                   2489: 
                   2490:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2491:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2492:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2493:    being U+0022 QUOTATION MARK (").</dd>
                   2494: 
                   2495:    <dt>EOF</dt>
                   2496:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2497:    <a href="#data-state">data state</a>.</dd>
                   2498: 
                   2499:    <dt>Anything else</dt>
                   2500:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2501:    value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted)
                   2502:    state</a>.</dd>
                   2503: 
                   2504:   </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.11 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
                   2505: 
                   2506:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2507: 
                   2508:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   2509:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2510:    state</a>.</dd>
                   2511: 
                   2512:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2513:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2514:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2515:    being U+0027 APOSTROPHE (').</dd>
                   2516: 
                   2517:    <dt>EOF</dt>
                   2518:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2519:    <a href="#data-state">data state</a>.</dd>
                   2520: 
                   2521:    <dt>Anything else</dt>
                   2522:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2523:    value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted)
                   2524:    state</a>.</dd>
                   2525: 
                   2526:   </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.12 </span><dfn>Attribute value (unquoted) state</dfn></h5>
                   2527: 
                   2528:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2529: 
                   2530:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2531:    <dt>U+000A LINE FEED (LF)</dt>
                   2532:    <dt>U+000C FORM FEED (FF)</dt>
                   2533:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2534:    <dt>U+0020 SPACE</dt>
                   2535:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2536: 
                   2537:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2538:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2539:    state</a>, with no <a href="#additional-allowed-character">additional allowed
                   2540:    character</a>.</dd>
                   2541: 
                   2542:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2543:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2544:    state</a>.</dd>
                   2545: 
                   2546:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2547:    <dt>U+0027 APOSTROPHE (')</dt>
                   2548:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2549:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2550:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2551:    entry below.</dd>
                   2552: 
                   2553:    <dt>EOF</dt>
                   2554:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2555:    <a href="#data-state">data state</a>.</dd>
                   2556: 
                   2557:    <dt>Anything else</dt>
                   2558:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2559:    value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2560:    state</a>.</dd>
                   2561: 
                   2562:   </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>
                   2563: 
                   2564:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
                   2565: 
                   2566:   <p>If nothing is returned, append a U+0026 AMPERSAND character to
                   2567:   the current attribute's value.</p>
                   2568: 
                   2569:   <p>Otherwise, append the returned character token to the current
                   2570:   attribute's value.</p>
                   2571: 
                   2572:   <p>Finally, switch back to the attribute value state that you were
                   2573:   in when were switched into this state.</p>
                   2574: 
                   2575: 
                   2576:   <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.14 </span><dfn>After attribute value (quoted) state</dfn></h5>
                   2577: 
                   2578:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2579: 
                   2580:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2581:    <dt>U+000A LINE FEED (LF)</dt>
                   2582:    <dt>U+000C FORM FEED (FF)</dt>
                   2583:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2584:    <dt>U+0020 SPACE</dt>
                   2585:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2586: 
                   2587:    <dt>U+002F SOLIDUS (/)</dt>
                   2588:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2589: 
                   2590:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2591:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2592:    state</a>.</dd>
                   2593: 
                   2594:    <dt>EOF</dt>
                   2595:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2596:    <a href="#data-state">data state</a>.</dd>
                   2597: 
                   2598:    <dt>Anything else</dt>
                   2599:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2600:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2601: 
                   2602:   </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.15 </span><dfn>Self-closing start tag state</dfn></h5>
                   2603: 
                   2604:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2605: 
                   2606:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2607:    <dd>Set the <i>self-closing flag</i> of the current tag
                   2608:    token. Emit the current tag token. Switch to the <a href="#data-state">data
                   2609:    state</a>.</dd>
                   2610: 
                   2611:    <dt>EOF</dt>
                   2612:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2613:    <a href="#data-state">data state</a>.</dd>
                   2614: 
                   2615:    <dt>Anything else</dt>
                   2616:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2617:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2618: 
                   2619:   </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.16 </span><dfn>Bogus comment state</dfn></h5>
                   2620: 
                   2621:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2622:   flag</a> is set to the PCDATA state.)</i></p>
                   2623: 
                   2624:   <p>Consume every character up to and including the first U+003E
                   2625:   GREATER-THAN SIGN character (&gt;) or the end of the file (EOF),
                   2626:   whichever comes first. Emit a comment token whose data is the
                   2627:   concatenation of all the characters starting from and including
                   2628:   the character that caused the state machine to switch into the
                   2629:   bogus comment state, up to and including the character immediately
                   2630:   before the last consumed character (i.e. up to the character just
                   2631:   before the U+003E or EOF character). (If the comment was started
                   2632:   by the end of the file (EOF), the token is empty.)</p>
                   2633: 
                   2634:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   2635: 
                   2636:   <p>If the end of the file was reached, reconsume the EOF
                   2637:   character.</p>
                   2638: 
                   2639: 
                   2640:   <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.17 </span><dfn>Markup declaration open state</dfn></h5>
                   2641: 
                   2642:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2643:   flag</a> is set to the PCDATA state.)</i></p>
                   2644: 
                   2645:   <p>If the next two characters are both U+002D HYPHEN-MINUS (-)
                   2646:   characters, consume those two characters, create a comment token
                   2647:   whose data is the empty string, and switch to the <a href="#comment-start-state">comment
                   2648:   start state</a>.</p>
                   2649: 
                   2650:   <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2651:   case-insensitive</a> match for the word "DOCTYPE", then consume
                   2652:   those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
                   2653: 
                   2654:   <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
                   2655:   content</a>" and the <a href="#current-node">current node</a> is not an element
                   2656:   in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
                   2657:   an <span>ASCII case-sensitive</span> match for the string "[CDATA["
                   2658:   (the five uppercase letters "CDATA" with a U+005B LEFT SQUARE
                   2659:   BRACKET character before and after), then consume those characters
1.91      mike     2660:   and switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1       mike     2661: 
                   2662:   <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
                   2663:   <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
                   2664:   consumed, if any, is the first character that will be in the
                   2665:   comment.</p>
                   2666: 
                   2667: 
                   2668:   <h5 id="comment-start-state"><span class="secno">9.2.4.18 </span><dfn>Comment start state</dfn></h5>
                   2669: 
                   2670:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2671: 
                   2672:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2673:    <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
                   2674: 
                   2675:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2676:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
                   2677:    <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
                   2678:    -->
                   2679: 
                   2680:    <dt>EOF</dt>
                   2681:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2682:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2683: 
                   2684:    <dt>Anything else</dt>
                   2685:    <dd>Append the input character to the comment token's
                   2686:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2687: 
                   2688:   </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.19 </span><dfn>Comment start dash state</dfn></h5>
                   2689: 
                   2690:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2691: 
                   2692:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2693:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2694: 
                   2695:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2696:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
                   2697:    the <a href="#data-state">data state</a>.</dd>
                   2698: 
                   2699:    <dt>EOF</dt>
                   2700:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2701:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2702:    in comment end state -->
                   2703: 
                   2704:    <dt>Anything else</dt>
                   2705:    <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
                   2706:    character to the comment token's data. Switch to the
                   2707:    <a href="#comment-state">comment state</a>.</dd>
                   2708: 
                   2709:   </dl><h5 id="comment-state"><span class="secno">9.2.4.20 </span><dfn id="comment">Comment state</dfn></h5>
                   2710: 
                   2711:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2712: 
                   2713:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2714:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
                   2715: 
                   2716:    <dt>EOF</dt>
                   2717:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2718:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2719:    in comment end state -->
                   2720: 
                   2721:    <dt>Anything else</dt>
                   2722:    <dd>Append the input character to the comment token's data. Stay
                   2723:    in the <a href="#comment-state">comment state</a>.</dd>
                   2724: 
                   2725:   </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.21 </span><dfn>Comment end dash state</dfn></h5>
                   2726: 
                   2727:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2728: 
                   2729:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2730:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2731: 
                   2732:    <dt>EOF</dt>
                   2733:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2734:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2735:    in comment end state -->
                   2736: 
                   2737:    <dt>Anything else</dt>
                   2738:    <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
                   2739:    character to the comment token's data. Switch to the
                   2740:    <a href="#comment-state">comment state</a>.</dd>
                   2741: 
                   2742:   </dl><h5 id="comment-end-state"><span class="secno">9.2.4.22 </span><dfn>Comment end state</dfn></h5>
                   2743: 
                   2744:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2745: 
                   2746:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2747:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2748:    state</a>.</dd>
                   2749: 
                   2750:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2751:    <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
                   2752:    (-) character to the comment token's data. Stay in the
                   2753:    <a href="#comment-end-state">comment end state</a>.</dd>
                   2754: 
                   2755:    <dt>U+0009 CHARACTER TABULATION</dt>
                   2756:    <dt>U+000A LINE FEED (LF)</dt>
                   2757:    <dt>U+000C FORM FEED (FF)</dt>
                   2758:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2759:    <dt>U+0020 SPACE</dt>
                   2760:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2761:    characters and the input character to the comment token's
                   2762:    data. Switch to the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2763: 
                   2764:    <dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2765:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
                   2766:    state</a>.</dd>
                   2767: 
                   2768:    <dt>EOF</dt>
                   2769:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2770:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
                   2771:    security reasons: otherwise, hostile user could put a <script> in
                   2772:    a comment e.g. in a blog comment and then DOS the server so that
                   2773:    the end tag isn't read, and then the commented <script> tag would
                   2774:    be treated as live code -->
                   2775: 
                   2776:    <dt>Anything else</dt>
                   2777:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2778:    characters and the input character to the comment token's
                   2779:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2780: 
                   2781:   </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.23 </span><dfn>Comment end bang state</dfn></h5>
                   2782: 
                   2783:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2784: 
                   2785:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2786:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2787:    state</a>.</dd>
                   2788: 
                   2789:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2790:    <dd>Append two U+002D HYPHEN-MINUS (-) characters and a U+0021
                   2791:    EXCLAMATION MARK (!) character to the comment token's data. Switch
                   2792:    to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2793: 
                   2794:    <dt>EOF</dt>
                   2795:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2796:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2797:    comment in comment end state -->
                   2798: 
                   2799:    <dt>Anything else</dt>
                   2800:    <dd>Append two U+002D HYPHEN-MINUS (-) characters, a U+0021
                   2801:    EXCLAMATION MARK (!) character, and the input character to the
                   2802:    comment token's data. Switch to the <a href="#comment-state">comment
                   2803:    state</a>.</dd>
                   2804: 
                   2805:   </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.24 </span><dfn>Comment end space state</dfn></h5>
                   2806: 
                   2807:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2808: 
                   2809:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2810:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2811:    state</a>.</dd>
                   2812: 
                   2813:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2814:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2815: 
                   2816:    <dt>U+0009 CHARACTER TABULATION</dt>
                   2817:    <dt>U+000A LINE FEED (LF)</dt>
                   2818:    <dt>U+000C FORM FEED (FF)</dt>
                   2819:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2820:    <dt>U+0020 SPACE</dt>
                   2821:    <dd>Append the input character to the comment token's data. Stay in
                   2822:    the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2823: 
                   2824:    <dt>EOF</dt>
                   2825:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2826:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2827:    comment in comment end state -->
                   2828: 
                   2829:    <dt>Anything else</dt>
                   2830:    <dd>Append the input character to the comment token's data. Switch
                   2831:    to the <a href="#comment-state">comment state</a>.</dd>
                   2832: 
                   2833:   </dl><h5 id="doctype-state"><span class="secno">9.2.4.25 </span><dfn>DOCTYPE state</dfn></h5>
                   2834: 
                   2835:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2836: 
                   2837:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2838:    <dt>U+000A LINE FEED (LF)</dt>
                   2839:    <dt>U+000C FORM FEED (FF)</dt>
                   2840:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2841:    <dt>U+0020 SPACE</dt>
                   2842:    <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2843: 
                   2844:    <dt>EOF</dt>
                   2845:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2846:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2847:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2848: 
                   2849:    <dt>Anything else</dt>
                   2850:    <dd><a href="#parse-error">Parse error</a>. Reconsume the current
                   2851:    character in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2852: 
                   2853:   </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.26 </span><dfn>Before DOCTYPE name state</dfn></h5>
                   2854: 
                   2855:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2856: 
                   2857:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2858:    <dt>U+000A LINE FEED (LF)</dt>
                   2859:    <dt>U+000C FORM FEED (FF)</dt>
                   2860:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2861:    <dt>U+0020 SPACE</dt>
                   2862:    <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2863: 
                   2864:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2865:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2866:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
                   2867:    the <a href="#data-state">data state</a>.</dd>
                   2868: 
                   2869:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2870:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2871:    lowercase version of the input character (add 0x0020 to the
                   2872:    character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2873:    state</a>.</dd>
                   2874: 
                   2875:    <dt>EOF</dt>
                   2876:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2877:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2878:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2879: 
                   2880:    <dt>Anything else</dt>
                   2881:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2882:    <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2883:    state</a>.</dd>
                   2884: 
                   2885:   </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.27 </span><dfn>DOCTYPE name state</dfn></h5>
                   2886: 
                   2887:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2888: 
                   2889:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2890:    <dt>U+000A LINE FEED (LF)</dt>
                   2891:    <dt>U+000C FORM FEED (FF)</dt>
                   2892:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2893:    <dt>U+0020 SPACE</dt>
                   2894:    <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   2895: 
                   2896:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2897:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2898:    state</a>.</dd>
                   2899: 
                   2900:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2901:    <dd>Append the lowercase version of the input character (add 0x0020
                   2902:    to the character's code point) to the current DOCTYPE token's
                   2903:    name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   2904: 
                   2905:    <dt>EOF</dt>
                   2906:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2907:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2908:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2909: 
                   2910:    <dt>Anything else</dt>
                   2911:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2912:    token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   2913: 
                   2914:   </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.28 </span><dfn>After DOCTYPE name state</dfn></h5>
                   2915: 
                   2916:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2917: 
                   2918:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2919:    <dt>U+000A LINE FEED (LF)</dt>
                   2920:    <dt>U+000C FORM FEED (FF)</dt>
                   2921:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2922:    <dt>U+0020 SPACE</dt>
                   2923:    <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   2924: 
                   2925:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2926:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2927:    state</a>.</dd>
                   2928: 
                   2929:    <dt>EOF</dt>
                   2930:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2931:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2932:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2933: 
                   2934:    <dt>Anything else</dt>
                   2935:    <dd>
                   2936: 
                   2937:     <p>If the six characters starting from the <a href="#current-input-character">current input
                   2938:     character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
                   2939:     for the word "PUBLIC", then consume those characters and switch to
                   2940:     the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</p>
                   2941: 
                   2942:     <p>Otherwise, if the six characters starting from the
                   2943:     <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2944:     case-insensitive</a> match for the word "SYSTEM", then consume
                   2945:     those characters and switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system
                   2946:     identifier state</a>.</p>
                   2947: 
                   2948:     <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
                   2949:     DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
                   2950:     the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
                   2951: 
                   2952:    </dd>
                   2953: 
                   2954:   </dl><h5 id="before-doctype-public-identifier-state"><span class="secno">9.2.4.29 </span><dfn>Before DOCTYPE public identifier state</dfn></h5>
                   2955: 
                   2956:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2957: 
                   2958:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2959:    <dt>U+000A LINE FEED (LF)</dt>
                   2960:    <dt>U+000C FORM FEED (FF)</dt>
                   2961:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2962:    <dt>U+0020 SPACE</dt>
                   2963:    <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
                   2964: 
                   2965:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2966:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   2967:    (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
                   2968:    (double-quoted) state</a>.</dd>
                   2969: 
                   2970:    <dt>U+0027 APOSTROPHE (')</dt>
                   2971:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   2972:    (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
                   2973:    (single-quoted) state</a>.</dd>
                   2974: 
                   2975:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2976:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2977:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2978:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2979: 
                   2980:    <dt>EOF</dt>
                   2981:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2982:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2983:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2984: 
                   2985:    <dt>Anything else</dt>
                   2986:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2987:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   2988:    DOCTYPE state</a>.</dd>
                   2989: 
                   2990:   </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>
                   2991: 
                   2992:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2993: 
                   2994:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2995:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   2996: 
                   2997:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2998:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2999:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3000:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3001: 
                   3002:    <dt>EOF</dt>
                   3003:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3004:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3005:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3006: 
                   3007:    <dt>Anything else</dt>
                   3008:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3009:    token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
                   3010:    identifier (double-quoted) state</a>.</dd>
                   3011: 
                   3012:   </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>
                   3013: 
                   3014:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3015: 
                   3016:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   3017:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   3018: 
                   3019:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3020:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3021:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3022:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3023: 
                   3024:    <dt>EOF</dt>
                   3025:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3026:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3027:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3028: 
                   3029:    <dt>Anything else</dt>
                   3030:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3031:    token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
                   3032:    identifier (single-quoted) state</a>.</dd>
                   3033: 
                   3034:   </dl><h5 id="after-doctype-public-identifier-state"><span class="secno">9.2.4.32 </span><dfn>After DOCTYPE public identifier state</dfn></h5>
                   3035: 
                   3036:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3037: 
                   3038:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3039:    <dt>U+000A LINE FEED (LF)</dt>
                   3040:    <dt>U+000C FORM FEED (FF)</dt>
                   3041:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3042:    <dt>U+0020 SPACE</dt>
                   3043:    <dd>Stay in the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   3044: 
                   3045:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3046:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3047:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   3048:    (double-quoted) state</a>.</dd>
                   3049: 
                   3050:    <dt>U+0027 APOSTROPHE (')</dt>
                   3051:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3052:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   3053:    (single-quoted) state</a>.</dd>
                   3054: 
                   3055:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3056:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3057:    state</a>.</dd>
                   3058: 
                   3059:    <dt>EOF</dt>
                   3060:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3061:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3062:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3063: 
                   3064:    <dt>Anything else</dt>
                   3065:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3066:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3067:    DOCTYPE state</a>.</dd>
                   3068: 
                   3069:   </dl><h5 id="before-doctype-system-identifier-state"><span class="secno">9.2.4.33 </span><dfn>Before DOCTYPE system identifier state</dfn></h5>
                   3070: 
                   3071:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3072: 
                   3073:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3074:    <dt>U+000A LINE FEED (LF)</dt>
                   3075:    <dt>U+000C FORM FEED (FF)</dt>
                   3076:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3077:    <dt>U+0020 SPACE</dt>
                   3078:    <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
                   3079: 
                   3080:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3081:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3082:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   3083:    (double-quoted) state</a>.</dd>
                   3084: 
                   3085:    <dt>U+0027 APOSTROPHE (')</dt>
                   3086:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3087:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   3088:    (single-quoted) state</a>.</dd>
                   3089: 
                   3090:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3091:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3092:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3093:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3094: 
                   3095:    <dt>EOF</dt>
                   3096:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3097:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3098:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3099: 
                   3100:    <dt>Anything else</dt>
                   3101:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3102:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3103:    DOCTYPE state</a>.</dd>
                   3104: 
                   3105:   </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>
                   3106: 
                   3107:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3108: 
                   3109:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   3110:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3111: 
                   3112:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3113:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3114:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3115:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3116: 
                   3117:    <dt>EOF</dt>
                   3118:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3119:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3120:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3121: 
                   3122:    <dt>Anything else</dt>
                   3123:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3124:    token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
                   3125:    identifier (double-quoted) state</a>.</dd>
                   3126: 
                   3127:   </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>
                   3128: 
                   3129:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3130: 
                   3131:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   3132:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3133: 
                   3134:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3135:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3136:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3137:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3138: 
                   3139:    <dt>EOF</dt>
                   3140:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3141:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3142:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3143: 
                   3144:    <dt>Anything else</dt>
                   3145:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3146:    token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
                   3147:    identifier (single-quoted) state</a>.</dd>
                   3148: 
                   3149:   </dl><h5 id="after-doctype-system-identifier-state"><span class="secno">9.2.4.36 </span><dfn>After DOCTYPE system identifier state</dfn></h5>
                   3150: 
                   3151:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3152: 
                   3153:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3154:    <dt>U+000A LINE FEED (LF)</dt>
                   3155:    <dt>U+000C FORM FEED (FF)</dt>
                   3156:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3157:    <dt>U+0020 SPACE</dt>
                   3158:    <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3159: 
                   3160:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3161:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3162:    state</a>.</dd>
                   3163: 
                   3164:    <dt>EOF</dt>
                   3165:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3166:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3167:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3168: 
                   3169:    <dt>Anything else</dt>
                   3170:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
                   3171:    state</a>. (This does <em>not</em> set the DOCTYPE token's
                   3172:    <i>force-quirks flag</i> to <i>on</i>.)</dd>
                   3173: 
                   3174:   </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.37 </span><dfn>Bogus DOCTYPE state</dfn></h5>
                   3175: 
                   3176:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3177: 
                   3178:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3179:    <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
                   3180:    state</a>.</dd>
                   3181: 
                   3182:    <dt>EOF</dt>
                   3183:    <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
                   3184:    <a href="#data-state">data state</a>.</dd>
                   3185: 
                   3186:    <dt>Anything else</dt>
                   3187:    <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
                   3188: 
                   3189:   </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.38 </span><dfn>CDATA section state</dfn></h5>
                   3190: 
                   3191:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
1.91      mike     3192:   flag</a> is set to the PCDATA state.)</i></p>
1.1       mike     3193: 
                   3194:   <p>Consume every character up to the next occurrence of the three
                   3195:   character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
                   3196:   BRACKET U+003E GREATER-THAN SIGN (<code title="">]]&gt;</code>), or the
                   3197:   end of the file (EOF), whichever comes first. Emit a series of
                   3198:   character tokens consisting of all the characters consumed except
                   3199:   the matching three character sequence at the end (if one was found
                   3200:   before the end of the file).</p>
                   3201: 
                   3202:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   3203: 
                   3204:   <p>If the end of the file was reached, reconsume the EOF
                   3205:   character.</p>
                   3206: 
                   3207: 
                   3208: 
                   3209:   <h5 id="tokenizing-character-references"><span class="secno">9.2.4.39 </span>Tokenizing character references</h5>
                   3210: 
                   3211:   <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
                   3212:   reference</dfn>. This definition is used when parsing character
                   3213:   references <a href="#character-reference-data-state" title="character reference data state">in
                   3214:   text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
                   3215:   state">in attributes</a>.</p>
                   3216: 
                   3217:   <p>The behavior depends on the identity of the next character (the
                   3218:   one immediately after the U+0026 AMPERSAND character):</p>
                   3219: 
                   3220:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3221:    <dt>U+000A LINE FEED (LF)</dt>
                   3222:    <dt>U+000C FORM FEED (FF)</dt>
                   3223:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3224:    <dt>U+0020 SPACE</dt>
                   3225:    <dt>U+003C LESS-THAN SIGN</dt>
                   3226:    <dt>U+0026 AMPERSAND</dt>
                   3227:    <dt>EOF</dt>
                   3228:    <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
                   3229: 
                   3230:    <dd>Not a character reference. No characters are consumed, and
                   3231:    nothing is returned. (This is not an error, either.)</dd>
                   3232: 
                   3233: 
                   3234:    <dt>U+0023 NUMBER SIGN (#)</dt>
                   3235: 
                   3236:    <dd>
                   3237: 
                   3238:     <p>Consume the U+0023 NUMBER SIGN.</p>
                   3239: 
                   3240:     <p>The behavior further depends on the character after the U+0023
                   3241:     NUMBER SIGN:</p>
                   3242: 
                   3243:     <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
                   3244:      <dt>U+0058 LATIN CAPITAL LETTER X</dt>
                   3245: 
                   3246:      <dd>
                   3247: 
                   3248:       <p>Consume the X.</p>
                   3249: 
                   3250:       <p>Follow the steps below, but using the range of characters
                   3251:       U+0030 DIGIT ZERO through to U+0039 DIGIT NINE, U+0061 LATIN
                   3252:       SMALL LETTER A through to U+0066 LATIN SMALL LETTER F, and
                   3253:       U+0041 LATIN CAPITAL LETTER A, through to U+0046 LATIN CAPITAL
                   3254:       LETTER F (in other words, 0-9, A-F, a-f).</p>
                   3255: 
                   3256:       <p>When it comes to interpreting the number, interpret it as a
                   3257:       hexadecimal number.</p>
                   3258: 
                   3259:      </dd>
                   3260: 
                   3261: 
                   3262:      <dt>Anything else</dt>
                   3263: 
                   3264:      <dd>
                   3265: 
                   3266:       <p>Follow the steps below, but using the range of characters
                   3267:       U+0030 DIGIT ZERO through to U+0039 DIGIT NINE (i.e. just
                   3268:       0-9).</p>
                   3269: 
                   3270:       <p>When it comes to interpreting the number, interpret it as a
                   3271:       decimal number.</p>
                   3272: 
                   3273:      </dd>
                   3274: 
                   3275:     </dl><p>Consume as many characters as match the range of characters
                   3276:     given above.</p>
                   3277: 
                   3278:     <p>If no characters match the range, then don't consume any
                   3279:     characters (and unconsume the U+0023 NUMBER SIGN character and, if
                   3280:     appropriate, the X character). This is a <a href="#parse-error">parse
                   3281:     error</a>; nothing is returned.</p>
                   3282: 
                   3283:     <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
                   3284:     that too. If it isn't, there is a <a href="#parse-error">parse
                   3285:     error</a>.</p>
                   3286: 
                   3287:     <p>If one or more characters match the range, then take them all
                   3288:     and interpret the string of characters as a number (either
                   3289:     hexadecimal or decimal as appropriate).</p>
                   3290: 
                   3291:     <p>If that number is one of the numbers in the first column of the
                   3292:     following table, then this is a <a href="#parse-error">parse error</a>. Find the
                   3293:     row with that number in the first column, and return a character
                   3294:     token for the Unicode character given in the second column of that
                   3295:     row.</p>
                   3296: 
                   3297:     <table><thead><tr><th>Number </th><th colspan="2">Unicode character
                   3298:      </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
                   3299:       </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
                   3300:       </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN ('&#8364;')
                   3301:       </td></tr><tr><td>0x81 </td><td>U+0081 </td><td>&lt;control&gt;
                   3302:       </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK ('&#8218;')
                   3303:       </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK ('&#402;')
                   3304:       </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK ('&#8222;')
                   3305:       </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS ('&#8230;')
                   3306:       </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER ('&#8224;')
                   3307:       </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER ('&#8225;')
                   3308:       </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT ('&#710;')
                   3309:       </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN ('&#8240;')
                   3310:       </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON ('&#352;')
                   3311:       </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK ('&#8249;')
                   3312:       </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE ('&#338;')
                   3313:       </td></tr><tr><td>0x8D </td><td>U+008D </td><td>&lt;control&gt;
                   3314:       </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON ('&#381;')
                   3315:       </td></tr><tr><td>0x8F </td><td>U+008F </td><td>&lt;control&gt;
                   3316:       </td></tr><tr><td>0x90 </td><td>U+0090 </td><td>&lt;control&gt;
                   3317:       </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK ('&#8216;')
                   3318:       </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK ('&#8217;')
                   3319:       </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK ('&#8220;')
                   3320:       </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK ('&#8221;')
                   3321:       </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET ('&#8226;')
                   3322:       </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH ('&#8211;')
                   3323:       </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH ('&#8212;')
                   3324:       </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE ('&#732;')
                   3325:       </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN ('&#8482;')
                   3326:       </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON ('&#353;')
                   3327:       </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK ('&#8250;')
                   3328:       </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE ('&#339;')
                   3329:       </td></tr><tr><td>0x9D </td><td>U+009D </td><td>&lt;control&gt;
                   3330:       </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON ('&#382;')
                   3331:       </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS ('&#376;')
1.18      mike     3332:     </td></tr></tbody></table><p>Otherwise, if the number is greater than 0x10FFFF, then this is
                   3333:     a <a href="#parse-error">parse error</a>. Return a U+FFFD REPLACEMENT
                   3334:     CHARACTER.</p>
                   3335: 
                   3336:     <p>Otherwise, return a character token for the Unicode character
1.1       mike     3337:     whose code point is that number.
                   3338: 
                   3339:     <!-- this is the same as the equivalent list in the input stream
                   3340:     section -->
                   3341:     If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
                   3342:     allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
                   3343:     allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
                   3344:     0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xD800 to
                   3345:     0xDFFF<!-- surrogates not allowed -->, 0xFDD0 to 0xFDEF, or is one
                   3346:     of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF,
                   3347:     0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF, 0x6FFFE,
                   3348:     0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE, 0x9FFFF,
                   3349:     0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE,
                   3350:     0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF, 0x10FFFE, or
1.18      mike     3351:     0x10FFFF, then this is a <a href="#parse-error">parse error</a>.</p>
1.1       mike     3352: 
                   3353:    </dd>
                   3354: 
                   3355: 
                   3356:    <dt>Anything else</dt>
                   3357: 
                   3358:    <dd>
                   3359: 
                   3360:     <p>Consume the maximum number of characters possible, with the
                   3361:     consumed characters matching one of the identifiers in the first
                   3362:     column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
                   3363:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
                   3364: 
                   3365:     <p>If no match can be made, then this is a <a href="#parse-error">parse
                   3366:     error</a>. No characters are consumed, and nothing is
                   3367:     returned.</p>
                   3368: 
                   3369:     <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>
                   3370: 
                   3371:     <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
                   3372:     attribute</a>, and the last character matched is not a U+003B
                   3373:     SEMICOLON (<code title="">;</code>), and the next character is in
                   3374:     the range U+0030 DIGIT ZERO to U+0039 DIGIT NINE, U+0041 LATIN
                   3375:     CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z, or U+0061 LATIN
                   3376:     SMALL LETTER A to U+007A LATIN SMALL LETTER Z, then, for
                   3377:     historical reasons, all the characters that were matched after the
                   3378:     U+0026 AMPERSAND (&amp;) must be unconsumed, and nothing is
                   3379:     returned.</p>
                   3380: 
                   3381:     <p>Otherwise, return a character token for the character
                   3382:     corresponding to the character reference name (as given by the
                   3383:     second column of the <a href="named-character-references.html#named-character-references">named character references</a>
                   3384:     table).</p>
                   3385: 
                   3386:     <div class="example">
                   3387: 
                   3388:      <p>If the markup contains <code title="">I'm &amp;notit; I tell
                   3389:      you</code>, the character reference is parsed as "not", as in,
                   3390:      <code title="">I'm &#172;it; I tell you</code>. But if the markup
                   3391:      was <code title="">I'm &amp;notin; I tell you</code>, the
                   3392:      character reference would be parsed as "notin;", resulting in
                   3393:      <code title="">I'm &#8713; I tell you</code>.</p>
                   3394: 
                   3395:     </div>
                   3396: 
                   3397:    </dd>
                   3398: 
                   3399:   </dl><h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4>
                   3400: 
                   3401:   <p>The input to the tree construction stage is a sequence of tokens
                   3402:   from the <a href="#tokenization">tokenization</a> stage. The tree construction
                   3403:   stage is associated with a DOM <code>Document</code> object when a
                   3404:   parser is created. The "output" of this stage consists of
                   3405:   dynamically modifying or extending that document's DOM tree.</p>
                   3406: 
                   3407:   <p>This specification does not define when an interactive user agent
                   3408:   has to render the <code>Document</code> so that it is available to
                   3409:   the user, or when it has to begin accepting user input.</p>
                   3410: 
                   3411:   <p>As each token is emitted from the tokenizer, the user agent must
                   3412:   process the token according to the rules given in the section
                   3413:   corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
                   3414: 
                   3415:   <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
                   3416:   character</dfn> into a node, if that node has a child immediately
                   3417:   before where the character is to be inserted, and that child is a
                   3418:   <code>Text</code> node, and that <code>Text</code> node was the last
                   3419:   node that the parser inserted into the document, then the character
                   3420:   must be appended to that <code>Text</code> node; otherwise, a new
                   3421:   <code>Text</code> node whose data is just that character must be
                   3422:   inserted in the appropriate place.</p>
                   3423: 
                   3424:   <div class="example">
                   3425: 
                   3426:    <p>Here are some sample inputs to the parser and the corresponding
                   3427:    number of text nodes that they result in, assuming a user agent
                   3428:    that executes scripts.</p>
                   3429: 
                   3430:    <table><thead><tr><th>Input </th><th>Number of text nodes
                   3431:     </th></tr></thead><tbody><tr><td><pre>A&lt;script&gt;
                   3432: var&#160;script&#160;=&#160;document.getElementsByTagName('script')[0];
                   3433: document.body.removeChild(script);
                   3434: &lt;/script&gt;B</pre>
                   3435:       </td><td>Two adjacent text nodes in the document, containing "A" and "B".
                   3436:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3437: var&#160;text&#160;=&#160;document.createTextNode('B');
                   3438: document.body.appendChild(text);
                   3439: &lt;/script&gt;C</pre>
                   3440:       </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
                   3441:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3442: var&#160;text&#160;=&#160;document.getElementsByTagName('script')[0].firstChild;
                   3443: text.data&#160;=&#160;'B';
                   3444: document.body.appendChild(text);
                   3445: &lt;/script&gt;B</pre>
                   3446:       </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
                   3447:      </td></tr><tr><td><pre>A&lt;table&gt;B&lt;tr&gt;C&lt;/tr&gt;C&lt;/table&gt;</pre>
                   3448:       </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>.)
                   3449:      </td></tr><tr><td><pre>A&lt;table&gt;&lt;tr&gt;&#160;B&lt;/tr&gt;&#160;B&lt;/table&gt;</pre>
                   3450:       </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>.)
                   3451:      </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>
                   3452:       </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.)
                   3453:    </td></tr></tbody></table></div>
                   3454: 
                   3455:   <p id="mutation-during-parsing">DOM mutation events must not fire
                   3456:   for changes caused by the UA parsing the document. (Conceptually,
                   3457:   the parser is not mutating the DOM, it is constructing it.) This
1.94      mike     3458:   includes the parsing of any content inserted using <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code> and <code title="dom-document-writeln"><a href="dom.html#dom-document-writeln">document.writeln()</a></code> calls. <a href="references.html#references">[DOMEVENTS]</a></p>
1.1       mike     3459: 
                   3460:   <p class="note">Not all of the tag names mentioned below are
                   3461:   conformant tag names in this specification; many are included to
                   3462:   handle legacy content. They still form part of the algorithm that
                   3463:   implementations are required to implement to claim conformance.</p>
                   3464: 
                   3465:   <p class="note">The algorithm described below places no limit on the
                   3466:   depth of the DOM tree generated, or on the length of tag names,
                   3467:   attribute names, attribute values, text nodes, etc. While
                   3468:   implementors are encouraged to avoid arbitrary limits, it is
                   3469:   recognized that <a href="infrastructure.html#hardwareLimitations">practical
                   3470:   concerns</a> will likely force user agents to impose nesting
                   3471:   depths.</p>
                   3472: 
                   3473: 
                   3474:   <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5>
                   3475: 
                   3476:   <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
                   3477:   element for the token">create an element for a token</dfn> in a
                   3478:   particular namespace, the UA must create a node implementing the
                   3479:   interface appropriate for the element type corresponding to the tag
                   3480:   name of the token in the given namespace (as given in the
                   3481:   specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
                   3482:   element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
                   3483:   defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
                   3484:   the tag name being the name of that element, with the node being in
                   3485:   the given namespace, and with the attributes on the node being those
                   3486:   given in the given token.</p>
                   3487: 
                   3488:   <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
                   3489:   namespace</a> that is not defined in this specification is
1.44      mike     3490:   <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1       mike     3491:   interface is not defined by that namespace's specification must use
                   3492:   the interface <code>Element</code>.</p>
                   3493: 
                   3494:   <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
                   3495:   created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
                   3496:   invoked once the attributes are set. (This initializes the element's
                   3497:   <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
                   3498:   attributes.)</p>
                   3499: 
                   3500:   <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
                   3501:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3502:   for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
                   3503:   append this node to the <a href="#current-node">current node</a>, and push it onto
                   3504:   the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3505:   <a href="#current-node">current node</a>.</p>
                   3506: 
                   3507:   <p>The steps below may also require that the UA insert an HTML
                   3508:   element in a particular place, in which case the UA must follow the
                   3509:   same steps except that it must insert or append the new node in the
                   3510:   location specified instead of appending it to the <a href="#current-node">current
                   3511:   node</a>. (This happens in particular during the parsing of
                   3512:   tables with invalid content.)</p>
                   3513: 
                   3514:   <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
                   3515:   algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
                   3516:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
                   3517:   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
                   3518:   <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
                   3519:   created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
                   3520:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
                   3521:   inserting it wherever it is to be inserted.</p>
                   3522: 
                   3523:   <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
                   3524:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3525:   for the token</a> in the given namespace, and then append this
                   3526:   node to the <a href="#current-node">current node</a>, and push it onto the
                   3527:   <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3528:   <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>
                   3529:   whose value is not exactly the same as the element's namespace, that
                   3530:   is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
                   3531:   element has an <code title="">xmlns:xlink</code> attribute in the
                   3532:   <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
                   3533:   Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
                   3534: 
                   3535:   <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
                   3536:   attributes</dfn> for a token, then, if the token has an attribute
                   3537:   named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
                   3538: 
                   3539:   <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
                   3540:   attributes</dfn> for a token, then, for each attribute on the token
                   3541:   whose attribute name is one of the ones in the first column of the
                   3542:   following table, change the attribute's name to the name given in
                   3543:   the corresponding cell in the second column. (This fixes the case of
                   3544:   SVG attributes that are not all lowercase.)</p>
                   3545: 
                   3546:   <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
                   3547:    </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
                   3548:     </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
                   3549:     </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
                   3550:     </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
                   3551:     </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
                   3552:     </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
                   3553:     </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
                   3554:     </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
                   3555:     </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
                   3556:     </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
                   3557:     </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
                   3558:     </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
                   3559:     </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
                   3560:     </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   3561:     </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
                   3562:     </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
                   3563:     </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
                   3564:     </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
                   3565:     </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
                   3566:     </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
                   3567:     </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
                   3568:     </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
                   3569:     </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
                   3570:     </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
                   3571:     </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
                   3572:     </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
                   3573:     </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
                   3574:     </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
                   3575:     </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
                   3576:     </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
                   3577:     </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
                   3578:     </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
                   3579:     </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
                   3580:     </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
                   3581:     </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
                   3582:     </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
                   3583:     </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
                   3584:     </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
                   3585:     </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
                   3586:     </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
                   3587:     </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
                   3588:     </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
                   3589:     </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
                   3590:     </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
                   3591:     </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
                   3592:     </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
                   3593:     </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
                   3594:     </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
                   3595:     </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
                   3596:     </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
                   3597:     </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
                   3598:     </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
                   3599:     </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
                   3600:     </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
                   3601:     </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
                   3602:     </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
                   3603:     </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
                   3604:     </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
                   3605:     </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
                   3606:     </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
                   3607:     </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
                   3608:     </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
                   3609:   </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
                   3610:   foreign attributes</dfn> for a token, then, if any of the attributes
                   3611:   on the token match the strings given in the first column of the
                   3612:   following table, let the attribute be a namespaced attribute, with
                   3613:   the prefix being the string given in the corresponding cell in the
                   3614:   second column, the local name being the string given in the
                   3615:   corresponding cell in the third column, and the namespace being the
                   3616:   namespace given in the corresponding cell in the fourth
                   3617:   column. (This fixes the use of namespaced attributes, in particular
                   3618:   <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
                   3619:   the <span>XML namespace</span></a>.)</p>
                   3620: 
                   3621:   <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
                   3622:    </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>
                   3623:     </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>
                   3624:     </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>
                   3625:     </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>
                   3626:     </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>
                   3627:     </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>
                   3628:     </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>
                   3629:     </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 -->
                   3630:     </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>
                   3631:     </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>
                   3632:     </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>
                   3633:     </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     3634:   </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     3635:   <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
                   3636:   following steps. These algorithms are always invoked in response to
                   3637:   a start tag token.</p>
                   3638: 
                   3639:   <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
                   3640: 
1.91      mike     3641:    <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
                   3642:    text element parsing algorithm</a>, switch the tokenizer's
                   3643:    <a href="#content-model-flag">content model flag</a> to the RAWTEXT state; otherwise the
1.1       mike     3644:    algorithm invoked was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing
                   3645:    algorithm</a>, switch the tokenizer's <a href="#content-model-flag">content model
                   3646:    flag</a> to the RCDATA state.</p></li>
                   3647: 
                   3648:    <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   3649:    <a href="#insertion-mode">insertion mode</a>.</p>
                   3650: 
1.91      mike     3651:    </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
                   3652:    RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     3653: 
                   3654:   </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>
                   3655: 
                   3656:   <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
                   3657:   tags</dfn>, then, while the <a href="#current-node">current node</a> is a
                   3658:   <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
                   3659:   <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
                   3660:   <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
                   3661:   <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
                   3662:   pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   3663:   elements</a>.</p>
                   3664: 
                   3665:   <p>If a step requires the UA to generate implied end tags but lists
                   3666:   an element to exclude from the process, then the UA must perform the
                   3667:   above steps as if that element was not in the above list.</p>
                   3668: 
                   3669: 
                   3670:   <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5>
                   3671: 
                   3672:   <p>Foster parenting happens when content is misnested in tables.</p>
                   3673: 
                   3674:   <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
                   3675:   parent">foster parented</dfn>, the node <var title="">node</var>
                   3676:   must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3677: 
                   3678:   <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
                   3679:   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
                   3680:   elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
                   3681:   such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3682:   the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
                   3683:   case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
                   3684:   element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
                   3685:   <code><a href="semantics.html#the-html-element">html</a></code> element). Otherwise, if there is a
                   3686:   <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
                   3687:   elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3688:   <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
                   3689:   node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
                   3690:   the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3691:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   3692: 
                   3693:   <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
                   3694:   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
                   3695:   elements</a>, then <var title="">node</var> must be inserted
                   3696:   immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3697:   the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
                   3698:   element</a></i>; otherwise, <var title="">node</var> must be
                   3699:   <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3700: 
                   3701: 
                   3702: 
                   3703:   <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>
                   3704: 
                   3705:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
                   3706:   mode: initial">initial</a>", tokens must be handled as follows:</p>
                   3707: 
                   3708:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3709:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3710:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3711:    <dd>
                   3712:     <p>Ignore the token.</p>
                   3713:    </dd>
                   3714: 
                   3715:    <dt>A comment token</dt>
                   3716:    <dd>
                   3717:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   3718:     object with the <code title="">data</code> attribute set to the
                   3719:     data given in the comment token.</p>
                   3720:    </dd>
                   3721: 
                   3722:    <dt>A DOCTYPE token</dt>
                   3723:    <dd>
                   3724: 
                   3725:     <p>If the DOCTYPE token's name is not a
                   3726:     <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
                   3727:     missing, or the token's system identifier is neither missing nor a
                   3728:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
                   3729:     "<code>about:legacy-compat</code>", and none of the sets of
                   3730:     conditions in the following list are matched, then there is a
                   3731:     <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
                   3732:     following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
                   3733:     permitted DOCTYPE</dfn>.</p>
                   3734: 
                   3735:     <ul><!-- only things that trigger no-quirks mode and were valid in
                   3736:      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     3737:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3738:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.0//EN</code>", and the
                   3739:      token's system identifier is either missing or the
                   3740:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
                   3741: 
                   3742:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3743:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3744:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.01//EN</code>", and the
                   3745:      token's system identifier is either missing or the
                   3746:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
                   3747: 
                   3748:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3749:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3750:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.0&#160;Strict//EN</code>",
                   3751:      and the token's system identifier is the
                   3752:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
                   3753: 
                   3754:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3755:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3756:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.1//EN</code>", and the
                   3757:      token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
                   3758:      string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
                   3759: 
                   3760:     </ul><p>Conformance checkers may, based on the values (including
                   3761:     presence or lack thereof) of the DOCTYPE token's name, public
                   3762:     identifier, or system identifier, switch to a conformance checking
                   3763:     mode for another language (e.g. based on the DOCTYPE token a
                   3764:     conformance checker could recognize that the document is an
                   3765:     HTML&#160;4-era document, and defer to an HTML&#160;4 conformance
                   3766:     checker.)</p>
                   3767: 
                   3768:     <p>Append a <code>DocumentType</code> node to the
                   3769:     <code>Document</code> node, with the <code title="">name</code>
                   3770:     attribute set to the name given in the DOCTYPE token, or the empty
                   3771:     string if the name was missing; the <code title="">publicId</code>
                   3772:     attribute set to the public identifier given in the DOCTYPE token,
                   3773:     or the empty string if the public identifier was missing; the
                   3774:     <code title="">systemId</code> attribute set to the system
                   3775:     identifier given in the DOCTYPE token, or the empty string if the
                   3776:     system identifier was missing; and the other attributes specific
                   3777:     to <code>DocumentType</code> objects set to null and empty lists
                   3778:     as appropriate. Associate the <code>DocumentType</code> node with
                   3779:     the <code>Document</code> object so that it is returned as the
                   3780:     value of the <code title="">doctype</code> attribute of the
                   3781:     <code>Document</code> object.</p>
                   3782: 
                   3783:     <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
                   3784:     one of the conditions in the following list, then set the
                   3785:     <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
                   3786: 
                   3787:     <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
                   3788:      <li> The name is set to anything other than "<code title="">HTML</code>". </li>
                   3789:      <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
                   3790:      <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   3791:      <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   3792:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
                   3793:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
                   3794:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
                   3795:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
                   3796:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
                   3797:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
                   3798:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
                   3799:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
                   3800:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
                   3801:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   3802:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
                   3803:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
                   3804:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
                   3805:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
                   3806:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
                   3807:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
                   3808:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
                   3809:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
                   3810:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
                   3811:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
                   3812:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
                   3813:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
                   3814:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
                   3815:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
                   3816:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
                   3817:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
                   3818:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
                   3819:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
                   3820:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
                   3821:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
                   3822:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
                   3823:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
                   3824:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
                   3825:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
                   3826:      <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
                   3827:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
                   3828:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
                   3829:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
                   3830:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
                   3831:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
                   3832:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
                   3833:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
                   3834:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
                   3835:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
                   3836:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
                   3837:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
                   3838:      <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
                   3839:      <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
                   3840:      <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
                   3841:      <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
                   3842:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
                   3843:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
                   3844:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
                   3845:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
                   3846:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   3847:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
                   3848:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
                   3849:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
                   3850:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
                   3851:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
                   3852:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
                   3853:      <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
                   3854:      <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
                   3855:    <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
                   3856:      <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
                   3857:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
                   3858:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
                   3859:      <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
                   3860:      <li> The public identifier is set to: "<code title="">HTML</code>" </li>
                   3861:      <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
                   3862:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   3863:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   3864:     </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
                   3865:     in the following list, then set the <code>Document</code> to
                   3866:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
                   3867: 
                   3868:     <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
                   3869:      <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
                   3870:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   3871:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   3872:     </ul><p>The name, system identifier, and public identifier strings must
                   3873:     be compared to the values given in the lists above in an
                   3874:     <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
                   3875:     whose value is the empty string is not considered missing for the
                   3876:     purposes of the conditions above.</p>
                   3877: 
                   3878:     <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>
                   3879: 
                   3880:    </dd>
                   3881: 
                   3882:    <dt>Anything else</dt>
                   3883:    <dd>
                   3884: 
                   3885:     <p><a href="#parse-error">Parse error</a>.</p>
                   3886: 
                   3887:     <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
                   3888: 
                   3889:     <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
                   3890:     reprocess the current token.</p>
                   3891: 
                   3892:    </dd>
                   3893: 
                   3894:   </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>
                   3895: 
                   3896:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
                   3897:   mode: before html">before html</a>", tokens must be handled as follows:</p>
                   3898: 
                   3899:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   3900:    <dd>
                   3901:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3902:    </dd>
                   3903: 
                   3904:    <dt>A comment token</dt>
                   3905:    <dd>
                   3906:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   3907:     object with the <code title="">data</code> attribute set to the
                   3908:     data given in the comment token.</p>
                   3909:    </dd>
                   3910: 
                   3911:    <dt>A character token that is one of U+0009 CHARACTER
                   3912:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3913:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3914:    <dd>
                   3915:     <p>Ignore the token.</p>
                   3916:    </dd>
                   3917: 
                   3918:    <dt>A start tag whose tag name is "html"</dt>
                   3919:    <dd>
                   3920: 
                   3921:     <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
                   3922:     namespace</a>. Append it to the <code>Document</code>
                   3923:     object. Put this element in the <a href="#stack-of-open-elements">stack of open
                   3924:     elements</a>.</p>
                   3925: 
                   3926:     <p id="parser-appcache">If the <code>Document</code> is being
                   3927:     loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
                   3928:     <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
                   3929:     has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
                   3930:     then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
                   3931:     attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
                   3932:     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     3933:     algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
                   3934:     any <a href="infrastructure.html#url-fragment" title="url-fragment">&lt;fragment&gt;</a> component
                   3935:     removed; otherwise, if there is no such attribute or resolving it
                   3936:     fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
                   3937:     cache selection algorithm</a> with no manifest. The algorithm
                   3938:     must be passed the <code>Document</code> object.</p>
1.1       mike     3939: 
                   3940:     <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>
                   3941: 
                   3942:    </dd>
                   3943: 
                   3944:    <dt>Anything else</dt>
                   3945:    <dd>
                   3946: 
                   3947:     <p>Create an <code><a href="semantics.html#the-html-element">html</a></code> element. Append it to the
                   3948:     <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
                   3949:     of open elements</a>.</p>
                   3950: 
                   3951:     <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
                   3952:     context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
                   3953:     algorithm</a> with no manifest, passing it the
                   3954:     <code>Document</code> object.</p>
                   3955: 
                   3956:     <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
                   3957:     reprocess the current token.</p>
                   3958: 
                   3959:     <p class="XXX">Should probably make end tags be ignored, so
                   3960:     that "&lt;/head&gt;&lt;!-- --&gt;&lt;html&gt;" puts the comment before the
                   3961:     root node (or should we?)</p>
                   3962: 
                   3963:    </dd>
                   3964: 
                   3965:   </dl><p>The root element can end up being removed from the
                   3966:   <code>Document</code> object, e.g. by scripts; nothing in particular
                   3967:   happens in such cases, content continues being appended to the nodes
                   3968:   as described in the next section.</p>
                   3969: 
                   3970: 
                   3971:   <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>
                   3972: 
                   3973:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
                   3974:   mode: before head">before head</a>", tokens must be handled as follows:</p>
                   3975: 
                   3976:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3977:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3978:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3979:    <dd>
                   3980:     <p>Ignore the token.</p> <!-- :-( -->
                   3981:    </dd>
                   3982: 
                   3983:    <dt>A comment token</dt>
                   3984:    <dd>
                   3985:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   3986:     node</a> with the <code title="">data</code> attribute set to
                   3987:     the data given in the comment token.</p>
                   3988:    </dd>
                   3989: 
                   3990:    <dt>A DOCTYPE token</dt>
                   3991:    <dd>
                   3992:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3993:    </dd>
                   3994: 
                   3995:    <dt>A start tag whose tag name is "html"</dt>
                   3996:    <dd>
                   3997:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   3998:     mode</a>.</p>
                   3999:    </dd>
                   4000: 
                   4001:    <dt>A start tag whose tag name is "head"</dt>
                   4002:    <dd>
                   4003: 
                   4004:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4005: 
                   4006:     <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
                   4007:     to the newly created <code><a href="semantics.html#the-head-element">head</a></code> element.</p>
                   4008: 
                   4009:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>".</p>
                   4010: 
                   4011:    </dd>
                   4012: 
                   4013:    <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
                   4014:    <dd>
                   4015: 
                   4016:     <p>Act as if a start tag token with the tag name "head" and no
                   4017:     attributes had been seen, then reprocess the current token.</p>
                   4018: 
                   4019:    </dd>
                   4020: 
                   4021:    <dt>Any other end tag</dt>
                   4022:    <dd>
                   4023: 
                   4024:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4025: 
                   4026:    </dd>
                   4027: 
                   4028:    <dt>Anything else</dt>
                   4029:    <dd>
                   4030: 
                   4031:     <p>Act as if a start tag token with the tag name "head" and no
                   4032:     attributes had been seen, then reprocess the current
                   4033:     token.</p>
                   4034: 
                   4035:    </dd>
                   4036: 
                   4037:   </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>
                   4038: 
                   4039:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
                   4040:   mode: in head">in head</a>", tokens must be handled as follows:</p>
                   4041: 
                   4042:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4043:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4044:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4045:    <dd>
                   4046:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   4047:     the <a href="#current-node">current node</a>.</p>
                   4048:    </dd>
                   4049: 
                   4050:    <dt>A comment token</dt>
                   4051:    <dd>
                   4052:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4053:     node</a> with the <code title="">data</code> attribute set to
                   4054:     the data given in the comment token.</p>
                   4055:    </dd>
                   4056: 
                   4057:    <dt>A DOCTYPE token</dt>
                   4058:    <dd>
                   4059:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4060:    </dd>
                   4061: 
                   4062:    <dt>A start tag whose tag name is "html"</dt>
                   4063:    <dd>
                   4064:     <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
                   4065:     mode</a>.</p>
                   4066:    </dd>
                   4067: 
                   4068:    <dt>A start tag whose tag name is one of: "base", "command",
                   4069:    "link"</dt>
                   4070:    <dd>
                   4071: 
                   4072:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   4073:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   4074:     elements</a>.</p>
                   4075: 
                   4076:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4077:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4078: 
                   4079:    </dd>
                   4080: 
                   4081:    <dt>A start tag whose tag name is "meta"</dt>
                   4082:    <dd>
                   4083: 
                   4084:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   4085:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   4086:     elements</a>.</p>
                   4087: 
                   4088:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4089:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4090: 
                   4091:     <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
                   4092:     value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   4093:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   4094:     encoding</a> to the encoding given by the value of the
                   4095:     <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
                   4096: 
                   4097:     <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
                   4098:     applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
                   4099:     Content-Type</a> to its value returns a supported encoding
                   4100:     <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   4101:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   4102:     encoding</a> to the encoding <var title="">encoding</var>.</p>
                   4103: 
                   4104:    </dd>
                   4105: 
                   4106:    <dt>A start tag whose tag name is "title"</dt>
                   4107:    <dd>
                   4108:     <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
                   4109:    </dd>
                   4110: 
                   4111:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   4112:    <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
                   4113:    <dd>
1.91      mike     4114:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     4115:    </dd>
                   4116: 
                   4117:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
                   4118:    <dd>
                   4119: 
                   4120:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4121: 
                   4122:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
                   4123:     noscript</a>".</p>
                   4124: 
                   4125:    </dd>
                   4126: 
                   4127:    <dt id="scriptTag">A start tag whose tag name is "script"</dt>
                   4128:    <dd>
                   4129: 
                   4130:     <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
                   4131:      <a href="#html-namespace-0">HTML namespace</a>.</p></li>
                   4132: 
                   4133:      <li>
                   4134: 
                   4135:       <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
                   4136: 
                   4137:       <p class="note">This ensures that, if the script is external,
                   4138:       any <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code>
                   4139:       calls in the script will execute in-line, instead of blowing the
                   4140:       document away, as would happen in most other cases. It also
                   4141:       prevents the script from executing until the end tag is
                   4142:       seen.</p>
                   4143: 
                   4144:      </li>
                   4145: 
                   4146:      <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
                   4147:      fragment parsing algorithm</a>, then mark the
                   4148:      <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
                   4149:      executed"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
                   4150: 
                   4151:      <li><p>Append the new element to the <a href="#current-node">current node</a>
                   4152:      and push it onto the <a href="#stack-of-open-elements">stack of open
                   4153:      elements</a>.</p></li>
                   4154: 
                   4155:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
1.91      mike     4156:      the RAWTEXT state.</p></li>
1.1       mike     4157: 
                   4158:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   4159:      <a href="#insertion-mode">insertion mode</a>.</p>
                   4160: 
1.91      mike     4161:      </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
                   4162:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     4163: 
                   4164:     </ol></dd>
                   4165: 
                   4166:    <dt>An end tag whose tag name is "head"</dt>
                   4167:    <dd>
                   4168: 
                   4169:     <p>Pop the <a href="#current-node">current node</a> (which will be the
                   4170:     <code><a href="semantics.html#the-head-element">head</a></code> element) off the <a href="#stack-of-open-elements">stack of open
                   4171:     elements</a>.</p>
                   4172: 
                   4173:     <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>
                   4174: 
                   4175:    </dd>
                   4176: 
                   4177:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4178:    <dd>
                   4179:     <p>Act as described in the "anything else" entry below.</p>
                   4180:    </dd>
                   4181: 
                   4182:    <dt>A start tag whose tag name is "head"</dt>
                   4183:    <dt>Any other end tag</dt>
                   4184:    <dd>
                   4185:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4186:    </dd>
                   4187: 
                   4188:    <dt>Anything else</dt>
                   4189:    <dd>
                   4190: 
                   4191:     <!-- can't get here with an EOF and a fragment case -->
                   4192: 
                   4193:     <p>Act as if an end tag token with the tag name "head" had
                   4194:     been seen, and reprocess the current token.</p>
                   4195: 
                   4196:     <p class="XXX">In certain UAs, <a href="https://bugzilla.mozilla.org/attachment.cgi?id=180157&amp;action=view">some
                   4197:     elements</a> don't trigger the "in body" mode straight away,
                   4198:     but instead get put into the head. Do we want to copy
                   4199:     that?</p>
                   4200: 
                   4201:    </dd>
                   4202: 
                   4203:   </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>
                   4204: 
                   4205:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
                   4206:   mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
                   4207: 
                   4208:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   4209:    <dd>
                   4210:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4211:    </dd>
                   4212: 
                   4213:    <dt>A start tag whose tag name is "html"</dt>
                   4214:    <dd>
                   4215:     <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
                   4216:     mode</a>.</p>
                   4217:    </dd>
                   4218: 
                   4219:    <dt>An end tag whose tag name is "noscript"</dt>
                   4220:    <dd>
                   4221: 
                   4222:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   4223:     <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   4224:     elements</a>; the new <a href="#current-node">current node</a> will be a
                   4225:     <code><a href="semantics.html#the-head-element">head</a></code> element.</p>
                   4226: 
                   4227:     <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>
                   4228: 
                   4229:    </dd>
                   4230: 
                   4231:    <dt>A character token that is one of U+0009 CHARACTER
                   4232:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4233:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4234:    <dt>A comment token</dt>
                   4235:    <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
                   4236:    <dd>
                   4237:     <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
                   4238:     mode</a>.</p>
                   4239:    </dd>
                   4240: 
                   4241:    <dt>An end tag whose tag name is "br"</dt>
                   4242:    <dd>
                   4243:     <p>Act as described in the "anything else" entry below.</p>
                   4244:    </dd>
                   4245: 
                   4246:    <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
                   4247:    <dt>Any other end tag</dt>
                   4248:    <dd>
                   4249:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4250:    </dd>
                   4251: 
                   4252:    <dt>Anything else</dt>
                   4253:    <dd>
                   4254: 
                   4255:     <!-- can't get here with an EOF and a fragment case -->
                   4256: 
                   4257:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   4258:     name "noscript" had been seen and reprocess the current
                   4259:     token.</p>
                   4260: 
                   4261:    </dd>
                   4262: 
                   4263:   </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>
                   4264: 
                   4265:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
                   4266:   mode: after head">after head</a>", tokens must be handled as follows:</p>
                   4267: 
                   4268:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4269:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4270:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4271:    <dd>
                   4272:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   4273:     the <a href="#current-node">current node</a>.</p>
                   4274:    </dd>
                   4275: 
                   4276:    <dt>A comment token</dt>
                   4277:    <dd>
                   4278:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4279:     node</a> with the <code title="">data</code> attribute set to
                   4280:     the data given in the comment token.</p>
                   4281:    </dd>
                   4282: 
                   4283:    <dt>A DOCTYPE token</dt>
                   4284:    <dd>
                   4285:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4286:    </dd>
                   4287: 
                   4288:    <dt>A start tag whose tag name is "html"</dt>
                   4289:    <dd>
                   4290:     <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
                   4291:     mode</a>.</p>
                   4292:    </dd>
                   4293: 
                   4294:    <dt>A start tag whose tag name is "body"</dt>
                   4295:    <dd>
                   4296: 
                   4297:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4298: 
                   4299:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4300: 
                   4301:     <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>
                   4302: 
                   4303:    </dd>
                   4304: 
                   4305:    <dt>A start tag whose tag name is "frameset"</dt>
                   4306:    <dd>
                   4307: 
                   4308:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4309: 
                   4310:     <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>
                   4311: 
                   4312:    </dd>
                   4313: 
                   4314:    <dt>A start tag token whose tag name is one of: "base", "link",
                   4315:    "meta", "noframes", "script", "style", "title"</dt>
                   4316:    <dd>
                   4317: 
                   4318:     <p><a href="#parse-error">Parse error</a>.</p>
                   4319: 
                   4320:     <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
                   4321:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4322: 
                   4323:     <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
                   4324:     mode</a>.</p>
                   4325: 
                   4326:     <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
                   4327:     of open elements</a>.</p>
                   4328: 
                   4329:     <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
                   4330:     pointer</a> cannot be null at this point.</p>
                   4331: 
                   4332:    </dd>
                   4333: 
                   4334:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4335:    <dd>
                   4336:     <p>Act as described in the "anything else" entry below.</p>
                   4337:    </dd>
                   4338: 
                   4339:    <dt>A start tag whose tag name is "head"</dt>
                   4340:    <dt>Any other end tag</dt>
                   4341:    <dd>
                   4342:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4343:    </dd>
                   4344: 
                   4345:    <dt>Anything else</dt>
                   4346:    <dd>
                   4347:     <p>Act as if a start tag token with the tag name "body" and no
                   4348:     attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
                   4349:     flag</a> back to "ok", and then reprocess the current
                   4350:     token.</p>
                   4351:    </dd>
                   4352: 
                   4353:   </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>
                   4354: 
                   4355:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
                   4356:   mode: in body">in body</a>", tokens must be handled as follows:</p>
                   4357: 
                   4358:   <dl class="switch"><dt>A character token</dt>
                   4359:    <dd>
                   4360: 
                   4361:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4362:     any.</p>
                   4363: 
                   4364:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   4365:     character</a> into the <a href="#current-node">current node</a>.</p>
                   4366: 
                   4367:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   4368:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   4369:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   4370:     flag</a> to "not ok".</p>
                   4371: 
                   4372:    </dd>
                   4373: 
                   4374:    <dt>A comment token</dt>
                   4375:    <dd>
                   4376:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4377:     node</a> with the <code title="">data</code> attribute set to
                   4378:     the data given in the comment token.</p>
                   4379:    </dd>
                   4380: 
                   4381:    <dt>A DOCTYPE token</dt>
                   4382:    <dd>
                   4383:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4384:    </dd>
                   4385: 
                   4386:    <dt>A start tag whose tag name is "html"</dt>
                   4387:    <dd>
                   4388:     <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
                   4389:     check to see if the attribute is already present on the top
                   4390:     element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
                   4391:     add the attribute and its corresponding value to that element.</p>
                   4392:    </dd>
                   4393: 
                   4394:    <dt>A start tag token whose tag name is one of: "base", "command",
                   4395:    "link", "meta", "noframes", "script", "style", "title"</dt>
                   4396:    <dd>
                   4397:     <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
                   4398:     mode</a>.</p>
                   4399:    </dd>
                   4400: 
                   4401:    <dt>A start tag whose tag name is "body"</dt>
                   4402:    <dd>
                   4403: 
                   4404:     <p><a href="#parse-error">Parse error</a>.</p>
                   4405: 
                   4406:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
                   4407:     elements</a> is not a <code><a href="semantics.html#the-body-element">body</a></code> element, or, if the
                   4408:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4409:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4410: 
                   4411:     <p>Otherwise, for each attribute on the token, check to see if
                   4412:     the attribute is already present on the <code><a href="semantics.html#the-body-element">body</a></code>
                   4413:     element (the second element) on the <a href="#stack-of-open-elements">stack of open
                   4414:     elements</a>. If it is not, add the attribute and its
                   4415:     corresponding value to that element.</p>
                   4416: 
                   4417:    </dd>
                   4418: 
                   4419:    <dt>A start tag whose tag name is "frameset"</dt>
                   4420:    <dd>
                   4421: 
                   4422:     <p><a href="#parse-error">Parse error</a>.</p>
                   4423: 
                   4424:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
                   4425:     elements</a> is not a <code><a href="semantics.html#the-body-element">body</a></code> element, or, if the
                   4426:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4427:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4428: 
                   4429:     <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
                   4430:     the token.</p>
                   4431: 
                   4432:     <p>Otherwise, run the following steps:</p>
                   4433: 
                   4434:     <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
                   4435:      elements</a> from its parent node, if it has one.</p></li>
                   4436: 
                   4437:      <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
                   4438:      open elements</a>, from the <a href="#current-node">current node</a> up to,
                   4439:      but not including, the root <code><a href="semantics.html#the-html-element">html</a></code> element.</p>
                   4440: 
                   4441:      </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   4442:      token.</p></li>
                   4443: 
                   4444:      <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>
                   4445: 
                   4446:     </li></ol></dd>
                   4447: 
                   4448:    <dt>An end-of-file token</dt>
                   4449:    <dd>
                   4450: 
                   4451:     <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
                   4452:     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>
                   4453:     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
                   4454:     <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
                   4455:     <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
                   4456:     <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
                   4457:     <code><a href="semantics.html#the-body-element">body</a></code> element, or the <code><a href="semantics.html#the-html-element">html</a></code> element, then
                   4458:     this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
                   4459:     fragment cases) -->
                   4460: 
                   4461:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   4462: 
                   4463:    </dd>
                   4464: 
                   4465:    <dt>An end tag whose tag name is "body"</dt>
                   4466:    <dd>
                   4467: 
                   4468:     <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
                   4469:     in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
                   4470:     token.</p>
                   4471: 
                   4472:     <!-- if we get here, the insertion mode here is forcibly "in
                   4473:     body". -->
                   4474: 
                   4475:     <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
                   4476:     elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
                   4477:     <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
                   4478:     <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
                   4479:     <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
                   4480:     <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
                   4481:     <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
                   4482:     <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
                   4483:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the <code><a href="semantics.html#the-body-element">body</a></code> element, or the
                   4484:     <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
                   4485:     error</a>.</p> <!-- (some of those are fragment cases, e.g. for
                   4486:     <tbody> you'd have hit the first paragraph since the <body>
                   4487:     wouldn't be in scope, unless it was a fragment case) -->
                   4488: 
                   4489:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   4490:     then we'd have to somehow keep track of its state when we switch
                   4491:     to after-body. -->
                   4492: 
                   4493:     <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>
                   4494: 
                   4495:    </dd>
                   4496: 
                   4497:    <dt>An end tag whose tag name is "html"</dt>
                   4498:    <dd>
                   4499: 
                   4500:     <p>Act as if an end tag with tag name "body" had been seen,
                   4501:     then, if that token wasn't ignored, reprocess the current
                   4502:     token.</p>
                   4503: 
                   4504:     <p class="note">The fake end tag token here can only be
                   4505:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   4506: 
                   4507:    </dd>
                   4508: 
                   4509:    <!-- start tags for non-phrasing flow content elements -->
                   4510: 
                   4511:    <!-- the normal ones -->
                   4512:    <dt>A start tag whose tag name is one of: "address", "article",
1.86      mike     4513:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
                   4514:    "details", "dialog", "dir", "div", "dl", "fieldset", "figure",
                   4515:    "footer", "header", "hgroup", "menu", "nav", "ol", "p", "section",
                   4516:    "ul"</dt>
1.1       mike     4517:    <dd>
                   4518: 
                   4519:     <!-- As of May 2008 this doesn't match any browser exactly, but is
                   4520:     as close to what IE does as I can get without doing the non-tree
                   4521:     DOM nonsense, and thus should actually afford better compatibility
                   4522:     when implemented by the other browsers. -->
                   4523: 
                   4524:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4525:     an element in scope">has a <code>p</code> element in
                   4526:     scope</a>, then act as if an end tag with the tag name
                   4527:     "p" had been seen.</p>
                   4528: 
                   4529:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4530: 
                   4531:    </dd>
                   4532: 
                   4533:    <!-- as normal, but close h1-h6 if it's the current node -->
                   4534:    <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
                   4535:    "h5", "h6"</dt>
                   4536:    <dd>
                   4537: 
                   4538:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4539:     an element in scope">has a <code>p</code> element in
                   4540:     scope</a>, then act as if an end tag with the tag name
                   4541:     "p" had been seen.</p>
                   4542: 
                   4543:     <p>If the <a href="#current-node">current node</a> is an element whose tag name
                   4544:     is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
                   4545:     <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
                   4546:     the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4547:     <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
                   4548: 
                   4549:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4550: 
                   4551:    </dd>
                   4552: 
                   4553:    <!-- as normal, but drops leading newline -->
                   4554:    <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
                   4555:    <dd>
                   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><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4563: 
                   4564:     <p>If the next token is a U+000A LINE FEED (LF) character
                   4565:     token, then ignore that token and move on to the next
                   4566:     one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
                   4567:     ignored as an authoring convenience.)</p>
                   4568: 
                   4569:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4570: 
                   4571:    </dd>
                   4572: 
                   4573:    <!-- as normal, but interacts with the form element pointer -->
                   4574:    <dt>A start tag whose tag name is "form"</dt>
                   4575:    <dd>
                   4576: 
                   4577:     <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
                   4578:     pointer</a> is not null, then this is a <a href="#parse-error">parse
                   4579:     error</a>; ignore the token.</p>
                   4580: 
                   4581:     <p>Otherwise:</p>
                   4582: 
                   4583:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4584:     an element in scope">has a <code>p</code> element in
                   4585:     scope</a>, then act as if an end tag with the tag name
                   4586:     "p" had been seen.</p>
                   4587: 
                   4588:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
                   4589:     <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
                   4590:     point to the element created.</p>
                   4591: 
                   4592:    </dd>
                   4593: 
                   4594:    <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
                   4595:    <dt>A start tag whose tag name is "li"</dt>
                   4596:    <dd>
                   4597: 
                   4598:     <p>Run the following algorithm:</p>
                   4599: 
                   4600:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4601: 
                   4602:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4603:      node</a> (the bottommost node of the stack).</p></li>
                   4604: 
                   4605:      <li><p>If <var title="">node</var> is an <code><a href="semantics.html#the-li-element">li</a></code> element,
                   4606:      then act as if an end tag with the tag name "li" had
                   4607:      been seen, then jump to the last step.</p></li>
                   4608: 
                   4609:      <li><p><i>Loop</i>: If <var title="">node</var> is not in the
                   4610:      <a href="#formatting">formatting</a> category, and is not in the
                   4611:      <a href="#phrasing">phrasing</a> category, and is not an
                   4612:      <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>
                   4613:      element, then jump to the last step.</p></li> <!-- an element
                   4614:      <foo> is in this list if the following markup:
                   4615: 
                   4616:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
                   4617: 
                   4618:      ...results in the second <li> not being (in any way) a descendant
                   4619:      of the first <li>, or if <foo> is a formatting element that gets
                   4620:      reopened later. -->
                   4621: 
                   4622:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4623:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4624:      the step labeled <i>loop</i>.</p></li>
                   4625: 
                   4626:      <li>
                   4627: 
                   4628:       <p>This is the last step.</p>
                   4629: 
                   4630:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4631:       an element in scope">has a <code>p</code> element in
                   4632:       scope</a>, then act as if an end tag with the tag name
                   4633:       "p" had been seen.</p>
                   4634: 
                   4635:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4636:       token.</p>
                   4637: 
                   4638:      </li>
                   4639: 
                   4640:     </ol></dd>
                   4641: 
                   4642:    <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases  -->
                   4643:    <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
                   4644:    <dd>
                   4645: 
                   4646:     <p>Run the following algorithm:</p>
                   4647: 
                   4648:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4649: 
                   4650:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4651:      node</a> (the bottommost node of the stack).</p></li>
                   4652: 
                   4653:      <li><p><i>Loop</i>: If <var title="">node</var> is a
                   4654:      <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
                   4655:      tag with the same tag name as <var title="">node</var> had been
                   4656:      seen, then jump to the last step.</p></li>
                   4657: 
                   4658:      <li><p>If <var title="">node</var> is not in the
                   4659:      <a href="#formatting">formatting</a> category, and is not in the
                   4660:      <a href="#phrasing">phrasing</a> category, and is not an
                   4661:      <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>
                   4662:      element, then jump to the last step.</p></li> <!-- an element
                   4663:      <foo> is in this list if the following markup:
                   4664: 
                   4665:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
                   4666: 
                   4667:      ...results in the second <dt> not being (in any way) a descendant
                   4668:      of the first <dt>, or if <foo> is a formatting element that gets
                   4669:      reopened later. -->
                   4670: 
                   4671:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4672:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4673:      the step labeled <i>loop</i>.</p></li>
                   4674: 
                   4675:      <li>
                   4676: 
                   4677:       <p>This is the last step.</p>
                   4678: 
                   4679:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4680:       an element in scope">has a <code>p</code> element in
                   4681:       scope</a>, then act as if an end tag with the tag name
                   4682:       "p" had been seen.</p>
                   4683: 
                   4684:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4685:       token.</p>
                   4686: 
                   4687:      </li>
                   4688: 
                   4689:     </ol></dd>
                   4690: 
                   4691:    <!-- same as normal, but effectively ends parsing -->
                   4692:    <dt>A start tag whose tag name is "plaintext"</dt>
                   4693:    <dd>
                   4694: 
                   4695:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4696:     an element in scope">has a <code>p</code> element in
                   4697:     scope</a>, then act as if an end tag with the tag name
                   4698:     "p" had been seen.</p>
                   4699: 
                   4700:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4701: 
                   4702:     <p>Switch the <a href="#content-model-flag">content model flag</a> to the PLAINTEXT
                   4703:     state.</p>
                   4704: 
                   4705:     <p class="note">Once a start tag with the tag name "plaintext"
                   4706:     has been seen, that will be the last token ever seen other
                   4707:     than character tokens (and the end-of-file token), because
                   4708:     there is no way to switch the <a href="#content-model-flag">content model flag</a>
                   4709:     out of the PLAINTEXT state.</p>
                   4710: 
                   4711:    </dd>
                   4712: 
                   4713:    <!-- end tags for non-phrasing flow content elements -->
                   4714: 
                   4715:    <!-- the normal ones -->
                   4716:    <dt>An end tag whose tag name is one of: "address", "article",
1.86      mike     4717:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
                   4718:    "details", "dialog", "dir", "div", "dl", "fieldset", "figure",
                   4719:    "footer", "header", "hgroup", "listing", "menu", "nav", "ol",
                   4720:    "pre", "section", "ul"</dt>
1.1       mike     4721:    <dd>
                   4722: 
                   4723:     <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>
                   4724:     with the same tag name as that of the token, then this is a
                   4725:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4726: 
                   4727:     <p>Otherwise, run these steps:</p>
                   4728: 
                   4729:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4730: 
                   4731:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4732:      the same tag name as that of the token, then this is a
                   4733:      <a href="#parse-error">parse error</a>.</p></li>
                   4734: 
                   4735:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4736:      until an element with the same tag name as the token has been
                   4737:      popped from the stack.</p></li>
                   4738: 
                   4739:     </ol></dd>
                   4740: 
                   4741:    <!-- removes the form element pointer instead of the matching node -->
                   4742:    <dt>An end tag whose tag name is "form"</dt>
                   4743:    <dd>
                   4744: 
                   4745:     <p>Let <var title="">node</var> be the element that the
                   4746:     <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
                   4747:     to.</p>
                   4748: 
                   4749:     <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   4750:     to null.</p>
                   4751: 
                   4752:     <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
                   4753:     elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
                   4754:     scope">have <var title="">node</var> in scope</a>, then this is
                   4755:     a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4756: 
                   4757:     <p>Otherwise, run these steps:</p>
                   4758: 
                   4759:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4760: 
                   4761:      <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
                   4762:      error</a>.</p></li>
                   4763: 
                   4764:      <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
                   4765:      open elements</a>.</p></li>
                   4766: 
                   4767:     </ol></dd>
                   4768: 
                   4769:    <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
                   4770:    <dt>An end tag whose tag name is "p"</dt>
                   4771:    <dd>
                   4772: 
                   4773:     <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>
                   4774:     with the same tag name as that of the token, then this is a
                   4775:     <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
                   4776:     "p" had been seen, then reprocess the current token.</p>
                   4777: 
                   4778:     <p>Otherwise, run these steps:</p>
                   4779: 
                   4780:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4781:      for elements with the same tag name as the token.</p></li>
                   4782: 
                   4783:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4784:      the same tag name as that of the token, then this is a
                   4785:      <a href="#parse-error">parse error</a>.</p></li>
                   4786: 
                   4787:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4788:      until an element with the same tag name as the token has been
                   4789:      popped from the stack.</p></li>
                   4790: 
                   4791:     </ol></dd>
                   4792: 
                   4793:    <!-- as normal, but needs care as the elements have optional tags -->
                   4794:    <dt>An end tag whose tag name is one of: "dd", "dt", "li"</dt>
                   4795:    <dd>
                   4796: 
                   4797:     <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>
                   4798:     with the same tag name as that of the token, then this is a
                   4799:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4800: 
                   4801:     <p>Otherwise, run these steps:</p>
                   4802: 
                   4803:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4804:      for elements with the same tag name as the token.</p></li>
                   4805: 
                   4806:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4807:      the same tag name as that of the token, then this is a
                   4808:      <a href="#parse-error">parse error</a>.</p></li>
                   4809: 
                   4810:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4811:      until an element with the same tag name as the token has been
                   4812:      popped from the stack.</p></li>
                   4813: 
                   4814:     </ol></dd>
                   4815: 
                   4816:    <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
                   4817:    <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
                   4818:    <dd>
                   4819: 
                   4820:     <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>
                   4821:     whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
                   4822:     then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4823: 
                   4824:     <p>Otherwise, run these steps:</p>
                   4825: 
                   4826:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4827: 
                   4828:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4829:      the same tag name as that of the token, then this is a
                   4830:      <a href="#parse-error">parse error</a>.</p></li>
                   4831: 
                   4832:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4833:      until an element whose tag name is one of "h1", "h2", "h3", "h4",
                   4834:      "h5", or "h6" has been popped from the stack.</p></li>
                   4835: 
                   4836:     </ol></dd>
                   4837: 
                   4838:    <dt>An end tag whose tag name is "sarcasm"</dt>
                   4839:    <dd>
                   4840:     <p>Take a deep breath, then act as described in the "any other end
                   4841:     tag" entry below.</p>
                   4842:    </dd>
                   4843: 
                   4844:    <!-- ADOPTION AGENCY ELEMENTS
                   4845:         Mozilla-only: bdo blink del ins sub sup q
                   4846:         Safari-only: code dfn kbd nobr samp var wbr
                   4847:         Both: a b big em font i s small strike strong tt u -->
                   4848: 
                   4849:    <dt>A start tag whose tag name is "a"</dt>
                   4850:    <dd>
                   4851: 
                   4852:     <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
                   4853:     contains an element whose tag name is "a" between the end of
                   4854:     the list and the last marker on the list (or the start of the
                   4855:     list if there is no marker on the list), then this is a
                   4856:     <a href="#parse-error">parse error</a>; act as if an end tag with the tag
                   4857:     name "a" had been seen, then remove that element from the
                   4858:     <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
                   4859:     <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
                   4860:     already remove it (it might not have if the element is not
                   4861:     <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
                   4862:     scope</a>).</p>
                   4863: 
                   4864:     <p class="example">In the non-conforming stream
                   4865:     <code>&lt;a&#160;href="a"&gt;a&lt;table&gt;&lt;a&#160;href="b"&gt;b&lt;/table&gt;x</code>,
                   4866:     the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
                   4867:     the second one, and the "x" character would be inside a link
                   4868:     to "b", not to "a". This is despite the fact that the outer
                   4869:     <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
                   4870:     regular <code>&lt;/a&gt;</code> end tag at the start of the table
                   4871:     wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
                   4872: 
                   4873:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4874:     any.</p>
                   4875: 
                   4876:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4877:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4878:     elements</a>.</p>
                   4879: 
                   4880:    </dd>
                   4881: 
                   4882:    <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
                   4883:    "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
                   4884:    <dd>
                   4885: 
                   4886:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4887:     any.</p>
                   4888: 
                   4889:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4890:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4891:     elements</a>.</p>
                   4892: 
                   4893:    </dd>
                   4894: 
                   4895:    <dt>A start tag whose tag name is "nobr"</dt>
                   4896:    <dd>
                   4897: 
                   4898:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4899:     any.</p>
                   4900: 
                   4901:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   4902:     element in scope">has a <code>nobr</code> element in scope</a>,
                   4903:     then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
                   4904:     the tag name "nobr" had been seen, then once again
                   4905:     <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
                   4906:     any.</p>
                   4907: 
                   4908:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4909:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4910:     elements</a>.</p>
                   4911: 
                   4912:    </dd>
                   4913: 
                   4914:    <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
                   4915:    "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
                   4916:    "strike", "strong", "tt", "u"</dt>
                   4917:    <dd>
                   4918: 
                   4919:     <p>Follow these steps:</p>
                   4920: 
                   4921:     <ol><li>
                   4922: 
                   4923:       <p>Let the <var title="">formatting element</var> be the
                   4924:       last element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   4925:       elements</a> that:</p>
                   4926: 
                   4927:       <ul><li>is between the end of the list and the last scope
                   4928:        marker in the list, if any, or the start of the list
                   4929:        otherwise, and</li>
                   4930: 
                   4931:        <li>has the same tag name as the token.</li>
                   4932: 
                   4933:       </ul><p>If there is no such node, or, if that node is also in the
                   4934:       <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
                   4935:       <a href="#parse-error">parse error</a>; ignore the token, and abort these
                   4936:       steps.</p>
                   4937: 
                   4938:       <p>Otherwise, if there is such a node, but that node is not
                   4939:       in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
                   4940:       <a href="#parse-error">parse error</a>; remove the element from the list,
                   4941:       and abort these steps.</p>
                   4942: 
                   4943:       <p>Otherwise, there is a <var title="">formatting
                   4944:       element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
                   4945:       open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
                   4946:       element in scope">in scope</a>. If the element is not the
                   4947:       <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
                   4948:       error</a>. In any case, proceed with the algorithm as
                   4949:       written in the following steps.</p>
                   4950: 
                   4951:      </li>
                   4952: 
                   4953:      <li><p>Let the <var title="">furthest block</var> be the
                   4954:      topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
                   4955:      is lower in the stack than the <var title="">formatting
                   4956:      element</var>, and is not an element in the
                   4957:      <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
                   4958:      categories. There might not be one.</p></li>
                   4959: 
                   4960:      <li><p>If there is no <var title="">furthest block</var>,
                   4961:      then the UA must skip the subsequent steps and instead just
                   4962:      pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
                   4963:      elements</a>, from the <a href="#current-node">current node</a> up to and
                   4964:      including the <var title="">formatting element</var>, and
                   4965:      remove the <var title="">formatting element</var> from the
                   4966:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
                   4967: 
                   4968:      <li><p>Let the <var title="">common ancestor</var> be the element
                   4969:      immediately above the <var title="">formatting element</var> in the
                   4970:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   4971: 
                   4972:      <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
                   4973:      formatting elements</a> relative to the elements on either
                   4974:      side of it in the list.</p></li>
                   4975: 
                   4976:      <li>
                   4977: 
                   4978:       <p>Let <var title="">node</var> and <var title="">last node</var> be the
                   4979:       <var title="">furthest block</var>. Follow these steps:</p>
                   4980: 
                   4981:       <ol><li>Let <var title="">node</var> be the element immediately
                   4982:        above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
                   4983:        elements</a>.</li>
                   4984: 
                   4985:        <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
                   4986:        active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
                   4987:        elements</a> and then go back to step 1.</li>
                   4988: 
                   4989:        <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
                   4990:        in the overall algorithm.</li>
                   4991: 
                   4992:        <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
                   4993:        bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   4994:        elements</a>.</li>
                   4995: 
                   4996:        <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   4997:        element <var title="">node</var> was created, replace the entry
                   4998:        for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
                   4999:        formatting elements</a> with an entry for the new element,
                   5000:        replace the entry for <var title="">node</var> in the
                   5001:        <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
                   5002:        element, and let <var title="">node</var> be the new
                   5003:        element.</li>
                   5004: 
                   5005:        <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
                   5006:        parent node if any.</li>
                   5007: 
                   5008:        <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
                   5009: 
                   5010:        <li>Return to step 1 of this inner set of steps.</li>
                   5011: 
                   5012:       </ol></li>
                   5013: 
                   5014:      <li>
                   5015: 
                   5016:       <p>If the <var title="">common ancestor</var> node is a
                   5017:       <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>,
                   5018:       <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,
                   5019:       <a href="#foster-parent">foster parent</a> whatever <var title="">last
                   5020:       node</var> ended up being in the previous step, first removing
                   5021:       it from its previous parent node if any.</p>
                   5022: 
                   5023:       <p>Otherwise, append whatever <var title="">last node</var>
                   5024:       ended up being in the previous step to the <var title="">common
                   5025:       ancestor</var> node, first removing it from its previous parent
                   5026:       node if any.</p>
                   5027: 
                   5028:      </li>
                   5029: 
                   5030:      <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   5031:      <var title="">formatting element</var> was created.</p></li>
                   5032: 
                   5033:      <li><p>Take all of the child nodes of the <var title="">furthest
                   5034:      block</var> and append them to the element created in the last
                   5035:      step.</p></li>
                   5036: 
                   5037:      <li><p>Append that new element to the <var title="">furthest
                   5038:      block</var>.</p></li>
                   5039: 
                   5040:      <li><p>Remove the <var title="">formatting element</var> from the
                   5041:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
                   5042:      new element into the <a href="#list-of-active-formatting-elements">list of active formatting
                   5043:      elements</a> at the position of the aforementioned
                   5044:      bookmark.</p></li>
                   5045: 
                   5046:      <li><p>Remove the <var title="">formatting element</var> from the
                   5047:      <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
                   5048:      into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
                   5049:      the position of the <var title="">furthest block</var> in that
                   5050:      stack.</p></li>
                   5051: 
                   5052:      <li><p>Jump back to step 1 in this series of steps.</p></li>
                   5053: 
                   5054:     </ol><!--XXX
                   5055:     <div class="example">
                   5056:      <p class="XXX">Need an example.</p>
                   5057:     </div>
                   5058: --><p class="note">Because of the way this algorithm causes elements to
                   5059:     change parents, it has been dubbed the "adoption agency algorithm"
                   5060:     (in contrast with other possibly algorithms for dealing with
                   5061:     misnested content, which included the "incest algorithm", the
                   5062:     "secret affair algorithm", and the "Heisenberg algorithm").</p>
                   5063: 
                   5064:    </dd>
                   5065: 
                   5066:    <dt>A start tag whose tag name is "button"</dt>
                   5067:    <dd>
                   5068: 
                   5069:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5070:     an element in scope">has a <code>button</code> element in
                   5071:     scope</a>, then this is a <a href="#parse-error">parse error</a>;
                   5072:     act as if an end tag with the tag name "button" had been seen,
                   5073:     then reprocess the token.</p>
                   5074: 
                   5075:     <p>Otherwise:</p>
                   5076: 
                   5077:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5078:     any.</p>
                   5079: 
                   5080:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5081: 
                   5082:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5083:     formatting elements</a>.</p>
                   5084: 
                   5085:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5086: 
                   5087:    </dd>
                   5088: 
                   5089:    <dt>A start tag token whose tag name is one of: "applet",
                   5090:    "marquee", "object"</dt>
                   5091:    <dd>
                   5092: 
                   5093:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5094:     any.</p>
                   5095: 
                   5096:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5097: 
                   5098:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5099:     formatting elements</a>.</p>
                   5100: 
                   5101:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5102: 
                   5103:    </dd>
                   5104: 
                   5105:    <dt>An end tag token whose tag name is one of: "applet", "button",
                   5106:    "marquee", "object"</dt>
                   5107:    <dd>
                   5108: 
                   5109:     <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>
                   5110:     with the same tag name as that of the token, then this is a
                   5111:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   5112: 
                   5113:     <p>Otherwise, run these steps:</p>
                   5114: 
                   5115:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5116: 
                   5117:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   5118:      the same tag name as that of the token, then this is a
                   5119:      <a href="#parse-error">parse error</a>.</p></li>
                   5120: 
                   5121:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   5122:      until an element with the same tag name as the token has been
                   5123:      popped from the stack.</p></li>
                   5124: 
                   5125:      <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
                   5126:      last marker</a>.</li>
                   5127: 
                   5128:     </ol></dd>
                   5129: 
                   5130:    <dt>A start tag whose tag name is "table"</dt>
                   5131:    <dd>
                   5132: 
                   5133:     <p>If the <code>Document</code> is <em>not</em> set to
                   5134:     <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
                   5135:     elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
                   5136:     <code>p</code> element in scope</a>, then act as if an end tag
                   5137:     with the tag name "p" had been seen.</p> <!-- i hate myself (this
                   5138:     quirk was basically caused by acid2; if i'd realised we could
                   5139:     change the specs when i wrote acid2, we could have avoided having
                   5140:     any parsing-mode quirks) -Hixie -->
                   5141: 
                   5142:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5143: 
                   5144:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5145: 
                   5146:     <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>
                   5147: 
                   5148:    </dd>
                   5149: 
                   5150:    <dt>A start tag whose tag name is one of: "area", "basefont",
                   5151:    "bgsound", "br", "embed", "img", "input", "keygen", "spacer",
                   5152:    "wbr"</dt>
                   5153:    <dd>
                   5154: 
                   5155:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5156:     any.</p>
                   5157: 
                   5158:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5159:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5160:     elements</a>.</p>
                   5161: 
                   5162:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5163:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5164: 
                   5165:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
                   5166:     shouldn't really do it for <area>, <basefont>, <bgsound>, and
                   5167:     <spacer> -->
                   5168: 
                   5169:    </dd>
                   5170: 
                   5171:    <dt>A start tag whose tag name is one of: "param", "source"</dt>
                   5172:    <dd>
                   5173: 
                   5174:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5175:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5176:     elements</a>.</p>
                   5177: 
                   5178:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5179:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5180: 
                   5181:    </dd>
                   5182: 
                   5183:    <dt>A start tag whose tag name is "hr"</dt>
                   5184:    <dd>
                   5185: 
                   5186:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5187:     an element in scope">has a <code>p</code> element in
                   5188:     scope</a>, then act as if an end tag with the tag name
                   5189:     "p" had been seen.</p>
                   5190: 
                   5191:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5192:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5193:     elements</a>.</p>
                   5194: 
                   5195:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5196:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5197: 
                   5198:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5199: 
                   5200:    </dd>
                   5201: 
                   5202:    <dt>A start tag whose tag name is "image"</dt>
                   5203:    <dd>
                   5204:     <p><a href="#parse-error">Parse error</a>. Change the token's tag name
                   5205:     to "img" and reprocess it. (Don't ask.)</p> <!-- As of
                   5206:     2005-12, studies showed that around 0.2% of pages used the
                   5207:     <image> element. -->
                   5208:    </dd>
                   5209: 
                   5210:    <dt id="isindex">A start tag whose tag name is "isindex"</dt>
                   5211:    <dd>
                   5212: 
                   5213:     <p><a href="#parse-error">Parse error</a>.</p>
                   5214: 
                   5215:     <p>If the <a href="#form-element-pointer"><code title="">form</code> element
                   5216:     pointer</a> is not null, then ignore the token.</p>
                   5217: 
                   5218:     <p>Otherwise:</p>
                   5219: 
                   5220:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5221:     token's <i>self-closing flag</i></a>, if it is set.</p> <!--
                   5222:     purely to reduce the number of errors (we don't care if they
                   5223:     included the /, they're not supposed to be including the tag at
                   5224:     all! -->
                   5225: 
                   5226:     <p>Act as if a start tag token with the tag name "form" had been seen.</p>
                   5227: 
                   5228:     <p>If the token has an attribute called "action", set the
                   5229:     <code title="attr-form-action">action</code> attribute on the
                   5230:     resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
                   5231:     "action" attribute of the token.</p>
                   5232: 
                   5233:     <p>Act as if a start tag token with the tag name "hr" had been
                   5234:     seen.</p>
                   5235: 
                   5236:     <p>Act as if a start tag token with the tag name "label" had been
                   5237:     seen.</p>
                   5238: 
                   5239:     <p>Act as if a stream of character tokens had been seen (see below
                   5240:     for what they should say).</p>
                   5241: 
                   5242:     <p>Act as if a start tag token with the tag name "input" had been
                   5243:     seen, with all the attributes from the "isindex" token except
                   5244:     "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
                   5245:     <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
                   5246: 
                   5247:     <p>Act as if a stream of character tokens had been seen (see
                   5248:     below for what they should say).</p>
                   5249: 
                   5250:     <p>Act as if an end tag token with the tag name "label" had been
                   5251:     seen.</p>
                   5252: 
                   5253:     <p>Act as if a start tag token with the tag name "hr" had been
                   5254:     seen.</p>
                   5255: 
                   5256:     <p>Act as if an end tag token with the tag name "form" had been
                   5257:     seen.</p>
                   5258: 
                   5259:     <p>If the token has an attribute with the name "prompt", then the
                   5260:     first stream of characters must be the same string as given in
                   5261:     that attribute, and the second stream of characters must be
                   5262:     empty. Otherwise, the two streams of character tokens together
                   5263:     should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
                   5264:     equivalent of "This is a searchable index. Insert your search
                   5265:     keywords here: (input field)" in the user's preferred
                   5266:     language.</p>
                   5267: 
                   5268:    </dd>
                   5269: 
                   5270:    <dt>A start tag whose tag name is "textarea"</dt>
                   5271:    <dd>
                   5272: 
                   5273:     <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   5274:      token.</p></li>
                   5275: 
                   5276:      <li><p>If the next token is a U+000A LINE FEED (LF) character
                   5277:      token, then ignore that token and move on to the next
                   5278:      one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
                   5279:      ignored as an authoring convenience.)</p></li>
                   5280: 
                   5281:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
                   5282:      the RCDATA state.</p></li>
                   5283: 
                   5284:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
                   5285:      current <a href="#insertion-mode">insertion mode</a>.</p>
                   5286: 
                   5287:      </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
                   5288:      ok".</p></li>
                   5289: 
1.91      mike     5290:      <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
                   5291:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     5292: 
                   5293:     </ol></dd>
                   5294: 
                   5295:    <dt>A start tag whose tag name is "xmp"</dt>
                   5296:    <dd>
                   5297: 
                   5298:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5299:     any.</p>
                   5300: 
                   5301:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5302: 
1.91      mike     5303:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5304: 
                   5305:    </dd>
                   5306: 
                   5307:    <dt>A start tag whose tag name is "iframe"</dt>
                   5308:    <dd>
                   5309: 
                   5310:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5311: 
1.91      mike     5312:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5313: 
                   5314:    </dd>
                   5315: 
                   5316:    <dt>A start tag whose tag name is "noembed"</dt>
                   5317:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   5318:    <dd>
                   5319: 
1.91      mike     5320:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5321: 
                   5322:    </dd>
                   5323: 
                   5324:    <dt>A start tag whose tag name is "select"</dt>
                   5325:    <dd>
                   5326: 
                   5327:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5328:     any.</p>
                   5329: 
                   5330:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5331: 
                   5332:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5333: 
                   5334:     <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>",
                   5335:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5336:     body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   5337:     row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   5338:     cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
                   5339:     "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
                   5340:     table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
                   5341:     to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
                   5342: 
                   5343:    </dd>
                   5344: 
                   5345:    <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
                   5346:    <dd>
                   5347: 
                   5348:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5349:     element in scope">has an <code>option</code> element in
                   5350:     scope</a>, then act as if an end tag with the tag name "option"
                   5351:     had been seen.</p>
                   5352: 
                   5353:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5354:     any.</p>
                   5355: 
                   5356:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5357: 
                   5358:    </dd>
                   5359: 
                   5360:    <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
                   5361:    <dd>
                   5362: 
                   5363:     <!-- the parsing rules for ruby really don't match IE much at all,
                   5364:          but in practice the markup used is very simple and so strict
                   5365:          compatibility with IE isn't required. For example, as defined
                   5366:          here we get very, very different behaviour than IE for
                   5367:          pathological cases like:
                   5368: 
                   5369:            <ruby><ol><li><p>a<rt>b
                   5370:            <ruby>a<rt>b<p>c
                   5371: 
                   5372:          But in practice most ruby markup falls into these cases:
                   5373: 
                   5374:            <ruby>a<rt>b</ruby>
                   5375:            <ruby>a<rp>b<rt>c<rp>d</ruby>
                   5376:            <ruby>a<rt>b</rt></ruby>
                   5377:            <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
                   5378: 
                   5379:     -->
                   5380: 
                   5381:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5382:     element in scope">has a <code>ruby</code> element in scope</a>,
                   5383:     then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
                   5384:     node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
                   5385:     <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
                   5386:     node</a> up to the node immediately before the bottommost
                   5387:     <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
                   5388:     elements</a>.</p>
                   5389: 
                   5390:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5391: 
                   5392:    </dd>
                   5393: 
                   5394:    <dt>An end tag whose tag name is "br"</dt>
                   5395:    <dd>
                   5396:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
                   5397:     the tag name "br" had been seen. Ignore the end tag token.</p>
                   5398:    </dd>
                   5399: 
                   5400:    <dt>A start tag whose tag name is "math"</dt>
                   5401:    <dd>
                   5402: 
                   5403:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5404:     any.</p>
                   5405: 
                   5406:     <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
                   5407:     fixes the case of MathML attributes that are not all
                   5408:     lowercase.)</p>
                   5409: 
                   5410:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5411:     fixes the use of namespaced attributes, in particular XLink.)</p>
                   5412: 
                   5413:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5414:     <a href="#mathml-namespace">MathML namespace</a>.</p>
                   5415: 
                   5416:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5417:     the following change would be implied, except we'd have to do it
                   5418:     even in the face of a self-closed tag:
                   5419:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5420:     -->
                   5421: 
                   5422:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5423:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5424:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5425:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5426: 
                   5427:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5428:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5429:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5430:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5431:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5432:     foreign content">in foreign content</a>".</p>
                   5433: 
                   5434:    </dd>
                   5435: 
                   5436:    <dt>A start tag whose tag name is "svg"</dt>
                   5437:    <dd>
                   5438: 
                   5439:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5440:     any.</p>
                   5441: 
                   5442:     <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
                   5443:     the case of SVG attributes that are not all lowercase.)</p>
                   5444: 
                   5445:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5446:     fixes the use of namespaced attributes, in particular XLink in
                   5447:     SVG.)</p>
                   5448: 
                   5449:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5450:     <a href="#svg-namespace">SVG namespace</a>.</p>
                   5451: 
                   5452:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5453:     the following change would be implied, except we'd have to do it
                   5454:     even in the face of a self-closed tag:
                   5455:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5456:     -->
                   5457: 
                   5458:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5459:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5460:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5461:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5462: 
                   5463:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5464:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5465:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5466:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5467:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5468:     foreign content">in foreign content</a>".</p>
                   5469: 
                   5470:    </dd>
                   5471: 
                   5472:    <dt>A start <!--or end--> tag whose tag name is one of: "caption",
                   5473:    "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
                   5474:    "thead", "tr"</dt>
                   5475:    <!--<dt>An end tag whose tag name is one of: "area", "base",
                   5476:    "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
                   5477:    "img", "input", "isindex", "keygen", "link", "meta", "noembed",
                   5478:    "noframes", "param", "script", "select", "source", "spacer",
                   5479:    "style", "table", "textarea", "title", "wbr"</dt>-->
                   5480:    <!--<dt>An end tag whose tag name is "noscript", if the
                   5481:    <span>scripting flag</span> is enabled</dt>-->
                   5482:    <dd>
                   5483:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5484:     <!-- end tags are commented out because since they can never end
                   5485:     up on the stack anyway, the default end tag clause will
                   5486:     automatically handle them. we don't want to have text in the spec
                   5487:     that is just an optimisation, as that detracts from the spec
                   5488:     itself -->
                   5489:    </dd>
                   5490: 
                   5491:    <dt>Any other start tag</dt>
                   5492:    <dd>
                   5493: 
                   5494:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5495:     any.</p>
                   5496: 
                   5497:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5498: 
                   5499:     <p class="note">This element will be a <a href="#phrasing">phrasing</a>
                   5500:     element.</p>
                   5501: 
                   5502:    </dd>
                   5503: 
                   5504:    <dt>Any other end tag</dt>
                   5505:    <dd>
                   5506: 
                   5507:     <p>Run the following steps:</p>
                   5508: 
                   5509:     <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   5510:      node</a> (the bottommost node of the stack).</p></li>
                   5511: 
                   5512:      <li><p>If <var title="">node</var> has the same tag name as
                   5513:      the end tag token, then:</p>
                   5514: 
                   5515:       <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5516: 
                   5517:        <li><p>If the tag name of the end tag token does not match
                   5518:        the tag name of the <a href="#current-node">current node</a>, this is a
                   5519:        <a href="#parse-error">parse error</a>.</p></li>
                   5520: 
                   5521:        <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
                   5522:        to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
                   5523: 
                   5524:       </ol></li>
                   5525: 
                   5526:      <li><p>Otherwise, if <var title="">node</var> is in neither the
                   5527:      <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
                   5528:      category, then this is a <a href="#parse-error">parse error</a>; ignore the
                   5529:      token, and abort these steps.</p></li>
                   5530: 
                   5531:      <li><p>Set <var title="">node</var> to the previous entry in the
                   5532:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   5533: 
                   5534:      <li><p>Return to step 2.</p></li>
                   5535: 
                   5536:     </ol></dd>
                   5537: 
1.91      mike     5538:   </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     5539: 
                   5540:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.91      mike     5541:   mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>", tokens must be
1.1       mike     5542:   handled as follows:</p>
                   5543: 
                   5544:   <dl class="switch"><dt>A character token</dt>
                   5545:    <dd>
                   5546: 
                   5547:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   5548:     character</a> into the <a href="#current-node">current node</a>.</p>
                   5549: 
                   5550:    </dd>
                   5551: 
                   5552:    <dt>An end-of-file token</dt>
                   5553:    <dd>
                   5554: 
                   5555:     <!-- can't be the fragment case -->
                   5556:     <p><a href="#parse-error">Parse error</a>.</p>
                   5557: 
                   5558:     <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
                   5559:     element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
                   5560:     executed"</a>.</p>
                   5561: 
                   5562:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5563:     elements</a>.</p>
                   5564: 
                   5565:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5566:     insertion mode</a> and reprocess the current token.</p>
                   5567: 
                   5568:    </dd>
                   5569: 
                   5570:    <dt>An end tag whose tag name is "script"</dt>
                   5571:    <dd>
                   5572: 
                   5573:     <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
                   5574:     (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
                   5575: 
                   5576:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5577:     elements</a>.</p>
                   5578: 
                   5579:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5580:     insertion mode</a>.</p>
                   5581: 
                   5582:     <p>Let the <var title="">old insertion point</var> have the
                   5583:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   5584:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   5585:     input character</a>.</p>
                   5586: 
                   5587:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5588:     one.</p>
                   5589: 
                   5590:     <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,
                   5591:     which might cause <a href="dom.html#dom-document-write" title="dom-document-write">new characters
                   5592:     to be inserted into the tokenizer</a>, and might cause the
                   5593:     tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
                   5594: 
                   5595:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5596:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   5597:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5598: 
                   5599:     <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
                   5600:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   5601:     might be the "undefined" value.)</p>
                   5602: 
                   5603:     <p id="scriptTagParserResumes">At this stage, if there is a
                   5604:     <a href="semantics.html#pending-external-script">pending external script</a>, then:</p>
                   5605: 
                   5606:     <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
                   5607: 
                   5608:      <dd>
                   5609: 
                   5610:       <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
                   5611:       processing of any nested invocations of the tokenizer, yielding
                   5612:       control back to the caller. (Tokenization will resume when the
                   5613:       caller returns to the "outer" tree construction stage.)</p>
                   5614: 
                   5615:       <p class="note">The tree construction stage of this particular
                   5616:       parser is <a href="#nestedParsing">being called reentrantly</a>,
                   5617:       say from a call to <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code>.</p>
                   5618: 
                   5619:      </dd>
                   5620: 
                   5621: 
                   5622:      <dt>Otherwise:</dt>
                   5623: 
                   5624:      <dd>
                   5625: 
                   5626:       <p>Follow these steps:</p>
                   5627: 
                   5628:       <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-external-script">pending
                   5629:        external script</a>. There is no longer a <a href="semantics.html#pending-external-script">pending
                   5630:        external script</a>.</p></li>
                   5631: 
                   5632:        <li><p><a href="browsers.html#pause">Pause</a> until the script has <a href="semantics.html#completed-loading">completed
                   5633:        loading</a>.</p></li>
                   5634: 
                   5635:        <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
                   5636:        <a href="#next-input-character">next input character</a>.</p></li>
                   5637: 
                   5638:        <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
                   5639:        by one (it should be zero before this step, so this sets it to
                   5640:        one).</p></li>
                   5641: 
                   5642:        <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute the
                   5643:        script</a>.</p></li>
                   5644: 
                   5645:        <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
                   5646:        by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
                   5647:        zero (which it always should be at this point), then set the
                   5648:        <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5649: 
                   5650:        </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
                   5651:        again.</p></li>
                   5652: 
                   5653:        <li><p>If there is once again a <a href="semantics.html#pending-external-script">pending external
                   5654:        script</a>, then repeat these steps from step 1.</p></li>
                   5655: 
                   5656:       </ol></dd>
                   5657: 
                   5658:     </dl></dd>
                   5659: 
                   5660:    <dt>Any other end tag</dt>
                   5661:    <dd>
                   5662: 
                   5663:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5664:     elements</a>.</p>
                   5665: 
                   5666:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5667:     insertion mode</a>.</p>
                   5668: 
                   5669:    </dd>
                   5670: 
                   5671:   </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>
                   5672: 
                   5673:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
                   5674:   mode: in table">in table</a>", tokens must be handled as follows:</p>
                   5675: 
                   5676:   <dl class="switch"><dt>A character token</dt>
                   5677:    <dd>
                   5678: 
                   5679:      <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
                   5680:      be an empty list of tokens.</p>
                   5681: 
                   5682:      <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   5683:      <a href="#insertion-mode">insertion mode</a>.</p>
                   5684: 
                   5685:      <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
                   5686:      reprocess the token.</p>
                   5687: 
                   5688:    </dd>
                   5689: 
                   5690:    <dt>A comment token</dt>
                   5691:    <dd>
                   5692:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   5693:     node</a> with the <code title="">data</code> attribute set to
                   5694:     the data given in the comment token.</p>
                   5695:    </dd>
                   5696: 
                   5697:    <dt>A DOCTYPE token</dt>
                   5698:    <dd>
                   5699:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5700:    </dd>
                   5701: 
                   5702:    <dt>A start tag whose tag name is "caption"</dt>
                   5703:    <dd>
                   5704: 
                   5705:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5706:     below.)</p>
                   5707: 
                   5708:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5709:     formatting elements</a>.</p>
                   5710: 
                   5711:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5712:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
                   5713: 
                   5714:    </dd>
                   5715: 
                   5716:    <dt>A start tag whose tag name is "colgroup"</dt>
                   5717:    <dd>
                   5718: 
                   5719:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5720:     below.)</p>
                   5721: 
                   5722:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5723:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
                   5724:     group</a>".</p>
                   5725: 
                   5726:    </dd>
                   5727: 
                   5728:    <dt>A start tag whose tag name is "col"</dt>
                   5729:    <dd>
                   5730:     <p>Act as if a start tag token with the tag name "colgroup"
                   5731:     had been seen, then reprocess the current token.</p>
                   5732:    </dd>
                   5733: 
                   5734:    <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
                   5735:    <dd>
                   5736: 
                   5737:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5738:     below.)</p>
                   5739: 
                   5740:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5741:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5742:     body</a>".</p>
                   5743: 
                   5744:    </dd>
                   5745: 
                   5746:    <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
                   5747:    <dd>
                   5748:     <p>Act as if a start tag token with the tag name "tbody" had
                   5749:     been seen, then reprocess the current token.</p>
                   5750:    </dd>
                   5751: 
                   5752:    <dt>A start tag whose tag name is "table"</dt>
                   5753:    <dd>
                   5754: 
                   5755:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
                   5756:     the tag name "table" had been seen, then, if that token wasn't
                   5757:     ignored, reprocess the current token.</p>
                   5758: 
                   5759:     <p class="note">The fake end tag token here can only be
                   5760:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5761: 
                   5762:    </dd>
                   5763: 
                   5764:    <dt>An end tag whose tag name is "table"</dt>
                   5765:    <dd>
                   5766: 
                   5767:     <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
                   5768:     scope</a> with the same tag name as the token, this is a
                   5769:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5770:     case</a>)</p>
                   5771: 
                   5772:     <p>Otherwise:</p>
                   5773: 
                   5774:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
                   5775:     element has been popped from the stack.</p>
                   5776: 
                   5777:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   5778: 
                   5779:    </dd>
                   5780: 
                   5781:    <dt>An end tag whose tag name is one of: "body", "caption",
                   5782:    "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
                   5783:    "thead", "tr"</dt>
                   5784:    <dd>
                   5785:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5786:    </dd>
                   5787: 
                   5788:    <dt>A start tag whose tag name is one of: "style", "script"</dt>
                   5789:    <dd>
                   5790: 
                   5791:     <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
                   5792:     mode</a>.</p>
                   5793: 
                   5794:    </dd>
                   5795: 
                   5796:    <dt>A start tag whose tag name is "input"</dt>
                   5797:    <dd>
                   5798: 
                   5799:     <p>If the token does not have an attribute with the name "type",
                   5800:     or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   5801:     case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
                   5802:     else" entry below.</p>
                   5803: 
                   5804:     <p>Otherwise:</p>
                   5805: 
                   5806:     <p><a href="#parse-error">Parse error</a>.</p>
                   5807: 
                   5808:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5809: 
                   5810:     <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
                   5811:     open elements</a>.</p>
                   5812: 
                   5813:    </dd>
                   5814: 
                   5815:    <dt>An end-of-file token</dt>
                   5816:    <dd>
                   5817: 
                   5818:     <p>If the <a href="#current-node">current node</a> is not the root
                   5819:     <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
                   5820:     error</a>.</p>
                   5821: 
                   5822:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   5823:     the <a href="#fragment-case">fragment case</a>.</p>
                   5824: 
                   5825:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   5826: 
                   5827:    </dd>
                   5828: 
                   5829:    <dt>Anything else</dt>
                   5830:    <dd>
                   5831: 
                   5832:     <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
                   5833:     rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   5834:     body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
                   5835:     <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   5836:     <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
                   5837:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
                   5838:     into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
                   5839: 
                   5840:    </dd>
                   5841: 
                   5842:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
                   5843:   back to a table context</dfn>, it means that the UA must, while
                   5844:   the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-table-element">table</a></code>
                   5845:   element or an <code><a href="semantics.html#the-html-element">html</a></code> element, pop elements from the
                   5846:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   5847: 
                   5848:   <p class="note">The <a href="#current-node">current node</a> being an
                   5849:   <code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="#fragment-case">fragment
                   5850:   case</a>.</p>
                   5851: 
                   5852: 
                   5853: 
                   5854:   <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>
                   5855: 
                   5856:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
                   5857:   mode: in table text">in table text</a>", tokens must be handled
                   5858:   as follows:</p>
                   5859: 
                   5860:   <dl class="switch"><dt>A character token</dt>
                   5861:    <dd>
                   5862: 
                   5863:     <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
                   5864:     tokens</a></var> list.</p>
                   5865: 
                   5866:    </dd>
                   5867: 
                   5868: 
                   5869:    <dt>Anything else</dt>
                   5870:    <dd>
                   5871: 
                   5872:     <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
                   5873:     tokens</a></var> list are character tokens that are not one of U+0009
                   5874:     CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
                   5875:     (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
                   5876:     reprocess those character tokens using the rules given in the
                   5877:     "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
                   5878:     table">in table</a>" insertion mode.</p>
                   5879: 
                   5880:     <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
                   5881:     characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
                   5882:     tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
                   5883: 
                   5884:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5885:     insertion mode</a> and reprocess the token.</p>
                   5886: 
                   5887:    </dd>
                   5888: 
                   5889:   </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>
                   5890: 
                   5891:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
                   5892:   mode: in caption">in caption</a>", tokens must be handled as follows:</p>
                   5893: 
                   5894:   <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
                   5895:    <dd>
                   5896: 
                   5897:     <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
                   5898:     scope</a> with the same tag name as the token, this is a
                   5899:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5900:     case</a>)</p>
                   5901: 
                   5902:     <p>Otherwise:</p>
                   5903: 
                   5904:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   5905: 
                   5906:     <p>Now, if the <a href="#current-node">current node</a> is not a
                   5907:     <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
                   5908:     error</a>.</p>
                   5909: 
                   5910:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
                   5911:     element has been popped from the stack.</p>
                   5912: 
                   5913:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   5914:     the last marker</a>.</p>
                   5915: 
                   5916:     <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>
                   5917: 
                   5918:    </dd>
                   5919: 
                   5920:    <dt>A start tag whose tag name is one of: "caption", "col",
                   5921:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   5922:    <dt>An end tag whose tag name is "table"</dt>
                   5923:    <dd>
                   5924: 
                   5925:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   5926:     name "caption" had been seen, then, if that token wasn't
                   5927:     ignored, reprocess the current token.</p>
                   5928: 
                   5929:     <p class="note">The fake end tag token here can only be
                   5930:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5931: 
                   5932:    </dd>
                   5933: 
                   5934:    <dt>An end tag whose tag name is one of: "body", "col",
                   5935:    "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
                   5936:    "tr"</dt>
                   5937:    <dd>
                   5938:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5939:    </dd>
                   5940: 
                   5941:    <dt>Anything else</dt>
                   5942:    <dd>
                   5943:     <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
                   5944:     mode</a>.</p>
                   5945:    </dd>
                   5946: 
                   5947:   </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>
                   5948: 
                   5949:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
                   5950:   mode: in column group">in column group</a>", tokens must be handled as follows:</p>
                   5951: 
                   5952:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   5953:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   5954:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   5955:    <dd>
                   5956:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   5957:     the <a href="#current-node">current node</a>.</p>
                   5958:    </dd>
                   5959: 
                   5960:    <dt>A comment token</dt>
                   5961:    <dd>
                   5962:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   5963:     node</a> with the <code title="">data</code> attribute set to
                   5964:     the data given in the comment token.</p>
                   5965:    </dd>
                   5966: 
                   5967:    <dt>A DOCTYPE token</dt>
                   5968:    <dd>
                   5969:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5970:    </dd>
                   5971: 
                   5972:    <dt>A start tag whose tag name is "html"</dt>
                   5973:    <dd>
                   5974:     <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
                   5975:     mode</a>.</p>
                   5976:    </dd>
                   5977: 
                   5978:    <dt>A start tag whose tag name is "col"</dt>
                   5979:    <dd>
                   5980: 
                   5981:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5982:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5983:     elements</a>.</p>
                   5984: 
                   5985:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5986:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5987: 
                   5988:    </dd>
                   5989: 
                   5990:    <dt>An end tag whose tag name is "colgroup"</dt>
                   5991:    <dd>
                   5992: 
                   5993:     <p>If the <a href="#current-node">current node</a> is the root
                   5994:     <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
                   5995:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   5996:     case</a>)</p>
                   5997: 
                   5998:     <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
                   5999:     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
                   6000:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   6001:     "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   6002: 
                   6003:    </dd>
                   6004: 
                   6005:    <dt>An end tag whose tag name is "col"</dt>
                   6006:    <dd>
                   6007:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6008:    </dd>
                   6009: 
                   6010:    <dt>An end-of-file token</dt>
                   6011:    <dd>
                   6012: 
                   6013:     <p>If the <a href="#current-node">current node</a> is the root <code><a href="semantics.html#the-html-element">html</a></code>
                   6014:     element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
                   6015:     case</a>)</p>
                   6016: 
                   6017:     <p>Otherwise, act as described in the "anything else" entry
                   6018:     below.</p>
                   6019: 
                   6020:    </dd>
                   6021: 
                   6022:    <dt>Anything else</dt>
                   6023:    <dd>
                   6024: 
                   6025:     <p>Act as if an end tag with the tag name "colgroup" had been
                   6026:     seen, and then, if that token wasn't ignored, reprocess the
                   6027:     current token.</p>
                   6028: 
                   6029:     <p class="note">The fake end tag token here can only be
                   6030:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6031: 
                   6032:    </dd>
                   6033: 
                   6034:   </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>
                   6035: 
                   6036:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
                   6037:   mode: in table body">in table body</a>", tokens must be handled as follows:</p>
                   6038: 
                   6039:   <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
                   6040:    <dd>
                   6041: 
                   6042:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6043:     context</a>. (See below.)</p>
                   6044: 
                   6045:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   6046:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
                   6047:     in row">in row</a>".</p>
                   6048: 
                   6049:    </dd>
                   6050: 
                   6051:    <dt>A start tag whose tag name is one of: "th", "td"</dt>
                   6052:    <dd>
                   6053:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
                   6054:     the tag name "tr" had been seen, then reprocess the current
                   6055:     token.</p>
                   6056:    </dd>
                   6057: 
                   6058:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   6059:    "thead"</dt>
                   6060:    <dd>
                   6061: 
                   6062:     <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
                   6063:     scope</a> with the same tag name as the token, this is a
                   6064:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   6065: 
                   6066:     <p>Otherwise:</p>
                   6067: 
                   6068:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6069:     context</a>. (See below.)</p>
                   6070: 
                   6071:     <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
                   6072:     open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   6073:     to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   6074: 
                   6075:    </dd>
                   6076: 
                   6077:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6078:    "colgroup", "tbody", "tfoot", "thead"</dt>
                   6079:    <dt>An end tag whose tag name is "table"</dt>
                   6080:    <dd>
                   6081: 
                   6082:     <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
                   6083:     <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
                   6084:     element in table scope</a>, this is a <a href="#parse-error">parse
                   6085:     error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6086:     case</a>)</p>
                   6087: 
                   6088:     <p>Otherwise:</p>
                   6089: 
                   6090:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6091:     context</a>. (See below.)</p>
                   6092: 
                   6093:     <p>Act as if an end tag with the same tag name as the
                   6094:     <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
                   6095:     been seen, then reprocess the current token.</p>
                   6096: 
                   6097:    </dd>
                   6098: 
                   6099:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6100:    "col", "colgroup", "html", "td", "th", "tr"</dt>
                   6101:    <dd>
                   6102:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6103:    </dd>
                   6104: 
                   6105:    <dt>Anything else</dt>
                   6106:    <dd>
                   6107:     <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
                   6108:     mode</a>.</p>
                   6109:    </dd>
                   6110: 
                   6111:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
                   6112:   back to a table body context</dfn>, it means that the UA must,
                   6113:   while the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
                   6114:   <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="semantics.html#the-html-element">html</a></code>
                   6115:   element, pop elements from the <a href="#stack-of-open-elements">stack of open
                   6116:   elements</a>.</p>
                   6117: 
                   6118:   <p class="note">The <a href="#current-node">current node</a> being an
                   6119:   <code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="#fragment-case">fragment
                   6120:   case</a>.</p>
                   6121: 
                   6122: 
                   6123:   <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>
                   6124: 
                   6125:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   6126:   mode: in row">in row</a>", tokens must be handled as follows:</p>
                   6127: 
                   6128:   <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
                   6129:    <dd>
                   6130: 
                   6131:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   6132:     context</a>. (See below.)</p>
                   6133: 
                   6134:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   6135:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
                   6136:     in cell">in cell</a>".</p>
                   6137: 
                   6138:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   6139:     formatting elements</a>.</p>
                   6140: 
                   6141:    </dd>
                   6142: 
                   6143:    <dt>An end tag whose tag name is "tr"</dt>
                   6144:    <dd>
                   6145: 
                   6146:     <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
                   6147:     scope</a> with the same tag name as the token, this is a
                   6148:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6149:     case</a>)</p>
                   6150: 
                   6151:     <p>Otherwise:</p>
                   6152: 
                   6153:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   6154:     context</a>. (See below.)</p>
                   6155: 
                   6156:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   6157:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   6158:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   6159:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   6160:     body</a>".</p>
                   6161: 
                   6162:    </dd>
                   6163: 
                   6164:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6165:    "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
                   6166:    <dt>An end tag whose tag name is "table"</dt>
                   6167:    <dd>
                   6168: 
                   6169:     <p>Act as if an end tag with the tag name "tr" had been seen,
                   6170:     then, if that token wasn't ignored, reprocess the current
                   6171:     token.</p>
                   6172: 
                   6173:     <p class="note">The fake end tag token here can only be
                   6174:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6175: 
                   6176:    </dd>
                   6177: 
                   6178:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   6179:    "thead"</dt>
                   6180:    <dd>
                   6181: 
                   6182:     <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
                   6183:     scope</a> with the same tag name as the token, this is a
                   6184:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   6185: 
                   6186:     <p>Otherwise, act as if an end tag with the tag name "tr" had
                   6187:     been seen, then reprocess the current token.</p>
                   6188: 
                   6189:    </dd>
                   6190: 
                   6191:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6192:    "col", "colgroup", "html", "td", "th"</dt>
                   6193:    <dd>
                   6194:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6195:    </dd>
                   6196: 
                   6197:    <dt>Anything else</dt>
                   6198:    <dd>
                   6199:     <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
                   6200:     mode</a>.</p>
                   6201:    </dd>
                   6202: 
                   6203:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
                   6204:   back to a table row context</dfn>, it means that the UA must,
                   6205:   while the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tr-element">tr</a></code>
                   6206:   element or an <code><a href="semantics.html#the-html-element">html</a></code> element, pop elements from the
                   6207:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6208: 
                   6209:   <p class="note">The <a href="#current-node">current node</a> being an
                   6210:   <code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="#fragment-case">fragment
                   6211:   case</a>.</p>
                   6212: 
                   6213: 
                   6214:   <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>
                   6215: 
                   6216:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
                   6217:   mode: in cell">in cell</a>", tokens must be handled as follows:</p>
                   6218: 
                   6219:   <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
                   6220:    <dd>
                   6221: 
                   6222:     <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
                   6223:     scope</a> with the same tag name as that of the token, then
                   6224:     this is a <a href="#parse-error">parse error</a> and the token must be
                   6225:     ignored.</p>
                   6226: 
                   6227:     <p>Otherwise:</p>
                   6228: 
                   6229:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   6230: 
                   6231:     <p>Now, if the <a href="#current-node">current node</a> is not an element
                   6232:     with the same tag name as the token, then this is a
                   6233:     <a href="#parse-error">parse error</a>.</p>
                   6234: 
                   6235:     <p>Pop elements from this stack until an element with the same
                   6236:     tag name as the token has been popped from the stack.</p>
                   6237: 
                   6238:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   6239:     the last marker</a>.</p>
                   6240: 
                   6241:     <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
                   6242:     <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
                   6243:     this point.)</p>
                   6244: 
                   6245:    </dd>
                   6246: 
                   6247:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6248:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   6249:    <dd>
                   6250: 
                   6251:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
                   6252:     <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
                   6253:     a <code>td</code> or <code>th</code> element in table
                   6254:     scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
                   6255:     the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6256: 
                   6257:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6258:     reprocess the current token.</p>
                   6259: 
                   6260:    </dd>
                   6261: 
                   6262:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6263:    "col", "colgroup", "html"</dt>
                   6264:    <dd>
                   6265:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6266:    </dd>
                   6267: 
                   6268:    <dt>An end tag whose tag name is one of: "table", "tbody",
                   6269:    "tfoot", "thead", "tr"</dt>
                   6270:    <dd>
                   6271: 
                   6272:     <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
                   6273:     scope</a> with the same tag name as that of the token
                   6274:     (which can only happen for "tbody", "tfoot" and "thead", or,
                   6275:     in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
                   6276:     error</a> and the token must be ignored.</p>
                   6277: 
                   6278:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6279:     reprocess the current token.</p>
                   6280: 
                   6281:    </dd>
                   6282: 
                   6283:    <dt>Anything else</dt>
                   6284:    <dd>
                   6285:     <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
                   6286:     mode</a>.</p>
                   6287:    </dd>
                   6288: 
                   6289:   </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
                   6290:   mean to run the following algorithm:</p>
                   6291: 
                   6292:   <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>
                   6293:    element in table scope</a>, then act as if an end tag token
                   6294:    with the tag name "td" had been seen.</p></li>
                   6295: 
                   6296:    <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
                   6297:    <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
                   6298:    <code>th</code> element in table scope</a>; act as if an end
                   6299:    tag token with the tag name "th" had been seen.</p></li>
                   6300: 
                   6301:   </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
                   6302:   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
                   6303:   the same time, nor can it have neither when the <a href="#insertion-mode">insertion
                   6304:   mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   6305:   cell</a>".</p>
                   6306: 
                   6307: 
                   6308:   <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>
                   6309: 
                   6310:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
                   6311:   mode: in select">in select</a>", tokens must be handled as follows:</p>
                   6312: 
                   6313:   <dl class="switch"><dt>A character token</dt>
                   6314:    <dd>
                   6315:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6316:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6317:    </dd>
                   6318: 
                   6319:    <dt>A comment token</dt>
                   6320:    <dd>
                   6321:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6322:     node</a> with the <code title="">data</code> attribute set to
                   6323:     the data given in the comment token.</p>
                   6324:    </dd>
                   6325: 
                   6326:    <dt>A DOCTYPE token</dt>
                   6327:    <dd>
                   6328:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6329:    </dd>
                   6330: 
                   6331:    <dt>A start tag whose tag name is "html"</dt>
                   6332:    <dd>
                   6333:     <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
                   6334:     mode</a>.</p>
                   6335:    </dd>
                   6336: 
                   6337:    <dt>A start tag whose tag name is "option"</dt>
                   6338:    <dd>
                   6339: 
                   6340:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6341:     element, act as if an end tag with the tag name "option" had
                   6342:     been seen.</p>
                   6343: 
                   6344:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6345: 
                   6346:    </dd>
                   6347: 
                   6348:    <dt>A start tag whose tag name is "optgroup"</dt>
                   6349:    <dd>
                   6350: 
                   6351:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6352:     element, act as if an end tag with the tag name "option" had
                   6353:     been seen.</p>
                   6354: 
                   6355:     <p>If the <a href="#current-node">current node</a> is an
                   6356:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
                   6357:     tag name "optgroup" had been seen.</p>
                   6358: 
                   6359:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6360: 
                   6361:    </dd>
                   6362: 
                   6363:    <dt>An end tag whose tag name is "optgroup"</dt>
                   6364:    <dd>
                   6365: 
                   6366:     <p>First, if the <a href="#current-node">current node</a> is an
                   6367:     <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
                   6368:     it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
                   6369:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
                   6370:     the tag name "option" had been seen.</p>
                   6371: 
                   6372:     <p>If the <a href="#current-node">current node</a> is an
                   6373:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
                   6374:     <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
                   6375:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   6376: 
                   6377:    </dd>
                   6378: 
                   6379:    <dt>An end tag whose tag name is "option"</dt>
                   6380:    <dd>
                   6381: 
                   6382:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6383:     element, then pop that node from the <a href="#stack-of-open-elements">stack of open
                   6384:     elements</a>. Otherwise, this is a <a href="#parse-error">parse
                   6385:     error</a>; ignore the token.</p>
                   6386: 
                   6387:    </dd>
                   6388: 
                   6389:    <dt>An end tag whose tag name is "select"</dt>
                   6390:    <dd>
                   6391: 
                   6392:     <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
                   6393:     scope</a> with the same tag name as the token, this is a
                   6394:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6395:     case</a>)</p>
                   6396: 
                   6397:     <p>Otherwise:</p>
                   6398: 
                   6399:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   6400:     until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
                   6401:     stack.</p>
                   6402: 
                   6403:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   6404: 
                   6405:    </dd>
                   6406: 
                   6407:    <dt>A start tag whose tag name is "select"</dt>
                   6408:    <dd>
                   6409: 
                   6410:     <p><a href="#parse-error">Parse error</a>. Act as if the token had been
                   6411:     an end tag with the tag name "select" instead.</p>
                   6412: 
                   6413:    </dd>
                   6414: 
                   6415:    <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
                   6416:    <dd>
1.73      mike     6417: 
                   6418:     <p><a href="#parse-error">Parse error</a>.</p>
                   6419: 
                   6420:     <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
                   6421:     scope</a> with the same tag name as the token, ignore the
                   6422:     token. (<a href="#fragment-case">fragment case</a>)</p>
                   6423: 
                   6424:     <p>Otherwise, act as if an end tag with the tag name "select" had
                   6425:     been seen, and reprocess the token.</p>
                   6426: 
1.1       mike     6427:    </dd>
                   6428: 
                   6429:    <dt>A start tag token whose tag name is "script"</dt>
                   6430:    <dd>
                   6431:     <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
                   6432:     mode</a>.</p>
                   6433:    </dd>
                   6434: 
                   6435:    <dt>An end-of-file token</dt>
                   6436:    <dd>
                   6437: 
                   6438:     <p>If the <a href="#current-node">current node</a> is not the root
                   6439:     <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
                   6440:     error</a>.</p>
                   6441: 
                   6442:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6443:     the <a href="#fragment-case">fragment case</a>.</p>
                   6444: 
                   6445:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6446: 
                   6447:    </dd>
                   6448: 
                   6449:    <dt>Anything else</dt>
                   6450:    <dd>
                   6451:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6452:    </dd>
                   6453: 
                   6454:   </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>
                   6455: 
                   6456:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
                   6457:   mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
                   6458: 
                   6459:   <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
                   6460:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6461:    <dd>
                   6462:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   6463:     name "select" had been seen, and reprocess the token.</p>
                   6464:    </dd>
                   6465: 
                   6466:    <dt>An end tag whose tag name is one of: "caption", "table",
                   6467:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6468:    <dd>
                   6469: 
                   6470:     <p><a href="#parse-error">Parse error</a>.</p>
                   6471: 
                   6472:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
                   6473:     element in table scope</a> with the same tag name as that
                   6474:     of the token, then act as if an end tag with the tag name
                   6475:     "select" had been seen, and reprocess the token. Otherwise,
                   6476:     ignore the token.</p>
                   6477: 
                   6478:    </dd>
                   6479: 
                   6480:    <dt>Anything else</dt>
                   6481:    <dd>
                   6482:     <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
                   6483:     mode</a>.</p>
                   6484:    </dd>
                   6485: 
                   6486:   </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>
                   6487: 
                   6488:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
                   6489:   mode: in foreign content">in foreign content</a>", tokens must be
                   6490:   handled as follows:</p>
                   6491: 
                   6492:   <dl class="switch"><dt>A character token</dt>
                   6493:    <dd>
                   6494: 
                   6495:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6496:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6497: 
                   6498:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   6499:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   6500:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   6501:     flag</a> to "not ok".</p>
                   6502: 
                   6503:    </dd>
                   6504: 
                   6505:    <dt>A comment token</dt>
                   6506:    <dd>
                   6507:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6508:     node</a> with the <code title="">data</code> attribute set to
                   6509:     the data given in the comment token.</p>
                   6510:    </dd>
                   6511: 
                   6512:    <dt>A DOCTYPE token</dt>
                   6513:    <dd>
                   6514:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6515:    </dd>
                   6516: 
                   6517:    <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>
                   6518:    <dd>
                   6519: 
                   6520:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6521:     elements</a>.</p>
                   6522: 
                   6523:     <p>Let the <var title="">old insertion point</var> have the
                   6524:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   6525:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   6526:     input character</a>.</p>
                   6527: 
                   6528:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6529:     one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
                   6530: 
                   6531:     <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
                   6532:     the <code title="">script</code> element</a> according to the SVG
                   6533:     rules. <a href="references.html#references">[SVG]</a></p>
                   6534: 
                   6535:     <p class="note">Even if this causes <a href="dom.html#dom-document-write" title="dom-document-write">new characters to be inserted into the
                   6536:     tokenizer</a>, the parser will not be executed reentrantly,
                   6537:     since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
                   6538: 
                   6539:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6540:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   6541:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   6542: 
                   6543:     <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
                   6544:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   6545:     might be the "undefined" value.)</p>
                   6546: 
                   6547:    </dd>
                   6548: 
                   6549:    <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>
                   6550:    <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>
                   6551:    <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>
                   6552:    <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>
                   6553:    <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>
                   6554:    <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>
                   6555:    <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>
                   6556:    <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>
                   6557:    <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>
                   6558:    <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>
                   6559:    <dt>An end tag</dt>
                   6560:    <dd>
                   6561: 
                   6562:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
                   6563:     <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6564: 
                   6565:     <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
                   6566:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   6567:     content</a>", but there is no element in scope that has a
                   6568:     namespace other than the <a href="#html-namespace-0">HTML namespace</a><!-- XXX this
                   6569:     isn't well-defined; it means check to see if the bottom-most HTML
                   6570:     element on the stack is in scope -->, switch the <a href="#insertion-mode">insertion
                   6571:     mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6572: 
                   6573:    </dd>
                   6574: 
                   6575:    <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
                   6576:    "blockquote", "body"<!--by inspection-->, "br", "center", "code",
                   6577:    "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
                   6578:    uniformly throughout the parser -->, "em", "embed", "h1", "h2",
                   6579:    "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
                   6580:    completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
                   6581:    "li", "listing"<!-- so that pre and listing can be handled
                   6582:    uniformly throughout the parser -->, "menu", "meta", "nobr",
                   6583:    "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
                   6584:    the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
                   6585:    "span", "strong", "strike"<!-- so that s and strike can be handled
                   6586:    uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
                   6587:    "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt>
                   6588:    <!-- this list was determined empirically by studying over
                   6589:    6,000,000,000 pages that were specifically not XML pages -->
                   6590:    <dt>A start tag whose tag name is "font", if the token has
                   6591:    any attributes named "color", "face", or "size"</dt>
                   6592:    <!-- the attributes here are required so that SVG <font> will go
                   6593:    through as SVG but legacy <font>s won't -->
                   6594:    <dt>An end-of-file token</dt>
                   6595:    <dd>
                   6596: 
                   6597:     <p><a href="#parse-error">Parse error</a>.</p>
                   6598: 
                   6599:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
                   6600:     the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
                   6601:     namespace</a>.</p>
                   6602: 
                   6603:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
                   6604:     insertion mode</a>, and reprocess the token.</p>
                   6605: 
                   6606:    </dd>
                   6607: 
                   6608:    <dt>Any other start tag</dt>
                   6609:    <dd>
                   6610: 
                   6611:     <p>If the <a href="#current-node">current node</a> is an element in the
                   6612:     <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
                   6613:     attributes</a> for the token. (This fixes the case of MathML
                   6614:     attributes that are not all lowercase.)</p>
                   6615: 
                   6616:     <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6617:     namespace</a>, and the token's tag name is one of the ones in
                   6618:     the first column of the following table, change the tag name to
                   6619:     the name given in the corresponding cell in the second
                   6620:     column. (This fixes the case of SVG elements that are not all
                   6621:     lowercase.)</p>
                   6622: 
                   6623:     <table><thead><tr><th> Tag name </th><th> Element name
                   6624:      </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
                   6625:       </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
                   6626:       </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
                   6627:       </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
                   6628:       </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
                   6629:       </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
                   6630:       </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
                   6631:       </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
                   6632:       </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
                   6633:       </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
                   6634:       </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
                   6635:       </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
                   6636:       </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
                   6637:       </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
                   6638:       </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
                   6639:       </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
                   6640:       </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
                   6641:       </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
                   6642:       </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
                   6643:       </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
                   6644:       </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
                   6645:       </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
                   6646:       </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
                   6647:       </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
                   6648:       </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
                   6649:       </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
                   6650:       </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
                   6651:       </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
                   6652:       </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
                   6653:       </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
                   6654:       </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
                   6655:       </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
                   6656:       </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   6657:       </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
                   6658:       </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
                   6659:       <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
                   6660:       </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
                   6661:     </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6662:     namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
                   6663:     token. (This fixes the case of SVG attributes that are not all
                   6664:     lowercase.)</p>
                   6665: 
                   6666:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   6667:     fixes the use of namespaced attributes, in particular XLink in
                   6668:     SVG.)</p>
                   6669: 
                   6670:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   6671:     same namespace as the <a href="#current-node">current node</a>.</p>
                   6672: 
                   6673:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   6674:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6675:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   6676:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   6677: 
                   6678:    </dd>
                   6679: 
                   6680:   </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>
                   6681: 
                   6682:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
                   6683:   mode: after body">after body</a>", tokens must be handled as follows:</p>
                   6684: 
                   6685:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6686:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6687:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6688:    <dd>
                   6689:     <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
                   6690:     mode</a>.</p>
                   6691:    </dd>
                   6692: 
                   6693:    <dt>A comment token</dt>
                   6694:    <dd>
                   6695:     <p>Append a <code>Comment</code> node to the first element in
                   6696:     the <a href="#stack-of-open-elements">stack of open elements</a> (the <code><a href="semantics.html#the-html-element">html</a></code>
                   6697:     element), with the <code title="">data</code> attribute set to
                   6698:     the data given in the comment token.</p>
                   6699:    </dd>
                   6700: 
                   6701:    <dt>A DOCTYPE token</dt>
                   6702:    <dd>
                   6703:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6704:    </dd>
                   6705: 
                   6706:    <dt>A start tag whose tag name is "html"</dt>
                   6707:    <dd>
                   6708:     <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
                   6709:     mode</a>.</p>
                   6710:    </dd>
                   6711: 
                   6712:    <dt>An end tag whose tag name is "html"</dt>
                   6713:    <dd>
                   6714: 
                   6715:     <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
                   6716:     fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
                   6717:     error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6718: 
                   6719:     <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
                   6720:     body</a>".</p>
                   6721: 
                   6722:    </dd>
                   6723: 
                   6724:    <dt>An end-of-file token</dt>
                   6725:    <dd>
                   6726:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6727:    </dd>
                   6728: 
                   6729:    <dt>Anything else</dt>
                   6730:    <dd>
                   6731: 
                   6732:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
                   6733:     mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   6734:     body</a>" and reprocess the token.</p>
                   6735: 
                   6736:    </dd>
                   6737: 
                   6738:   </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>
                   6739: 
                   6740:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
                   6741:   mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
                   6742: 
                   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>A start tag whose tag name is "frameset"</dt>
                   6770:    <dd>
                   6771:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6772:    </dd>
                   6773: 
                   6774:    <dt>An end tag whose tag name is "frameset"</dt>
                   6775:    <dd>
                   6776: 
                   6777:     <p>If the <a href="#current-node">current node</a> is the root
                   6778:     <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
                   6779:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   6780:     case</a>)</p>
                   6781: 
                   6782:     <p>Otherwise, pop the <a href="#current-node">current node</a> from the
                   6783:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6784: 
                   6785:     <p>If the parser was <em>not</em> originally created as part
                   6786:     of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
                   6787:     (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5       mike     6788:     node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1       mike     6789:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
                   6790:     frameset</a>".</p>
                   6791: 
                   6792:    </dd>
                   6793: 
                   6794:    <dt>A start tag whose tag name is "frame"</dt>
                   6795:    <dd>
                   6796: 
                   6797:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
                   6798:     Immediately pop the <a href="#current-node">current node</a> off the
                   6799:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6800: 
                   6801:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   6802:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   6803: 
                   6804:    </dd>
                   6805: 
                   6806:    <dt>A start tag whose tag name is "noframes"</dt>
                   6807:    <dd>
                   6808:     <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
                   6809:     mode</a>.</p>
                   6810:    </dd>
                   6811: 
                   6812:    <dt>An end-of-file token</dt>
                   6813:    <dd>
                   6814: 
                   6815:     <p>If the <a href="#current-node">current node</a> is not the root
                   6816:     <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
                   6817:     error</a>.</p>
                   6818: 
                   6819:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6820:     the <a href="#fragment-case">fragment case</a>.</p>
                   6821: 
                   6822:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6823: 
                   6824:    </dd>
                   6825: 
                   6826:    <dt>Anything else</dt>
                   6827:    <dd>
                   6828:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6829:    </dd>
                   6830: 
                   6831:   </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>
                   6832: 
                   6833:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
                   6834:   mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
                   6835: 
                   6836:   <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
                   6837:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6838:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6839:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6840:    <dd>
                   6841:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6842:     the <a href="#current-node">current node</a>.</p>
                   6843:    </dd>
                   6844: 
                   6845:    <dt>A comment token</dt>
                   6846:    <dd>
                   6847:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6848:     node</a> with the <code title="">data</code> attribute set to
                   6849:     the data given in the comment token.</p>
                   6850:    </dd>
                   6851: 
                   6852:    <dt>A DOCTYPE token</dt>
                   6853:    <dd>
                   6854:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6855:    </dd>
                   6856: 
                   6857:    <dt>A start tag whose tag name is "html"</dt>
                   6858:    <dd>
                   6859:     <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
                   6860:     mode</a>.</p>
                   6861:    </dd>
                   6862: 
                   6863:    <dt>An end tag whose tag name is "html"</dt>
                   6864:    <dd>
                   6865:     <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
                   6866:     frameset</a>".</p>
                   6867:    </dd>
                   6868: 
                   6869:    <dt>A start tag whose tag name is "noframes"</dt>
                   6870:    <dd>
                   6871:     <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
                   6872:     mode</a>.</p>
                   6873:    </dd>
                   6874: 
                   6875:    <dt>An end-of-file token</dt>
                   6876:    <dd>
                   6877:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6878:    </dd>
                   6879: 
                   6880:    <dt>Anything else</dt>
                   6881:    <dd>
                   6882:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6883:    </dd>
                   6884: 
                   6885:   </dl><p class="XXX">This doesn't handle UAs that don't support
                   6886:   frames, or that do support frames but want to show the NOFRAMES
                   6887:   content. Supporting the former is easy; supporting the latter is
                   6888:   harder.</p>
                   6889: 
                   6890: 
                   6891:   <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>
                   6892: 
                   6893:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
                   6894:   mode: after after body">after after body</a>", tokens must be handled as follows:</p>
                   6895: 
                   6896:   <dl class="switch"><dt>A comment token</dt>
                   6897:    <dd>
                   6898:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   6899:     object with the <code title="">data</code> attribute set to the
                   6900:     data given in the comment token.</p>
                   6901:    </dd>
                   6902: 
                   6903:    <dt>A DOCTYPE token</dt>
                   6904:    <dt>A character token that is one of U+0009 CHARACTER
                   6905:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6906:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6907:    <dt>A start tag whose tag name is "html"</dt>
                   6908:    <dd>
                   6909:     <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
                   6910:     mode</a>.</p>
                   6911:    </dd>
                   6912: 
                   6913:    <dt>An end-of-file token</dt>
                   6914:    <dd>
                   6915:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6916:    </dd>
                   6917: 
                   6918:    <dt>Anything else</dt>
                   6919:    <dd>
                   6920:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   6921:     to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
                   6922:     reprocess the token.</p>
                   6923:    </dd>
                   6924: 
                   6925:   </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>
                   6926: 
                   6927:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
                   6928:   mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
                   6929: 
                   6930:   <dl class="switch"><dt>A comment token</dt>
                   6931:    <dd>
                   6932:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   6933:     object with the <code title="">data</code> attribute set to the
                   6934:     data given in the comment token.</p>
                   6935:    </dd>
                   6936: 
                   6937:    <dt>A DOCTYPE token</dt>
                   6938:    <dt>A character token that is one of U+0009 CHARACTER
                   6939:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6940:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6941:    <dt>A start tag whose tag name is "html"</dt>
                   6942:    <dd>
                   6943:     <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
                   6944:     mode</a>.</p>
                   6945:    </dd>
                   6946: 
                   6947:    <dt>An end-of-file token</dt>
                   6948:    <dd>
                   6949:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6950:    </dd>
                   6951: 
                   6952:    <dt>A start tag whose tag name is "noframes"</dt>
                   6953:    <dd>
                   6954:     <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
                   6955:     mode</a>.</p>
                   6956:    </dd>
                   6957: 
                   6958:    <dt>Anything else</dt>
                   6959:    <dd>
                   6960:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6961:    </dd>
                   6962: 
                   6963:   </dl><h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4>
                   6964: 
                   6965:   <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
                   6966:   the document, the user agent must follow the steps in this
                   6967:   section.</p>
                   6968: 
1.10      mike     6969:   <!-- this happens as part of one of the tasks that runs the parser -->
1.1       mike     6970: 
1.10      mike     6971:   <p>First, the user agent must set the <a href="dom.html#current-document-readiness">current document
                   6972:   readiness</a> to "interactive" and the <a href="#insertion-point">insertion
                   6973:   point</a> to undefined.</p>
                   6974: 
                   6975:   <p>Then, the user agent must then make a list of all the scripts
                   6976:   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
                   6977:   document has finished parsing</a>, the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that
                   6978:   will execute asynchronously</a>, and the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts
                   6979:   that will execute as soon as possible</a>. This is the <dfn id="list-of-scripts-pending-after-the-parser-stopped">list
                   6980:   of scripts pending after the parser stopped</dfn>.</p>
                   6981: 
                   6982:   <p>The rules for <a href="semantics.html#when-a-script-completes-loading">when a script completes loading</a> start
                   6983:   applying (script execution is no longer managed by the parser).</p>
1.1       mike     6984: 
                   6985:   <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
                   6986:   execute as soon as possible</a> have <a href="semantics.html#completed-loading">completed
                   6987:   loading</a>, or if the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that will execute
                   6988:   asynchronously</a> is not empty and the first script in that list
                   6989:   has <a href="semantics.html#completed-loading">completed loading</a>, then the user agent must act as
                   6990:   if those scripts just completed loading, following the rules given
                   6991:   for that in the <code><a href="semantics.html#script">script</a></code> element definition.</p>
                   6992: 
1.10      mike     6993:   <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
                   6994:   has finished parsing</a> is not empty, and the first item in this
                   6995:   list has already <a href="semantics.html#completed-loading">completed loading</a>, then the user agent
                   6996:   must act as if that script just finished loading.</p>
                   6997: 
                   6998:   <p class="note">By this point, there will be no scripts that have
                   6999:   loaded but have not yet been executed.</p>
                   7000: 
                   7001:   <hr><!-- async --><p>Once all the scripts on the <a href="#list-of-scripts-pending-after-the-parser-stopped">list of scripts pending after
                   7002:   the parser stopped</a> have <a href="semantics.html#completed-loading">completed loading</a> and
                   7003:   been <a href="semantics.html#executing-a-script-block" title="executing a script block">executed</a>, the
                   7004:   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
                   7005:   event</a> called <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
                   7006:   <code>Document</code>. (If the list is empty, this happens
                   7007:   immediately.)</p>
1.1       mike     7008: 
1.10      mike     7009:   <hr><!-- async --><p>Once everything that <dfn id="delay-the-load-event" title="delay the load event">delays the
1.1       mike     7010:   load event</dfn> of the document has completed, the user agent must
                   7011:   run the following steps:</p>
                   7012: 
                   7013:   <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
                   7014:    readiness</a> to "complete".</li>
                   7015: 
                   7016:    <li>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
                   7017:    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
                   7018:    simple event</a> called <code title="event-load"><a href="video.html#event-load">load</a></code> at
                   7019:    the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
                   7020:    its <code title="dom-event-target">target</code> set to the
                   7021:    <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
                   7022:    <code><a href="browsers.html#window">Window</a></code> object).</li>
                   7023: 
                   7024:    <li>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
                   7025:    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
                   7026:    <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
                   7027:    <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
                   7028:    current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
                   7029:    must bubble but not be cancelable and has no default action.</li>
                   7030: 
                   7031:   </ol><p>The <a href="browsers.html#task-source">task source</a> for these tasks is the <a href="browsers.html#dom-manipulation-task-source">DOM
                   7032:   manipulation task source</a>.</p>
                   7033: 
                   7034:   <!-- XXX make sure things "delay the load event", e.g. applet and
                   7035:   object element's frame contents -->
                   7036: 
                   7037:   <p class="XXX">delaying the load event for things like image
                   7038:   loads allows for intranet port scans (even without
                   7039:   javascript!). Should we really encode that into the spec?</p>
                   7040: 
                   7041: 
                   7042: <!--XXX need to handle
                   7043: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#2354
                   7044: 2354           // Don't open transient styles if it makes the stack deep, bug 58917.
                   7045: -->
                   7046: 
                   7047: <!--XXX
                   7048: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/nsHTMLTokenizer.cpp#749
                   7049: -->
                   7050: 
                   7051: <!--
                   7052: see also  CTextToken::ConsumeCharacterData()  for CDATA parsing?
                   7053: 
                   7054: 1212                      1  Here's a tricky case from bug 22596:  <h5><li><h5>
                   7055: 1213                         How do we know that the 2nd <h5> should close the <LI> rather than nest inside the <LI>?
                   7056: 1214                         (Afterall, the <h5> is a legal child of the <LI>).
                   7057: 1215
                   7058: 1216                         The way you know is that there is no root between the two, so the <h5> binds more
                   7059: 1217                         tightly to the 1st <h5> than to the <LI>.
                   7060: 1218                      2. Also, bug 6148 shows this case: <SPAN><DIV><SPAN>
                   7061: 1219                         From this case we learned not to execute this logic if the parent is a block.
                   7062: 1220
                   7063: 1221                      3. Fix for 26583
                   7064: 1222                         Ex. <A href=foo.html><B>foo<A href-bar.html>bar</A></B></A>  <- A legal HTML
                   7065: 1223                         In the above example clicking on "foo" or "bar" should link to
                   7066: 1224                         foo.html or bar.html respectively. That is, the inner <A> should be informed
                   7067: 1225                         about the presence of an open <A> above <B>..so that the inner <A> can close out
                   7068: 1226                         the outer <A>. The following code does it for us.
                   7069: 1227
                   7070: 1228                      4. Fix for 27865 [ similer to 22596 ]. Ex: <DL><DD><LI>one<DD><LI>two
                   7071:  - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1211
                   7072: 
                   7073: 815             // Here's a problem.  If theTag is legal in here, we don't move it
                   7074: 816             // out.  So if we're moving stuff out of here, the parent of theTag
                   7075: 817             // gets closed at this point.  But some things are legal
                   7076: 818             // _everywhere_ and hence would effectively close out misplaced
                   7077: 819             // content in tables.  This is undesirable, so treat them as
                   7078: 820             // illegal here so they'll be shipped out with their parents and
                   7079: 821             // siblings.  See bug 40855 for an explanation (that bug was for
                   7080: 822             // comments, but the same issues arise with whitespace, newlines,
                   7081: 823             // noscript, etc).  Script is special, though.  Shipping it out
                   7082: 824             // breaks document.write stuff.  See bug 243064.
                   7083:  - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#825
                   7084: 
                   7085: 
                   7086: 1326     /**************************************************************************************
                   7087: 1327      *
                   7088: 1328      * Now a little code to deal with bug #49687 (crash when layout stack gets too deep)
                   7089: 1329      * I've also opened this up to any container (not just inlines): re bug 55095
                   7090: 1330      * Improved to handle bug 55980 (infinite loop caused when DEPTH is exceeded and
                   7091: 1331      * </P> is encountered by itself (<P>) is continuously produced.
                   7092: 1332      *
                   7093: 1333      **************************************************************************************/
                   7094: 
                   7095: 1912               // Oh boy!! we found a "stray" tag. Nav4.x and IE introduce line break in
                   7096: 1913               // such cases. So, let's simulate that effect for compatibility.
                   7097: 1914               // Ex. <html><body>Hello</P>There</body></html>
                   7098: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1912
                   7099: 
                   7100: http://lxr.mozilla.org/seamonkey/search?string=nested
                   7101: /parser/htmlparser/src/CNavDTD.cpp, line 791 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
                   7102: /parser/htmlparser/src/CNavDTD.cpp, line 792 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
                   7103: /parser/htmlparser/src/CNavDTD.cpp, line 2562 - // Discard nested forms - bug 72639
                   7104: /parser/htmlparser/src/nsElementTable.cpp, line 1453 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
                   7105: /parser/htmlparser/src/nsElementTable.cpp, line 1454 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
                   7106: /parser/htmlparser/src/nsElementTable.cpp, line 1901 - // Ex: <H1><LI><H1><LI>. Inner LI has the potential of getting nested
                   7107: -->
                   7108: 
                   7109: 
                   7110:   <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4>
                   7111: 
                   7112:   <p>When an application uses an <a href="#html-parser">HTML parser</a> in
                   7113:   conjunction with an XML pipeline, it is possible that the
                   7114:   constructed DOM is not compatible with the XML tool chain in certain
                   7115:   subtle ways. For example, an XML toolchain might not be able to
                   7116:   represent attributes with the name <code title="">xmlns</code>,
                   7117:   since they conflict with the Namespaces in XML syntax. There is also
                   7118:   some data that the <a href="#html-parser">HTML parser</a> generates that isn't
                   7119:   included in the DOM itself. This section specifies some rules for
                   7120:   handling these issues.</p>
                   7121: 
                   7122:   <p>If the XML API being used doesn't support DOCTYPEs, the tool may
                   7123:   drop DOCTYPEs altogether.</p>
                   7124: 
                   7125:   <p>If the XML API doesn't support attributes in no namespace that
                   7126:   are named "<code title="">xmlns</code>", attributes whose names
                   7127:   start with "<code title="">xmlns:</code>", or attributes in the
                   7128:   <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
                   7129:   attributes.</p>
                   7130: 
                   7131:   <p>The tool may annotate the output with any namespace declarations
                   7132:   required for proper operation.</p>
                   7133: 
                   7134:   <p>If the XML API being used restricts the allowable characters in
                   7135:   the local names of elements and attributes, then the tool may map
                   7136:   all element and attribute local names that the API wouldn't support
                   7137:   to a set of names that <em>are</em> allowed, by replacing any
                   7138:   character that isn't supported with the uppercase letter U and the
                   7139:   six digits of the character's Unicode code point when expressed in
                   7140:   hexadecimal, using digits 0-9 and capital letters A-F as the
                   7141:   symbols, in increasing numeric order.</p>
                   7142: 
                   7143:   <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
                   7144:   parser</a>, though it is neither a legal HTML element name nor a
                   7145:   well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
                   7146:   element name (though it's still not legal in HTML by any means).</p>
                   7147: 
                   7148:   <p class="example">As another example, consider the attribute
                   7149:   <code>xlink:href</code>. Used on a MathML element, it becomes, after
                   7150:   being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
                   7151:   attribute with a prefix "<code title="">xlink</code>" and a local
                   7152:   name "<code title="">href</code>". However, used on an HTML element,
                   7153:   it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
                   7154:   might not be accepted by an XML API. It could thus get converted,
                   7155:   becoming "<code title="">xlinkU00003Ahref</code>".</p>
                   7156: 
                   7157:   <p class="note">The resulting names from this conversion
                   7158:   conveniently can't clash with any attribute generated by the
                   7159:   <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
                   7160:   those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
                   7161:   algorithm's table.</p>
                   7162: 
                   7163:   <p>If the XML API restricts comments from having two consecutive
                   7164:   U+002D HYPHEN-MINUS characters (--), the tool may insert a single
                   7165:   U+0020 SPACE character between any such offending characters.</p>
                   7166: 
                   7167:   <p>If the XML API restricts comments from ending in a
                   7168:   U+002D HYPHEN-MINUS character (-), the tool may insert a single
                   7169:   U+0020 SPACE character at the end of such comments.</p>
                   7170: 
                   7171:   <p>If the XML API restricts allowed characters in character data,
                   7172:   the tool may replace any U+000C FORM FEED (FF) character with a
                   7173:   U+0020 SPACE character, and any other literal non-XML character with
                   7174:   a U+FFFD REPLACEMENT CHARACTER.</p>
                   7175: 
                   7176:   <p>If the tool has no way to convey out-of-band information, then
                   7177:   the tool may drop the following information:</p>
                   7178: 
                   7179:   <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
                   7180:    <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>
                   7181: 
                   7182:    <li>The association between form controls and forms that aren't
                   7183:    their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
                   7184:    <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
                   7185: 
                   7186:   </ul><p class="note">The mutations allowed by this section apply
                   7187:   <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
                   7188:   applied. For example, a <code title="">&lt;a::&gt;</code> start tag
                   7189:   will be closed by a <code title="">&lt;/a::&gt;</code> end tag, and
                   7190:   never by a <code title="">&lt;/aU00003AU00003A&gt;</code> end tag, even
                   7191:   if the user agent is using the rules above to then generate an
                   7192:   actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
                   7193: 
                   7194: 
                   7195: 
1.35      mike     7196:   <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     7197: 
                   7198:   <p><i>This section is non-normative.</i></p>
                   7199: 
                   7200:   <p>This section examines some erroneous markup and discusses how
                   7201:   the <a href="#html-parser">HTML parser</a> handles these cases.</p>
                   7202: 
                   7203: 
                   7204:   <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>
                   7205: 
                   7206:   <p><i>This section is non-normative.</i></p>
                   7207: 
                   7208:   <p>The most-often discussed example of erroneous markup is as
                   7209:   follows:</p>
                   7210: 
                   7211:   <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>
                   7212: 
                   7213:   <p>The parsing of this markup is straightforward up to the "3". At
                   7214:   this point, the DOM looks like this:</p>
                   7215: 
                   7216:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>Here, the <a href="#stack-of-open-elements">stack of open elements</a> has five elements
                   7217:   on it: <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>,
                   7218:   <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
                   7219:   formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
                   7220:   <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>
                   7221: 
                   7222:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
                   7223:   invoked. This is a simple case, in that the <var title="">formatting
                   7224:   element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
                   7225:   <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
                   7226:   elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element">html</a></code>,
                   7227:   <code><a href="semantics.html#the-body-element">body</a></code>, and <code><a href="semantics.html#the-p-element">p</a></code>, while the <a href="#list-of-active-formatting-elements">list of
                   7228:   active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
                   7229:   DOM tree is unmodified at this point.</p>
                   7230: 
                   7231:   <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
                   7232:   the active formatting elements</a>, in this case just the
                   7233:   <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
                   7234:   for the "4" text node. After the end tag token for the "i" is also
                   7235:   received, and the "5" text node is inserted, the DOM looks as
                   7236:   follows:</p>
                   7237: 
                   7238:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">4</span></li></ul></li><li class="t3"><code>#text</code>: <span title="">5</span></li></ul></li></ul></li></ul></li></ul><h5 id="misnested-tags:-b-p-b-p"><span class="secno">9.2.8.2 </span>Misnested tags: &lt;b&gt;&lt;p&gt;&lt;/b&gt;&lt;/p&gt;</h5>
                   7239: 
                   7240:   <p><i>This section is non-normative.</i></p>
                   7241: 
                   7242:   <p>A case similar to the previous one is the following:</p>
                   7243: 
                   7244:   <pre>&lt;b&gt;1&lt;p&gt;2&lt;/b&gt;3&lt;/p&gt;</pre>
                   7245: 
                   7246:   <p>Up to the "2" the parsing here is straightforward:</p>
                   7247: 
                   7248:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>The interesting part is when the end tag token with the tag name
                   7249:   "b" is parsed.</p>
                   7250: 
                   7251:   <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
                   7252:   elements</a> has four elements on it: <code><a href="semantics.html#the-html-element">html</a></code>,
                   7253:   <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="text-level-semantics.html#the-b-element">b</a></code>, and <code><a href="semantics.html#the-p-element">p</a></code>. The
                   7254:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
                   7255:   <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>
                   7256: 
                   7257:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
                   7258:   in the previous example. However, in this case, there <em>is</em> a
                   7259:   <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
                   7260:   this time the adoption agency algorithm isn't skipped over.</p>
                   7261: 
                   7262:   <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element">body</a></code>
                   7263:   element. A conceptual "bookmark" marks the position of the
                   7264:   <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
                   7265:   elements</a>, but since that list has only one element in it,
                   7266:   it won't have much effect.</p>
                   7267: 
                   7268:   <p>As the algorithm progresses, <var title="">node</var> ends up set
                   7269:   to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
                   7270:   node</var> ends up set to the <var title="">furthest block</var>
                   7271:   (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7272: 
                   7273:   <p>The <var title="">last node</var> gets appended (moved) to the
                   7274:   <var title="">common ancestor</var>, so that the DOM looks like:</p>
                   7275: 
                   7276:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul><p>A new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created, and the children of the
                   7277:   <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
                   7278: 
                   7279:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code></li></ul></li></ul></li></ul><ul class="domTree"><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul><p>Finally, the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is appended to the
                   7280:   <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
                   7281: 
                   7282:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>The <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is removed from the <a href="#list-of-active-formatting-elements">list of
                   7283:   active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
                   7284:   elements</a>, so that when the "3" is parsed, it is appended to
                   7285:   the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
                   7286: 
                   7287:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li></ul></li></ul><h5 id="unexpected-markup-in-tables"><span class="secno">9.2.8.3 </span>Unexpected markup in tables</h5>
                   7288: 
                   7289:   <p><i>This section is non-normative.</i></p>
                   7290: 
                   7291:   <p>Error handling in tables is, for historical reasons, especially
                   7292:   strange. For example, consider the following markup:</p>
                   7293: 
                   7294:   <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>
                   7295: 
                   7296:   <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
                   7297:   directly inside a table like that, and the parser handles this case
                   7298:   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
                   7299:   examining the DOM tree as it stands just after the
                   7300:   <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
                   7301: 
                   7302:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code></li></ul></li></ul></li></ul><p>...and then immediately after the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start
                   7303:   tag has been seen:</p>
                   7304: 
                   7305:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code></li></ul></li></ul></li></ul><p>At this point, the <a href="#stack-of-open-elements">stack of open elements</a> has on it
                   7306:   the elements <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>,
                   7307:   <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
                   7308:   resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
                   7309:   elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
                   7310:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
                   7311:   table">in table</a>".</p>
                   7312: 
                   7313:   <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
                   7314:   to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
                   7315:   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
                   7316:   then handled in a rather straight-forward manner, taking the parser
                   7317:   through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   7318:   body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   7319:   row</a>" insertion modes, after which the DOM looks as
                   7320:   follows:</p>
                   7321: 
                   7322:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code></li></ul></li></ul></li></ul></li></ul></li></ul><p>Here, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
                   7323:   elements <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   7324:   <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
                   7325:   formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
                   7326:   it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   7327:   mode: in row">in row</a>".</p>
                   7328: 
                   7329:   <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
                   7330:   <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
                   7331:   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
                   7332:   mode</a>).</p>
                   7333: 
                   7334:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The marker means that when the "aaa" character tokens are seen,
                   7335:   no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
                   7336:   node:</p>
                   7337: 
                   7338:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The end tags are handled in a straight-forward manner; after
                   7339:   handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
                   7340:   elements <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   7341:   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
                   7342:   elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
                   7343:   marker having been removed by the "td" end tag token); and the
                   7344:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
                   7345:   table body">in table body</a>".</p>
                   7346: 
                   7347:   <p>Thus it is that the "bbb" character tokens are found. These
                   7348:   trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
                   7349:   text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
                   7350:   insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
                   7351:   body">in table body</a>"). The character tokens are collected,
                   7352:   and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
                   7353:   seen, they are processed as a group. Since they are not all spaces,
                   7354:   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,
                   7355:   which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   7356:   body</a>" insertion mode but with <a href="#foster-parent" title="foster
                   7357:   parent">foster parenting</a>.</p>
                   7358: 
                   7359:   <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
                   7360:   active formatting elements are reconstructed</a>, a
                   7361:   <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
                   7362:   parent">foster parented</a>, and then the "bbb" text node is
                   7363:   appended to it:</p>
                   7364: 
                   7365:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">bbb</span></li></ul></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The <a href="#stack-of-open-elements">stack of open elements</a> has on it the elements
                   7366:   <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   7367:   <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
                   7368:   this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
                   7369:   formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
                   7370:   and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
                   7371:   mode: in table body">in table body</a>".</p>
                   7372: 
                   7373:   <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
                   7374:   character">space characters</a> instead of "bbb", then those
                   7375:   <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
                   7376:   appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
                   7377: 
                   7378:   <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
                   7379:   tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
                   7380:   elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   7381:   but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
                   7382:   elements</a>, so the "ccc" character tokens after the table
                   7383:   result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
                   7384:   time after the table:</p>
                   7385: 
                   7386:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">bbb</span></li></ul></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">ccc</span></li></ul></li></ul></li></ul></li></ul><h5 id="scripts-that-modify-the-page-as-it-is-being-parsed"><span class="secno">9.2.8.4 </span>Scripts that modify the page as it is being parsed</h5>
                   7387: 
                   7388:   <p><i>This section is non-normative.</i></p>
                   7389: 
                   7390:   <p>Consider the following markup, which for this example we will
                   7391:   assume is the document with <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/inner</code>, being rendered as the
                   7392:   content of an <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code> in another document with the
                   7393:   <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
                   7394: 
                   7395:   <pre>&lt;div id=a&gt;
                   7396:  &lt;script&gt;
                   7397:   var div = document.getElementById('a');
                   7398:   parent.document.body.appendChild(div);
                   7399:  &lt;/script&gt;
                   7400:  &lt;script&gt;
                   7401:   alert(document.URL);
                   7402:  &lt;/script&gt;
                   7403: &lt;/div&gt;
                   7404: &lt;script&gt;
                   7405:  alert(document.URL);
                   7406: &lt;/script&gt;</pre>
                   7407: 
                   7408:   <p>Up to the first "script" end tag, before the script is parsed,
                   7409:   the result is relatively straightforward:</p>
                   7410: 
                   7411:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="interactive-elements.html#the-div-element">div</a></code> <span class="t2" title=""><code class="attribute name">id</code>="<code class="attribute value"><a href="text-level-semantics.html#the-a-element">a</a></code>"</span><ul><li class="t3"><code>#text</code>: <span title="">
                   7412:  </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
                   7413:   and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
                   7414: 
                   7415:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code></li></ul></li></ul><p>They are, at this point, in the <code>Document</code> of the
                   7416:   aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
                   7417:   <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
                   7418:   <code><a href="interactive-elements.html#the-div-element">div</a></code> element</em>.</p>
                   7419: 
                   7420:   <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
                   7421:   is inserted <em>into the outer <code>Document</code>
                   7422:   object</em>.</p>
                   7423: 
                   7424:   <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
                   7425:   the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
                   7426:   object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
                   7427:   <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code>.</p>
                   7428: 
                   7429:   <p class="note">This isn't a security problem since the script that
                   7430:   moves the <code><a href="interactive-elements.html#the-div-element">div</a></code> into the outer <code>Document</code> can
                   7431:   only do so because they have the two <code>Document</code> object
                   7432:   have the same <a href="browsers.html#origin-0">origin</a>.</p>
                   7433: 
                   7434:   <p>Thus, the first alert says "http://example.com/outer".</p>
                   7435: 
                   7436:   <p>Once the <code><a href="interactive-elements.html#the-div-element">div</a></code> element's end tag is parsed, the
                   7437:   <code><a href="interactive-elements.html#the-div-element">div</a></code> element is popped off the stack, and so the next
                   7438:   <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
                   7439: 
                   7440:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="semantics.html#script">script</a></code><ul><li class="t3"><code>#text</code>: <span title="">alert(document.URL);</span></li></ul></li></ul></li></ul></li></ul><p>This second alert will say "http://example.com/inner".</p>
                   7441: 
                   7442: 
                   7443: 
                   7444:   <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3>
                   7445: 
                   7446:   <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
                   7447: 
                   7448:   <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
                   7449: 
                   7450:   <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
                   7451: 
                   7452:   <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
                   7453: 
                   7454:   <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
                   7455: 
                   7456:   <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
                   7457: 
                   7458:   <hr><p>Data mining tools and other user agents that perform operations
1.83      mike     7459:   on <code><a href="iana-considerations.html#text-html">text/html</a></code> content without running scripts,
1.1       mike     7460:   evaluating CSS or XPath expressions, or otherwise exposing the
                   7461:   resulting DOM to arbitrary content, may "support namespaces" by just
                   7462:   asserting that their DOM node analogues are in certain namespaces,
                   7463:   without actually exposing the above strings.</p>
                   7464: 
                   7465: 
                   7466: 
                   7467: 
                   7468:   <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3>
                   7469: 
                   7470:   <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
                   7471:   algorithm</dfn>. The algorithm takes as input a DOM
                   7472:   <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
                   7473:   exception.</p>
                   7474: 
                   7475:   <p class="note">This algorithm serializes the <em>children</em> of
                   7476:   the node being serialized, not the node itself.</p>
                   7477: 
                   7478:   <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
                   7479:    the empty string.</p></li>
                   7480: 
                   7481:    <li>
                   7482: 
                   7483:     <p>For each child node of <var title="">the node</var>, in
                   7484:     <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
                   7485: 
                   7486:     </p><ol><li><p>Let <var title="">current node</var> be the child node
                   7487:      being processed.</p></li>
                   7488: 
                   7489:      <li>
                   7490: 
                   7491:       <p>Append the appropriate string from the following list to
                   7492:       <var title="">s</var>:</p>
                   7493: 
                   7494:       <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
                   7495: 
                   7496:        <dd>
                   7497: 
                   7498:         <p>Append a U+003C LESS-THAN SIGN (<code title="">&lt;</code>)
                   7499:         character, followed by the element's tag name. (For nodes
                   7500:         created by the <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
                   7501:         lowercase.)</p>
                   7502: 
                   7503:         <p>For each attribute that the element has, append a U+0020
                   7504:         SPACE character, the attribute's name (which, for attributes
                   7505:         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
                   7506:         U+003D EQUALS SIGN (<code title="">=</code>) character, a
                   7507:         U+0022 QUOTATION MARK (<code title="">"</code>)
                   7508:         character, the attribute's value, <a href="#escapingString" title="escaping a
                   7509:         string">escaped as described below</a> in <i>attribute
                   7510:         mode</i>, and a second U+0022 QUOTATION MARK (<code title="">"</code>) character.</p>
                   7511: 
                   7512:         <p>While the exact order of attributes is UA-defined, and may
                   7513:         depend on factors such as the order that the attributes were
                   7514:         given in the original markup, the sort order must be stable,
                   7515:         such that consecutive invocations of this algorithm serialize an
                   7516:         element's attributes in the same order.</p>
                   7517: 
                   7518:         <p>Append a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>)
                   7519:         character.</p>
                   7520: 
                   7521:         <p>If <var title="">current node</var> is an
1.5       mike     7522:         <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     7523:         <code>bgsound</code>, <code><a href="semantics.html#the-br-element">br</a></code>, <code><a href="tabular-data.html#the-col-element">col</a></code>,
1.5       mike     7524:         <code><a href="embedded-content-0.html#the-embed-element">embed</a></code>, <code><a href="obsolete.html#frame">frame</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>,
1.1       mike     7525:         <code><a href="embedded-content-0.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="forms.html#the-keygen-element">keygen</a></code>,
                   7526:         <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#meta">meta</a></code>, <code><a href="embedded-content-0.html#the-param-element">param</a></code>,
1.5       mike     7527:         <code><a href="obsolete.html#spacer">spacer</a></code>, or <code>wbr</code> element, then
1.1       mike     7528:         continue on to the next child node at this point.</p> <!--
                   7529:         also, i guess: image and isindex, but we don't list those
                   7530:         because we don't consider those "elements", more "macros", and
                   7531:         thus we should never serialize them -->
                   7532: 
                   7533:         <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42      mike     7534:         <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     7535:         a U+000A LINE FEED (LF) character.</p>
                   7536: 
                   7537:         <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
                   7538:         serialization algorithm</a> on the <var title="">current
                   7539:         node</var> element (thus recursing into this algorithm for
                   7540:         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,
                   7541:         and finally a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>) character.</p>
                   7542: 
                   7543:        </dd>
                   7544: 
                   7545: 
                   7546:        <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
                   7547:        node</dt>
                   7548: 
                   7549:        <dd>
                   7550: 
1.19      mike     7551:         <p>If the parent of <var title="">current node</var> is a
1.42      mike     7552:         <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="semantics.html#script">script</a></code>, <code><a href="obsolete.html#xmp">xmp</a></code>,
1.19      mike     7553:         <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>,
1.5       mike     7554:         <code><a href="obsolete.html#noframes">noframes</a></code>, <code><a href="semantics.html#the-noscript-element">noscript</a></code>, or
1.42      mike     7555:         <code><a href="obsolete.html#plaintext">plaintext</a></code> element, then append the value of <var title="">current node</var>'s <code title="">data</code> DOM
1.1       mike     7556:         attribute literally.</p> <!-- note about noscript: we're
                   7557:         assuming here that scripting is enabled. If this algorithm is
1.19      mike     7558:         used with scripting disabled, this won't work
                   7559:         right. (e.g. This might affect calling innerHTML on nodes in a
                   7560:         document that is being designMode'd) -->
1.1       mike     7561: 
                   7562:         <p>Otherwise, append the value of <var title="">current
                   7563:         node</var>'s <code title="">data</code> DOM attribute, <a href="#escapingString" title="escaping a string">escaped as described
                   7564:         below</a>.</p>
                   7565: 
                   7566:        </dd>
                   7567: 
                   7568: 
                   7569:        <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
                   7570: 
                   7571:        <dd>
                   7572: 
                   7573:         <p>Append the literal string <code>&lt;!--</code> (U+003C
                   7574:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
                   7575:         U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> DOM
                   7576:         attribute, followed by the literal string <code>--&gt;</code>
                   7577:         (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
                   7578:         SIGN).</p>
                   7579: 
                   7580:        </dd>
                   7581: 
                   7582: 
                   7583:        <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
                   7584: 
                   7585:        <dd>
                   7586: 
                   7587:         <p>Append the literal string <code>&lt;?</code> (U+003C
                   7588:         LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
                   7589:         of <var title="">current node</var>'s <code title="">target</code> DOM attribute, followed by a single
                   7590:         U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> DOM
                   7591:         attribute, followed by a single U+003E GREATER-THAN SIGN
                   7592:         character ('&gt;').</p>
                   7593: 
                   7594:        </dd>
                   7595: 
                   7596: 
                   7597:        <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
                   7598: 
                   7599:        <dd>
                   7600: 
                   7601:         <p>Append the literal string <code>&lt;!DOCTYPE</code> (U+003C
                   7602:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
                   7603:         LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
                   7604:         LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
                   7605:         LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
                   7606:         LETTER E), followed by a space (U+0020 SPACE), followed by the
                   7607:         value of <var title="">current node</var>'s <code title="">name</code> DOM attribute, followed by the literal
                   7608:         string <code>&gt;</code> (U+003E GREATER-THAN SIGN).</p>
                   7609: 
                   7610:        </dd>
                   7611: 
                   7612: 
                   7613:       </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
                   7614:       occur as children of elements. If, despite this, they somehow do
                   7615:       occur, this algorithm must raise an
                   7616:       <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
                   7617: 
                   7618:      </li>
                   7619: 
                   7620:     </ol></li>
                   7621: 
                   7622:    <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
                   7623: 
                   7624:   </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
                   7625:   purposes of the algorithm above) consists of replacing any
                   7626:   occurrences of the "<code title="">&amp;</code>" character by the
                   7627:   string "<code title="">&amp;amp;</code>", any occurrences of the
                   7628:   U+00A0 NO-BREAK SPACE character by the string "<code title="">&amp;nbsp;</code>", and, if the algorithm was invoked in
                   7629:   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
                   7630:   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>
                   7631: 
                   7632:   <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
                   7633:   agent, and are therefore not covered in the algorithm above.</p>
                   7634: 
                   7635:   <p class="note">It is possible that the output of this algorithm, if
                   7636:   parsed with an <a href="#html-parser">HTML parser</a>, will not return the
                   7637:   original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
                   7638:   element to which a <code title="">Comment</code> node has been
                   7639:   appended is serialized and the output is then reparsed, the comment
                   7640:   will end up being displayed in the text field. Similarly, if, as a
                   7641:   result of DOM manipulation, an element contains a comment that
                   7642:   contains the literal string "<code title="">--&gt;</code>", then
                   7643:   when the result of serializing the element is parsed, the comment
                   7644:   will be truncated at that point and the rest of the comment will be
                   7645:   interpreted as markup. More examples would be making a
                   7646:   <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
                   7647:   "<code>&lt;/script&gt;</code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
                   7648:   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
                   7649:   <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
                   7650:   tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7651: 
                   7652: 
                   7653:   <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3>
                   7654: 
                   7655:   <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
                   7656:   algorithm</dfn>. The algorithm optionally takes as input an
                   7657:   <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
                   7658:   parser, as well as <var title="">input</var>, a string to parse, and
                   7659:   returns a list of zero or more nodes.</p>
                   7660: 
                   7661:   <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
                   7662:   in the parser section are parts that only occur if the parser was
                   7663:   created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
                   7664:   with such markings for informational purposes only; such markings
                   7665:   have no normative weight. If it is possible for a condition
                   7666:   described as a <a href="#fragment-case">fragment case</a> to occur even when the
                   7667:   parser wasn't created for the purposes of handling this algorithm,
                   7668:   then that is an error in the specification.</p>
                   7669: 
                   7670:   <ol><li>
                   7671: 
                   7672:     <p>Create a new <code>Document</code> node, and mark it as being
                   7673:     an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                   7674: 
                   7675:    </li>
                   7676: 
                   7677:    <li>
                   7678: 
                   7679:     <p>If there is a <var title="">context</var> element, and the
                   7680:     <code>Document</code> of the <var title="">context</var> element
                   7681:     is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
                   7682:     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
                   7683:     the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
                   7684:     mode</a>, then let the <code>Document</code> be in
                   7685:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
                   7686:     <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
                   7687: 
                   7688:    </li>
                   7689: 
                   7690:    <li>
                   7691: 
                   7692:     <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
                   7693:     the just created <code>Document</code> node.</p>
                   7694: 
                   7695:    </li>
                   7696: 
                   7697:    <li>
                   7698: 
                   7699:     <p>If there is a <var title="">context</var> element, run these
                   7700:     substeps:</p>
                   7701: 
                   7702:     <ol><li>
                   7703: 
                   7704:       <p>Set the <a href="#html-parser">HTML parser</a>'s <a href="#tokenization">tokenization</a>
                   7705:       stage's <a href="#content-model-flag">content model flag</a> according to the <var title="">context</var> element, as follows:</p>
                   7706: 
                   7707:       <dl class="switch"><dt>If it is a <code><a href="semantics.html#the-title-element">title</a></code> or <code><a href="forms.html#the-textarea-element">textarea</a></code>
                   7708:        element</dt>
                   7709: 
                   7710:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7711:        the RCDATA state.</dd>
                   7712: 
                   7713: 
                   7714:        <dt>If it is a <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="semantics.html#script">script</a></code>,
1.42      mike     7715:        <code><a href="obsolete.html#xmp">xmp</a></code>, <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>, or
1.5       mike     7716:        <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1       mike     7717: 
                   7718:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
1.91      mike     7719:        the RAWTEXT state.</dd>
1.1       mike     7720: 
                   7721: 
                   7722:        <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
                   7723: 
                   7724:        <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, set the
1.91      mike     7725:        <a href="#content-model-flag">content model flag</a> to the RAWTEXT
1.1       mike     7726:        state. Otherwise, set the <a href="#content-model-flag">content model flag</a> to the
                   7727:        PCDATA state.</dd>
                   7728: 
                   7729: 
1.42      mike     7730:        <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1       mike     7731: 
                   7732:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7733:        PLAINTEXT.</dd>
                   7734: 
                   7735: 
                   7736:        <dt>Otherwise</dt>
                   7737: 
                   7738:        <dd>Leave the <a href="#content-model-flag">content model flag</a> in the PCDATA
                   7739:        state.</dd>
                   7740: 
                   7741:       </dl></li>
                   7742: 
                   7743:      <li>
                   7744: 
                   7745:       <p>Let <var title="">root</var> be a new <code><a href="semantics.html#the-html-element">html</a></code> element
                   7746:       with no attributes.</p>
                   7747: 
                   7748:      </li>
                   7749: 
                   7750:      <li>
                   7751: 
                   7752:       <p>Append the element <var title="">root</var> to the
                   7753:       <code>Document</code> node created above.</p>
                   7754: 
                   7755:      </li>
                   7756: 
                   7757:      <li>
                   7758: 
                   7759:       <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
                   7760:       it contains just the single element <var title="">root</var>.</p>
                   7761: 
                   7762:      </li>
                   7763: 
                   7764:      <li>
                   7765: 
                   7766:       <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
                   7767:       parser's insertion mode appropriately</a>.</p>
                   7768: 
                   7769:       <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
                   7770: 
                   7771:      </li>
                   7772: 
                   7773:      <li>
                   7774: 
                   7775:       <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
                   7776:       to the nearest node to the <var title="">context</var> element
                   7777:       that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
                   7778:       ancestor chain, and including the element itself, if it is a
                   7779:       <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
                   7780:       <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
                   7781: 
                   7782:      </li>
                   7783: 
                   7784:     </ol></li>
                   7785: 
                   7786:    <li>
                   7787: 
                   7788:     <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
                   7789:     parser</a> just created the <var title="">input</var>. The
                   7790:     encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   7791:     <i>irrelevant</i>.</p>
                   7792: 
                   7793:    </li>
                   7794: 
                   7795:    <li>
                   7796: 
                   7797:     <p>Start the parser and let it run until it has consumed all the
                   7798:     characters just inserted into the input stream.</p>
                   7799: 
                   7800:    </li>
                   7801: 
                   7802:    <li>
                   7803: 
                   7804:     <p>If there is a <var title="">context</var> element, return the
                   7805:     child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
                   7806:     order</a>.</p>
                   7807: 
                   7808:     <p>Otherwise, return the children of the <code>Document</code>
                   7809:     object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
                   7810: 
                   7811:    </li>
                   7812: 
1.97      mike     7813:   </ol></div>
                   7814: 
                   7815: 
                   7816: 
                   7817:   </body></html>

Webmaster