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

1.2       mike        1: <!DOCTYPE HTML>
1.258     mike        2: <!-- when publishing, change bits marked ZZZ --><html lang="en-US-x-Hixie"><head><title>9 The HTML syntax &#8212; HTML 5</title><style type="text/css">
1.1       mike        3:    pre { margin-left: 2em; white-space: pre-wrap; }
                      4:    h2 { margin: 3em 0 1em 0; }
                      5:    h3 { margin: 2.5em 0 1em 0; }
                      6:    h4 { margin: 2.5em 0 0.75em 0; }
                      7:    h5, h6 { margin: 2.5em 0 1em; }
                      8:    h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
                      9:    h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
                     10:    p { margin: 1em 0; }
                     11:    hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
                     12:    dl, dd { margin-top: 0; margin-bottom: 0; }
                     13:    dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
                     14:    dt + dt { margin-top: 0; }
                     15:    dd dt { margin-top: 0.25em; margin-bottom: 0; }
                     16:    dd p { margin-top: 0; }
                     17:    dd dl + p { margin-top: 1em; }
                     18:    dd table + p { margin-top: 1em; }
                     19:    p + * > li, dd li { margin: 1em 0; }
                     20:    dt, dfn { font-weight: bold; font-style: normal; }
                     21:    dt dfn { font-style: italic; }
                     22:    pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
                     23:    pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
                     24:    pre em { font-weight: bolder; font-style: normal; }
                     25:    @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
                     26:    var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
                     27:    table { border-collapse: collapse; border-style: hidden hidden none hidden; }
                     28:    table thead { border-bottom: solid; }
                     29:    table tbody th:first-child { border-left: solid; }
                     30:    table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
                     31:    blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
                     32: 
                     33:    .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
                     34:    .matrix, .matrix td { border: none; text-align: right; }
                     35:    .matrix { margin-left: 2em; }
                     36:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                     37:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                     38:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
1.2       mike       39:    .applies th > * { display: block; }
1.1       mike       40:    .applies thead code { display: block; }
                     41:    .applies td { text-align: center; }
                     42:    .applies .yes { background: yellow; }
                     43: 
                     44:    .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
                     45:    img.extra { float: right; }
                     46:    pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
                     47:    pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
                     48:    pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
                     49:    pre.css:first-line { color: #AAAA50; }
                     50:    dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #EEFFEE; }
                     51:    hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
                     52:    dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
                     53:    dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
                     54:    dl.domintro dd p { margin: 0.5em 0; }
                     55:    dl.switch { padding-left: 2em; }
                     56:    dl.switch > dt { text-indent: -1.5em; }
                     57:    dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
                     58:    dl.triple { padding: 0 0 0 1em; }
                     59:    dl.triple dt, dl.triple dd { margin: 0; display: inline }
                     60:    dl.triple dt:after { content: ':'; }
                     61:    dl.triple dd:after { content: '\A'; white-space: pre; }
                     62:    .diff-old { text-decoration: line-through; color: silver; background: transparent; }
                     63:    .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
                     64:    a .diff-new { border-bottom: 1px blue solid; }
                     65: 
                     66:    h2 { page-break-before: always; }
                     67:    h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
                     68:    h1 + h2, hr + h2.no-toc { page-break-before: auto; }
                     69: 
                     70:    p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
                     71: 
                     72:    div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
                     73:    div.head p { margin: 0; }
                     74:    div.head h1 { margin: 0; }
                     75:    div.head .logo { float: right; margin: 0 1em; }
                     76:    div.head .logo img { border: none } /* remove border from top image */
                     77:    div.head dl { margin: 1em 0; }
                     78:    p.copyright { font-size: x-small; font-style: oblique; margin: 0; }
                     79: 
                     80:    body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
                     81:    body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
                     82:    body > .toc > li > * { margin-bottom: 0.5em; }
                     83:    body > .toc > li > * > li > * { margin-bottom: 0.25em; }
                     84:    .toc, .toc li { list-style: none; }
                     85: 
                     86:    .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
                     87:    .brief li { margin: 0; padding: 0; }
                     88:    .brief li p { margin: 0; padding: 0; }
                     89: 
                     90:    .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
                     91:    .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
                     92:    .category-list li { display: inline; }
                     93:    .category-list li:not(:last-child)::after { content: ', '; }
                     94:    .category-list li > span, .category-list li > a { text-transform: lowercase; }
                     95:    .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
                     96: 
                     97:    .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
                     98:    .XXX > :first-child { margin-top: 0; }
                     99:    p .XXX { line-height: 3em; }
1.159     mike      100:    .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
                    101:    .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
                    102:    .annotation :link, .annotation :visited { color: inherit; }
                    103:    .annotation :link:hover, .annotation :visited:hover { background: transparent; }
                    104:    .annotation span { border: none ! important; }
1.1       mike      105:    .note { color: green; background: transparent; font-family: sans-serif; }
                    106:    .warning { color: red; background: transparent; }
                    107:    .note, .warning { font-weight: bolder; font-style: italic; }
                    108:    p.note, div.note { padding: 0.5em 2em; }
                    109:    span.note { padding: 0 2em; }
                    110:    .note p:first-child, .warning p:first-child { margin-top: 0; }
                    111:    .note p:last-child, .warning p:last-child { margin-bottom: 0; }
                    112:    .warning:before { font-style: normal; }
                    113:    p.note:before { content: 'Note: '; }
                    114:    p.warning:before { content: '\26A0 Warning! '; }
                    115: 
                    116:    .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
                    117:    .bookkeeping { font-size: 0.8em; margin: 2em 0; }
                    118:    .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
                    119: 
                    120:    h4 { position: relative; z-index: 3; }
                    121:    h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
                    122:    .element {
                    123:      background: #EEEEFF;
                    124:      color: black;
                    125:      margin: 0 0 1em 0.15em;
                    126:      padding: 0 1em 0.25em 0.75em;
                    127:      border-left: solid #9999FF 0.25em;
                    128:      position: relative;
                    129:      z-index: 1;
                    130:    }
                    131:    .element:before {
                    132:      position: absolute;
                    133:      z-index: 2;
                    134:      top: 0;
                    135:      left: -1.15em;
                    136:      height: 2em;
                    137:      width: 0.9em;
                    138:      background: #EEEEFF;
                    139:      content: ' ';
                    140:      border-style: none none solid solid;
                    141:      border-color: #9999FF;
                    142:      border-width: 0.25em;
                    143:    }
                    144: 
1.149     mike      145:    .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
                    146:    td > .example:only-child { margin: 0 0 0 0.1em; }
1.1       mike      147: 
                    148:    .tall-and-narrow {
                    149:      font-size: 0.6em;
                    150:      column-width: 25em;
                    151:      column-gap: 1em;
                    152:      -moz-column-width: 25em;
                    153:      -moz-column-gap: 1em;
                    154:      -webkit-column-width: 25em;
                    155:      -webkit-column-gap: 1em;
                    156:    }
                    157: 
                    158:    ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
                    159:    ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
                    160:    ul.domTree li li { list-style: none; }
                    161:    ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    162:    ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    163:    ul.domTree span { font-style: italic; font-family: serif; }
                    164:    ul.domTree .t1 code { color: purple; font-weight: bold; }
                    165:    ul.domTree .t2 { font-style: normal; font-family: monospace; }
                    166:    ul.domTree .t2 .name { color: black; font-weight: bold; }
                    167:    ul.domTree .t2 .value { color: blue; font-weight: normal; }
                    168:    ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
                    169:    ul.domTree .t7 code, .domTree .t8 code { color: green; }
                    170:    ul.domTree .t10 code { color: teal; }
                    171: 
1.267     mike      172:   </style><style type="text/css">
                    173: 
                    174:    .matrix, .matrix td { border: none; text-align: right; }
                    175:    .matrix { margin-left: 2em; }
                    176: 
                    177:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                    178:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                    179:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
                    180: 
                    181:    #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
                    182:    #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
                    183:    #table-example-1 caption { padding-bottom: 0.5em; }
                    184:    #table-example-1 thead, #table-example-1 tbody { border: none; }
                    185:    #table-example-1 th, #table-example-1 td { border: solid thin; }
                    186:    #table-example-1 th { font-weight: normal; }
                    187:    #table-example-1 td { border-style: none solid; vertical-align: top; }
                    188:    #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
                    189:    #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
                    190:    #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
                    191:    #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
                    192:    #table-example-1 tbody td:first-child::after { content: leader(". "); }
                    193:    #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
                    194:    #table-example-1 tbody td:first-child + td { width: 10em; }
                    195:    #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
                    196:    #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
                    197: 
                    198:    .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
                    199:    .apple-table-examples * { font-family: "Times", serif; }
                    200:    .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
                    201:    .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
                    202:    .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
                    203:    .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
                    204:    .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
                    205:    .apple-table-examples td { text-align: right; vertical-align: top; }
                    206:    .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
                    207:    .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
                    208:    .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
                    209:    .apple-table-examples sup { line-height: 0; }
                    210: 
1.235     mike      211:   </style><link href="data:text/css," rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D" rel="alternate stylesheet" title="Highlight implementation requirements"><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css"><!-- ZZZ ED vs WD -->
1.2       mike      212:   <script src="link-fixup.js"></script>
                    213:   <link href="comms.html" title="8 Communication" rel="prev">
                    214:   <link href="spec.html#contents" title="Table of contents" rel="index">
1.1       mike      215:   <link href="named-character-references.html" title="9.6 Named character references" rel="next">
1.16      mike      216:   </head><body onload="fixBrokenLink(); fixBrokenLink()"><div class="head">
1.1       mike      217:    <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
1.183     mike      218:    <h1>HTML5</h1>
1.1       mike      219:    <h2 class="no-num no-toc" id="a-vocabulary-and-associated-apis-for-html-and-xhtml">A vocabulary and associated APIs for HTML and XHTML</h2>
1.123     mike      220:    </div><nav>
1.1       mike      221:    <a href="comms.html">&#8592; 8 Communication</a> &#8211;
1.2       mike      222:    <a href="spec.html#contents">Table of contents</a> &#8211;
1.1       mike      223:    <a href="named-character-references.html">9.6 Named character references &#8594;</a>
1.279   ! mike      224:   </nav><p>This is revision 1.2996.</p>
1.11      mike      225: 
1.1       mike      226: 
1.123     mike      227:   <h2 id="syntax"><span class="secno">9 </span><dfn>The HTML syntax</dfn></h2><p class="note">This section only describes the rules for
1.83      mike      228:   <code><a href="iana-considerations.html#text-html">text/html</a></code> resources. Rules for XML resources are
1.1       mike      229:   discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.159     mike      230:   syntax</a>".</p><h3 id="writing"><span class="secno">9.1 </span>Writing HTML documents</h3><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p><div class="impl">
1.1       mike      231: 
                    232:   <p><i>This section only applies to documents, authoring tools, and
                    233:   markup generators. In particular, it does not apply to conformance
                    234:   checkers; conformance checkers must use the requirements given in
                    235:   the next section ("parsing HTML documents").</i></p>
                    236: 
1.123     mike      237:   </div><p>Documents must consist of the following parts, in the given
                    238:   order:</p><ol><li>Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.</li>
1.1       mike      239: 
                    240:    <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    241:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    242: 
                    243:    <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
                    244: 
                    245:    </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    246:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    247: 
1.159     mike      248:    <li>The root element, in the form of an <code><a href="semantics.html#the-html-element-0">html</a></code> <a href="#syntax-elements" title="syntax-elements">element</a>.</li>
1.1       mike      249: 
                    250:    <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    251:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    252: 
                    253:   </ol><p>The various types of content mentioned above are described in the
1.123     mike      254:   next few sections.</p><p>In addition, there are some restrictions on how <a href="semantics.html#character-encoding-declaration" title="character encoding declaration">character encoding
1.1       mike      255:   declarations</a> are to be serialized, as discussed in the
1.123     mike      256:   section on that topic.</p><div class="note">
1.1       mike      257: 
1.159     mike      258:    <p>Space characters before the root <code><a href="semantics.html#the-html-element-0">html</a></code> element, and
                    259:    space characters at the start of the <code><a href="semantics.html#the-html-element-0">html</a></code> element and
                    260:    before the <code><a href="semantics.html#the-head-element-0">head</a></code> element, will be dropped when the
1.1       mike      261:    document is parsed; space characters <em>after</em> the root
1.159     mike      262:    <code><a href="semantics.html#the-html-element-0">html</a></code> element will be parsed as if they were at the end
                    263:    of the <code><a href="semantics.html#the-body-element-0">body</a></code> element. Thus, space characters around the
1.1       mike      264:    root element do not round-trip.</p>
                    265: 
                    266:    <p>It is suggested that newlines be inserted after the DOCTYPE,
                    267:    after any comments that are before the root element, after the
1.159     mike      268:    <code><a href="semantics.html#the-html-element-0">html</a></code> element's start tag (if it is not <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>), and after any comments
                    269:    that are inside the <code><a href="semantics.html#the-html-element-0">html</a></code> element but before the
                    270:    <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike      271: 
1.123     mike      272:   </div><p>Many strings in the HTML syntax (e.g. the names of elements and
1.1       mike      273:   their attributes) are case-insensitive, but only for characters in
                    274:   the ranges U+0041 .. U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
                    275:   LETTER Z) and U+0061 .. U+007A (LATIN SMALL LETTER A to LATIN SMALL
                    276:   LETTER Z). For convenience, in this section this is just referred to
1.168     mike      277:   as "case-insensitive".</p><h4 id="the-doctype"><span class="secno">9.1.1 </span>The DOCTYPE</h4><p class="XXX annotation"><span><a href="http://www.w3.org/html/wg/tracker/issues/4">ISSUE-4</a> (html-versioning) blocks progress to Last Call</span></p><p>A <dfn id="syntax-doctype" title="syntax-doctype">DOCTYPE</dfn> is a mostly useless,
1.123     mike      278:   but required, header.</p><p class="note">DOCTYPEs are required for legacy reasons. When
1.1       mike      279:   omitted, browsers tend to use a different rendering mode that is
                    280:   incompatible with some specifications. Including the DOCTYPE in a
                    281:   document ensures that the browser makes a best-effort attempt at
1.123     mike      282:   following the relevant specifications.</p><p>A DOCTYPE must consist of the following characters, in this
                    283:   order:</p><ol class="brief"><li>A U+003C LESS-THAN SIGN (<code>&lt;</code>) character.</li>
1.1       mike      284:    <li>A U+0021 EXCLAMATION MARK (<code>!</code>) character.</li>
                    285:    <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>
                    286:    <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    287:    <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>
                    288:    <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> (defined below).</li>
                    289:    <li>Zero or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    290:    <li>A U+003E GREATER-THAN SIGN (<code>&gt;</code>) character.</li>
                    291:   </ol><p class="note">In other words, <code>&lt;!DOCTYPE HTML&gt;</code>,
1.123     mike      292:   case-insensitively.</p><p>For the purposes of HTML generators that cannot output HTML
1.1       mike      293:   markup with the short DOCTYPE "<code title="">&lt;!DOCTYPE
                    294:   HTML&gt;</code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
                    295:   into the DOCTYPE (in the position defined above). This string must
1.123     mike      296:   consist of:</p><ol class="brief"><li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.1       mike      297:    <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>
                    298:    <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    299:    <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
                    300:    <li>The literal string "<code title="">about:legacy-compat</code>".</li>
                    301:    <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>
                    302:   </ol><p class="note">In other words, <code>&lt;!DOCTYPE HTML SYSTEM
                    303:   "about:legacy-compat"&gt;</code> or <code>&lt;!DOCTYPE HTML SYSTEM
                    304:   'about:legacy-compat'&gt;</code>, case-insensitively except for the bit
1.123     mike      305:   in quotes.</p><p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1       mike      306:   the document is generated from a system that cannot output the
1.123     mike      307:   shorter string.</p><h4 id="elements-0"><span class="secno">9.1.2 </span>Elements</h4><p>There are five different kinds of <dfn id="syntax-elements" title="syntax-elements">elements</dfn>: void elements, raw text
1.1       mike      308:   elements, RCDATA elements, foreign elements, and normal
1.123     mike      309:   elements.</p><dl><dt><dfn id="void-elements">Void elements</dfn></dt>
1.1       mike      310: 
                    311:    <dd><code><a href="the-canvas-element.html#the-area-element">area</a></code>, <code><a href="semantics.html#the-base-element">base</a></code>, <code><a href="semantics.html#the-br-element">br</a></code>,
1.159     mike      312:    <code><a href="tabular-data.html#the-col-element">col</a></code>, <code><a href="interactive-elements.html#the-command">command</a></code>, <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>,
                    313:    <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="text-level-semantics.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>,
1.1       mike      314:    <code><a href="forms.html#the-keygen-element">keygen</a></code>, <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#meta">meta</a></code>,
1.159     mike      315:    <code><a href="text-level-semantics.html#the-param-element">param</a></code>, <code><a href="video.html#the-source-element">source</a></code></dd>
1.1       mike      316: 
1.91      mike      317:    <dt>Raw text elements</dt>
1.1       mike      318: 
                    319:    <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      320:    noscript don't count as raw text for syntax purposes -->
1.1       mike      321: 
                    322:    <dt>RCDATA elements</dt>
                    323: 
1.159     mike      324:    <dd><code><a href="forms.html#the-textarea-element">textarea</a></code>, <code><a href="semantics.html#the-title-element-0">title</a></code></dd>
1.1       mike      325: 
                    326:    <dt>Foreign elements</dt>
                    327: 
                    328:    <dd>Elements from the <a href="#mathml-namespace">MathML namespace</a>
                    329:    and the <a href="#svg-namespace">SVG namespace</a>.</dd>
                    330: 
                    331:    <dt>Normal elements</dt>
                    332: 
                    333:    <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
                    334:    elements.</dd>
                    335: 
                    336:   </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.91      mike      337:   and end of elements in the markup. Raw text, RCDATA, and normal
1.1       mike      338:   elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to
                    339:   indicate where they begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end
                    340:   tag</a> to indicate where they end. The start and end tags of
                    341:   certain normal elements can be <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>, as described
                    342:   later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
                    343:   elements</a> only have a start tag; end tags must not be
                    344:   specified for void elements. Foreign elements must either have a
                    345:   start tag and an end tag, or a start tag that is marked as
1.123     mike      346:   self-closing, in which case they must not have an end tag.</p><p>The contents of the element must be placed between just after the
1.1       mike      347:   start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
                    348:   in certain cases</a>) and just before the end tag (which again,
                    349:   <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
                    350:   cases</a>). The exact allowed contents of each individual element
                    351:   depends on the content model of that element, as described earlier
                    352:   in this specification. Elements must not contain content that their
                    353:   content model disallows. In addition to the restrictions placed on
                    354:   the contents by those content models, however, the five types of
1.123     mike      355:   elements have additional <em>syntactic</em> requirements.</p><p><a href="#void-elements">Void elements</a> can't have any contents (since there's
1.1       mike      356:   no end tag, no content can be put between the start tag and the end
1.123     mike      357:   tag).</p><p>Raw text elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1       mike      358:   though it has <a href="#cdata-rcdata-restrictions">restrictions</a>
1.123     mike      359:   described below.</p><p>RCDATA elements can have <a href="#syntax-text" title="syntax-text">text</a>
1.1       mike      360:   and <a href="#syntax-charref" title="syntax-charref">character references</a>, but
                    361:   the text must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
                    362:   There are also <a href="#cdata-rcdata-restrictions">further
1.123     mike      363:   restrictions</a> described below.</p><p>Foreign elements whose start tag is marked as self-closing can't
1.1       mike      364:   have any contents (since, again, as there's no end tag, no content
                    365:   can be put between the start tag and the end tag). Foreign elements
                    366:   whose start tag is <em>not</em> marked as self-closing can have
                    367:   <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
                    368:   contain the character U+003C LESS-THAN SIGN (<code>&lt;</code>) or
                    369:   an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.123     mike      370:   ampersand</a>.</p><p>Normal elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1       mike      371:   <a href="#syntax-charref" title="syntax-charref">character references</a>, other
                    372:   <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
                    373:   contain the character U+003C LESS-THAN SIGN (<code>&lt;</code>) or
                    374:   an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
                    375:   ampersand</a>. Some normal elements also have <a href="#element-restrictions">yet more restrictions</a> on what
                    376:   content they are allowed to hold, beyond the restrictions imposed by
                    377:   the content model and those described in this paragraph. Those
1.123     mike      378:   restrictions are described below.</p><p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1       mike      379:   giving the element's name. HTML elements all have names that only
                    380:   use characters in the range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE,
1.202     mike      381:   U+0061 LATIN SMALL LETTER A .. U+007A LATIN SMALL LETTER Z, and
                    382:   U+0041 LATIN CAPITAL LETTER A .. U+005A LATIN CAPITAL LETTER Z. In
                    383:   the HTML syntax, tag names may be written with any mix of lower- and
                    384:   uppercase letters that, when converted to all-lowercase, matches the
                    385:   element's tag name; tag names are case-insensitive.</p><h5 id="start-tags"><span class="secno">9.1.2.1 </span>Start tags</h5><p><dfn id="syntax-start-tag" title="syntax-start-tag">Start tags</dfn> must have the
1.123     mike      386:   following format:</p><ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.1       mike      387:    SIGN (<code>&lt;</code>).</li>
                    388: 
                    389:    <li>The next few characters of a start tag must be the element's
                    390:    <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
                    391: 
                    392:    <li>If there are to be any attributes in the next step, there must
                    393:    first be one or more <a href="infrastructure.html#space-character" title="space character">space
                    394:    characters</a>.</li>
                    395: 
                    396:    <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
                    397:    below. Attributes may be separated from each other by one or more
                    398:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    399: 
                    400:    <li>After the attributes, there may be one or more <a href="infrastructure.html#space-character" title="space character">space characters</a>. (Some attributes
                    401:    are required to be followed by a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes section</a> below.)</li>
                    402: 
                    403:    <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
                    404:    or if the element is a foreign element, then there may be a single
                    405:    U+002F SOLIDUS (<code>/</code>) character. This character has no
                    406:    effect on void elements, but on foreign elements it marks the start
                    407:    tag as self-closing.</li>
                    408: 
                    409:    <li>Finally, start tags must be closed by a U+003E GREATER-THAN
                    410:    SIGN (<code>&gt;</code>) character.</li>
                    411: 
1.123     mike      412:   </ol><h5 id="end-tags"><span class="secno">9.1.2.2 </span>End tags</h5><p><dfn id="syntax-end-tag" title="syntax-end-tag">End tags</dfn> must have the
                    413:   following format:</p><ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.1       mike      414:    SIGN (<code>&lt;</code>).</li>
                    415: 
                    416:    <li>The second character of an end tag must be a U+002F SOLIDUS
                    417:    (<code>/</code>).</li>
                    418: 
                    419:    <li>The next few characters of an end tag must be the element's
                    420:    <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
                    421: 
                    422:    <li>After the tag name, there may be one or more <a href="infrastructure.html#space-character" title="space
                    423:    character">space characters</a>.</li>
                    424: 
                    425:    <li>Finally, end tags must be closed by a U+003E GREATER-THAN
                    426:    SIGN (<code>&gt;</code>) character.</li>
                    427: 
1.123     mike      428:   </ol><h5 id="attributes"><span class="secno">9.1.2.3 </span>Attributes</h5><p><dfn id="syntax-attributes" title="syntax-attributes">Attributes</dfn> for an element
                    429:   are expressed inside the element's start tag.</p><p>Attributes have a name and a value. <dfn id="syntax-attribute-name" title="syntax-attribute-name">Attribute names</dfn> must consist of
1.1       mike      430:   one or more characters other than the <a href="infrastructure.html#space-character" title="space
                    431:   character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
                    432:   MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
                    433:   (&gt;), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters,
                    434:   the control characters, and any characters that are not defined by
                    435:   Unicode. In the HTML syntax, attribute names may be written with any
                    436:   mix of lower- and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.123     mike      437:   case-insensitive</a> match for the attribute's name.</p><p><dfn id="syntax-attribute-value" title="syntax-attribute-value">Attribute values</dfn> are a
1.1       mike      438:   mixture of <a href="#syntax-text" title="syntax-text">text</a> and <a href="#syntax-charref" title="syntax-charref">character references</a>, except with the
1.123     mike      439:   additional restriction that the text cannot contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.</p><p>Attributes can be specified in four different ways:</p><dl><dt>Empty attribute syntax</dt>
1.1       mike      440: 
                    441:    <dd>
                    442: 
                    443:     <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
                    444:     name</a>.</p>
                    445: 
                    446:     <div class="example">
                    447: 
                    448:      <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
                    449:      the empty attribute syntax:</p>
                    450: 
                    451:      <pre>&lt;input <em>disabled</em>&gt;</pre>
                    452: 
                    453:     </div>
                    454: 
                    455:     <p>If an attribute using the empty attribute syntax is to be
                    456:     followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    457:     character</a> separating the two.</p>
                    458: 
                    459:    </dd>
                    460: 
1.2       mike      461:    <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1       mike      462: 
                    463:    <dd>
                    464: 
                    465:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    466:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    467:     characters</a>, followed by a single U+003D EQUALS SIGN
                    468:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    469:     character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    470:     addition to the requirements given above for attribute values,
                    471:     must not contain any literal <a href="infrastructure.html#space-character" title="space character">space
                    472:     characters</a>, any U+0022 QUOTATION MARK (<code>"</code>)
                    473:     characters, U+0027 APOSTROPHE (<code>'</code>) characters,
                    474:     U+003D EQUALS SIGN (<code>=</code>) characters, U+003C LESS-THAN
                    475:     SIGN (<code>&lt;</code>) characters, or U+003E GREATER-THAN SIGN
                    476:     (<code>&gt;</code>) characters, and must not be the empty
                    477:     string.</p>
                    478: 
                    479:     <div class="example">
                    480: 
                    481:      <p>In the following example, the <code title="attr-input-value"><a href="forms.html#attr-input-value">value</a></code> attribute is given
                    482:      with the unquoted attribute value syntax:</p>
                    483: 
                    484:      <pre>&lt;input <em>value=yes</em>&gt;</pre>
                    485: 
                    486:     </div>
                    487: 
                    488:     <p>If an attribute using the unquoted attribute syntax is to be
1.101     mike      489:     followed by another attribute or by the optional U+002F SOLIDUS
                    490:     (<code>/</code>) character allowed in step 6 of the <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> syntax above, then there
1.1       mike      491:     must be a <a href="infrastructure.html#space-character">space character</a> separating the two.</p>
                    492: 
                    493:    </dd>
                    494: 
                    495:    <dt>Single-quoted attribute value syntax</dt>
                    496: 
                    497:    <dd>
                    498: 
                    499:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    500:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    501:     characters</a>, followed by a single U+003D EQUALS SIGN
                    502:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    503:     character">space characters</a>, followed by a single U+0027
                    504:     APOSTROPHE (<code>'</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    505:     addition to the requirements given above for attribute values,
                    506:     must not contain any literal U+0027 APOSTROPHE (<code>'</code>)
                    507:     characters, and finally followed by a second single U+0027
                    508:     APOSTROPHE (<code>'</code>) character.</p>
                    509: 
                    510:     <div class="example">
                    511: 
                    512:      <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
                    513:      single-quoted attribute value syntax:</p>
                    514: 
                    515:      <pre>&lt;input <em>type='checkbox'</em>&gt;</pre>
                    516: 
                    517:     </div>
                    518: 
                    519:     <p>If an attribute using the single-quoted attribute syntax is to
                    520:     be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    521:     character</a> separating the two.</p>
                    522: 
                    523:    </dd>
                    524: 
                    525:    <dt>Double-quoted attribute value syntax</dt>
                    526: 
                    527:    <dd>
                    528: 
                    529:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    530:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    531:     characters</a>, followed by a single U+003D EQUALS SIGN
                    532:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    533:     character">space characters</a>, followed by a single U+0022
                    534:     QUOTATION MARK (<code>"</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    535:     addition to the requirements given above for attribute values,
                    536:     must not contain any literal U+0022 QUOTATION MARK
                    537:     (<code>"</code>) characters, and finally followed by a second
                    538:     single U+0022 QUOTATION MARK (<code>"</code>) character.</p>
                    539: 
                    540:     <div class="example">
                    541: 
                    542:      <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
                    543:      double-quoted attribute value syntax:</p>
                    544: 
                    545:      <pre>&lt;input <em>name="be evil"</em>&gt;</pre>
                    546: 
                    547:     </div>
                    548: 
                    549:     <p>If an attribute using the double-quoted attribute syntax is to
                    550:     be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    551:     character</a> separating the two.</p>
                    552: 
                    553:    </dd>
                    554: 
                    555:   </dl><p>There must never be two or more attributes on the same start tag
                    556:   whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.123     mike      557:   each other.</p><h5 id="optional-tags"><span class="secno">9.1.2.4 </span>Optional tags</h5><p>Certain tags can be <dfn id="syntax-tag-omission" title="syntax-tag-omission">omitted</dfn>.</p><p class="note">Omitting an element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> does not mean the element
1.1       mike      558:   is not present; it is implied, but it is still there. An HTML
1.159     mike      559:   document always has a root <code><a href="semantics.html#the-html-element-0">html</a></code> element, even if the
1.1       mike      560:   string <code title="">&lt;html&gt;</code> doesn't appear anywhere in
1.159     mike      561:   the markup.</p><!-- <html> --><p>An <code><a href="semantics.html#the-html-element-0">html</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
                    562:   first thing inside the <code><a href="semantics.html#the-html-element-0">html</a></code> element is not a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- </html> --><p>An <code><a href="semantics.html#the-html-element-0">html</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
                    563:   tag</a> may be omitted if the <code><a href="semantics.html#the-html-element-0">html</a></code> element is not
                    564:   immediately followed by a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- <head> --><p>A <code><a href="semantics.html#the-head-element-0">head</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted <!--if the
1.1       mike      565:   element is empty, or--> if the first thing inside the
1.159     mike      566:   <code><a href="semantics.html#the-head-element-0">head</a></code> element is an element.</p><!-- </head> --><p>A <code><a href="semantics.html#the-head-element-0">head</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
                    567:   tag</a> may be omitted if the <code><a href="semantics.html#the-head-element-0">head</a></code> element is not
                    568:   immediately followed by a <a href="infrastructure.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- <body> --><p>A <code><a href="semantics.html#the-body-element-0">body</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
                    569:   element is empty, or if the first thing inside the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1       mike      570:   element is not a <a href="infrastructure.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>, except if the first thing
1.159     mike      571:   inside the <code><a href="semantics.html#the-body-element-0">body</a></code> element is a <code><a href="semantics.html#script">script</a></code> or
1.1       mike      572:   <code><a href="semantics.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
                    573:   tag is present, the parser makes <style> and <script> elements
                    574:   between </head> and <body> end up in the <head> instead of implying
1.159     mike      575:   the <body> --></p><!-- </body> --><p>A <code><a href="semantics.html#the-body-element-0">body</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
                    576:   tag</a> may be omitted if the <code><a href="semantics.html#the-body-element-0">body</a></code> element is not
1.123     mike      577:   immediately followed by a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- </li> --><p>A <code><a href="semantics.html#the-li-element">li</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      578:   tag</a> may be omitted if the <code><a href="semantics.html#the-li-element">li</a></code> element is
                    579:   immediately followed by another <code><a href="semantics.html#the-li-element">li</a></code> element or if there
1.123     mike      580:   is no more content in the parent element.</p><!-- </dt> --><p>A <code><a href="semantics.html#the-dt-element">dt</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      581:   tag</a> may be omitted if the <code><a href="semantics.html#the-dt-element">dt</a></code> element is
                    582:   immediately followed by another <code><a href="semantics.html#the-dt-element">dt</a></code> element or a
1.123     mike      583:   <code><a href="semantics.html#the-dd-element">dd</a></code> element.</p><!-- </dd> --><p>A <code><a href="semantics.html#the-dd-element">dd</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      584:   tag</a> may be omitted if the <code><a href="semantics.html#the-dd-element">dd</a></code> element is
                    585:   immediately followed by another <code><a href="semantics.html#the-dd-element">dd</a></code> element or a
                    586:   <code><a href="semantics.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.123     mike      587:   parent element.</p><!-- </p> --><p>A <code><a href="semantics.html#the-p-element">p</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      588:   tag</a> may be omitted if the <code><a href="semantics.html#the-p-element">p</a></code> element is
                    589:   immediately followed by an <code><a href="semantics.html#the-address-element">address</a></code>,
                    590:   <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      591:   <!--v2DATAGRID <code>datagrid</code>,--> <code><a href="semantics.html#the-dialog-element">dialog</a></code>,
                    592:   <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>,
                    593:   <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>,
                    594:   <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>,
                    595:   <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>,
                    596:   <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>,
                    597:   <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      598:   <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>,
                    599:   element, or if there is no more content in the parent element and
1.123     mike      600:   the parent element is not an <code><a href="text-level-semantics.html#the-a-element">a</a></code> element.</p><!-- </rt> --><p>An <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      601:   tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element is
                    602:   immediately followed by an <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> or <code><a href="text-level-semantics.html#the-rp-element">rp</a></code>
1.123     mike      603:   element, or if there is no more content in the parent element.</p><!-- </rp> --><p>An <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      604:   tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element is
                    605:   immediately followed by an <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> or <code><a href="text-level-semantics.html#the-rp-element">rp</a></code>
1.123     mike      606:   element, or if there is no more content in the parent element.</p><!-- </optgroup> (the text assumes <optgroup> can only be inside a
1.1       mike      607:   <select>; commented out text below can handle the non-<select> case
1.123     mike      608:   if we ever allow it) --><p>An <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> may be omitted if the
1.1       mike      609:   <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
                    610:   <code>select</code> element and--> is immediately followed by
                    611:   another <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
                    612:   that are ancestors of the <code>optgroup</code> element, up to and
                    613:   including the first ancestor element that is not an
                    614:   <code>optgroup</code> element, have no more content--> there is no
1.123     mike      615:   more content in the parent element.</p><!-- so e.g. the max number of </optgroup>s are omitted here:
1.1       mike      616:    <select><optgroup></select>
                    617:    <p id=x><optgroup></optgroup>x</p>
                    618:    <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
                    619:    <p><optgroup id=x><optgroup></optgroup>x</p>
                    620:    <p><optgroup><optgroup id=x>x</p>
1.123     mike      621:   --><!-- </option> --><p>An <code><a href="forms.html#the-option-element">option</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      622:   tag</a> may be omitted if the <code><a href="forms.html#the-option-element">option</a></code> element is
                    623:   immediately followed by another <code><a href="forms.html#the-option-element">option</a></code> element, or if
                    624:   it is immediately followed by an <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or
1.123     mike      625:   if there is no more content in the parent element.</p><!-- <colgroup> --><p>A <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.1       mike      626:   first thing inside the <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is a
                    627:   <code><a href="tabular-data.html#the-col-element">col</a></code> element, and if the element is not immediately
                    628:   preceded by another <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> has been omitted. (It can't be
1.123     mike      629:   omitted if the element is empty.)</p><!-- </colgroup> --><p>A <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> may be omitted if the
1.1       mike      630:   <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.123     mike      631:   <a href="infrastructure.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p><!-- </thead> --><p>A <code><a href="tabular-data.html#the-thead-element">thead</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      632:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-thead-element">thead</a></code> element is
                    633:   immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> or <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>
1.123     mike      634:   element.</p><!-- <tbody> --><p>A <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.1       mike      635:   first thing inside the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is a
                    636:   <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, and if the element is not immediately
                    637:   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
                    638:   <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
                    639:   tag</a> has been omitted. (It can't be omitted if the element is
1.123     mike      640:   empty.)</p><!-- </tbody> --><p>A <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      641:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is
                    642:   immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> or <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>
1.123     mike      643:   element, or if there is no more content in the parent element.</p><!-- </tfoot> --><p>A <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      644:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element is
                    645:   immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, or if there is
1.123     mike      646:   no more content in the parent element.</p><!-- </tr> --><p>A <code><a href="tabular-data.html#the-tr-element">tr</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      647:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
                    648:   immediately followed by another <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, or if there
1.123     mike      649:   is no more content in the parent element.</p><!-- </td> --><p>A <code><a href="tabular-data.html#the-td-element">td</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      650:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-td-element">td</a></code> element is
                    651:   immediately followed by a <code><a href="tabular-data.html#the-td-element">td</a></code> or <code><a href="tabular-data.html#the-th-element">th</a></code>
1.123     mike      652:   element, or if there is no more content in the parent element.</p><!-- </th> --><p>A <code><a href="tabular-data.html#the-th-element">th</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      653:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-th-element">th</a></code> element is
                    654:   immediately followed by a <code><a href="tabular-data.html#the-td-element">td</a></code> or <code><a href="tabular-data.html#the-th-element">th</a></code>
1.123     mike      655:   element, or if there is no more content in the parent element.</p><p><strong>However</strong>, a <a href="#syntax-start-tag" title="syntax-start-tag">start
                    656:   tag</a> must never be omitted if it has any attributes.</p><h5 id="element-restrictions"><span class="secno">9.1.2.5 </span>Restrictions on content models</h5><p>For historical reasons, certain elements have extra restrictions
                    657:   beyond even the restrictions given by their content model.</p><p>A <code><a href="tabular-data.html#the-table-element">table</a></code> element must not contain <code><a href="tabular-data.html#the-tr-element">tr</a></code>
1.1       mike      658:   elements, even though these elements are technically allowed inside
                    659:   <code><a href="tabular-data.html#the-table-element">table</a></code> elements according to the content models
                    660:   described in this specification. (If a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
                    661:   put inside a <code><a href="tabular-data.html#the-table-element">table</a></code> in the markup, it will in fact imply
1.123     mike      662:   a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag before it.)</p><p>A single U+000A LINE FEED (LF) character may be placed
1.1       mike      663:   immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
                    664:   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>
                    665:   elements. This does not affect the processing of the element. The
                    666:   otherwise optional U+000A LINE FEED (LF) character <em>must</em> be
                    667:   included if the element's contents start with that character
                    668:   (because otherwise the leading newline in the contents would be
1.123     mike      669:   treated like the optional newline, and ignored).</p><div class="example">
1.1       mike      670:    <p>The following two <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
                    671:    <pre>&lt;pre&gt;Hello&lt;/pre&gt;</pre>
                    672:    <pre>&lt;pre&gt;<br>Hello&lt;/pre&gt;</pre>
1.123     mike      673:   </div><h5 id="cdata-rcdata-restrictions"><span class="secno">9.1.2.6 </span>Restrictions on the contents of raw text and RCDATA elements</h5><p>The text in raw text and RCDATA elements must not contain any
1.1       mike      674:   occurrences of the string "<code title="">&lt;/</code>" (U+003C
                    675:   LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that
                    676:   case-insensitively match the tag name of the element followed by one
                    677:   of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM
                    678:   FEED (FF), U+0020 SPACE, U+003E GREATER-THAN SIGN (&gt;), or U+002F
1.123     mike      679:   SOLIDUS (/), unless that string is part of an <a href="#syntax-escape" title="syntax-escape">escaping text span</a>.</p><p>An <dfn id="syntax-escape" title="syntax-escape">escaping text span</dfn> is a span
1.1       mike      680:   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
                    681:   not itself in an <a href="#syntax-escape" title="syntax-escape">escaping text
                    682:   span</a>, and ends at the next <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span end</a>. There
                    683:   cannot be any <a href="#syntax-charref" title="syntax-charref">character
                    684:   references</a> inside an <a href="#syntax-escape" title="syntax-escape">escaping
                    685:   text span</a> &#8212; sequences of characters that would look
                    686:   like <a href="#syntax-charref" title="syntax-charref">character references</a> do not
1.123     mike      687:   have special meaning.</p><p>An <dfn id="syntax-escape-start" title="syntax-escape-start">escaping text span
1.1       mike      688:   start</dfn> is a part of <a href="#syntax-text" title="syntax-text">text</a> that
                    689:   consists of the four character sequence "<code title="">&lt;!--</code>" (U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
1.123     mike      690:   MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS).</p><p>An <dfn id="syntax-escape-end" title="syntax-escape-end">escaping text span end</dfn> is
1.1       mike      691:   a part of <a href="#syntax-text" title="syntax-text">text</a> that consists of the
                    692:   three character sequence "<code title="">--&gt;</code>" (U+002D
1.134     mike      693:   HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN).</p><p>An <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span
1.1       mike      694:   start</a> may share its U+002D HYPHEN-MINUS characters with its
                    695:   corresponding <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span
1.123     mike      696:   end</a>.</p><p>The text in raw text elements and RCDATA elements must not have
1.91      mike      697:   an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a>
                    698:   that is not followed by an <a href="#syntax-escape-end" title="syntax-escape-end">escaping
1.123     mike      699:   text span end</a>.</p><h4 id="text-0"><span class="secno">9.1.3 </span>Text</h4><p><dfn id="syntax-text" title="syntax-text">Text</dfn> is allowed inside elements,
1.1       mike      700:   attributes, and comments. Text must consist of Unicode characters.
                    701:   Text must not contain U+0000 characters. Text must not contain
                    702:   permanently undefined Unicode characters. Text must not contain
                    703:   control characters other than <a href="infrastructure.html#space-character" title="space character">space
                    704:   characters</a>. Extra constraints are placed on what is and what
                    705:   is not allowed in text based on where the text is to be put, as
1.123     mike      706:   described in the other sections.</p><h5 id="newlines"><span class="secno">9.1.3.1 </span>Newlines</h5><p><dfn id="syntax-newlines" title="syntax-newlines">Newlines</dfn> in HTML may be
1.1       mike      707:   represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A
                    708:   LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR),
1.123     mike      709:   U+000A LINE FEED (LF) characters in that order.</p><h4 id="character-references"><span class="secno">9.1.4 </span>Character references</h4><p>In certain cases described in other sections, <a href="#syntax-text" title="syntax-text">text</a> may be mixed with <dfn id="syntax-charref" title="syntax-charref">character references</dfn>. These can be used
1.1       mike      710:   to escape characters that couldn't otherwise legally be included in
1.123     mike      711:   <a href="#syntax-text" title="syntax-text">text</a>.</p><p>Character references must start with a U+0026 AMPERSAND
1.1       mike      712:   (<code>&amp;</code>). Following this, there are three possible kinds
1.123     mike      713:   of character references:</p><dl><dt>Named character references</dt>
1.1       mike      714: 
                    715:    <dd>The ampersand must be followed by one of the names given in the
                    716:    <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
                    717:    case. The name must be one that is terminated by a U+003B SEMICOLON
                    718:    (<code title="">;</code>) character.</dd>
                    719: 
                    720: 
                    721:    <dt>Decimal numeric character reference</dt>
                    722: 
                    723:    <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
                    724:    (<code>#</code>) character, followed by one or more digits in the
                    725:    range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, representing a
                    726:    base-ten integer that itself is a Unicode code point that is
                    727:    not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
                    728:    0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
                    729:    a U+003B SEMICOLON character (<code title="">;</code>).</dd>
                    730: 
                    731: 
                    732:    <dt>Hexadecimal numeric character reference</dt>
                    733: 
                    734:    <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
                    735:    (<code>#</code>) character, which must be followed by either a
                    736:    U+0078 LATIN SMALL LETTER X or a U+0058 LATIN CAPITAL LETTER X
                    737:    character, which must then be followed by one or more digits in the
                    738:    range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, U+0061 LATIN SMALL
                    739:    LETTER A .. U+0066 LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL
                    740:    LETTER A .. U+0046 LATIN CAPITAL LETTER F, representing a
                    741:    base-sixteen integer that itself is a Unicode code point that is
                    742:    not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
                    743:    0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
                    744:    a U+003B SEMICOLON character (<code title="">;</code>).</dd>
                    745: 
                    746:   </dl><p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
                    747:   ampersand</dfn> is a U+0026 AMPERSAND (<code>&amp;</code>) character
                    748:   that is followed by some <a href="#syntax-text" title="syntax-text">text</a> other
                    749:   than a <a href="infrastructure.html#space-character">space character</a>, a U+003C LESS-THAN SIGN
                    750:   character ('&lt;'), or another U+0026 AMPERSAND (<code>&amp;</code>)
1.123     mike      751:   character.</p><h4 id="cdata-sections"><span class="secno">9.1.5 </span>CDATA sections</h4><p><dfn id="syntax-cdata" title="syntax-cdata">CDATA sections</dfn> must start with
1.1       mike      752:   the character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
                    753:   MARK, U+005B LEFT SQUARE BRACKET, U+0043 LATIN CAPITAL LETTER C,
                    754:   U+0044 LATIN CAPITAL LETTER D, U+0041 LATIN CAPITAL LETTER A, U+0054
                    755:   LATIN CAPITAL LETTER T, U+0041 LATIN CAPITAL LETTER A, U+005B LEFT
                    756:   SQUARE BRACKET (<code title="">&lt;![CDATA[</code>). Following this
                    757:   sequence, the CDATA section may have <a href="#syntax-text" title="syntax-text">text</a>, with the additional restriction
                    758:   that the text must not contain the three character sequence U+005D
                    759:   RIGHT SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E
                    760:   GREATER-THAN SIGN (<code title="">]]&gt;</code>). Finally, the CDATA
                    761:   section must be ended by the three character sequence U+005D RIGHT
                    762:   SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E GREATER-THAN
1.159     mike      763:   SIGN (<code title="">]]&gt;</code>).</p><h4 id="comments"><span class="secno">9.1.6 </span>Comments</h4><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p><p><dfn id="syntax-comments" title="syntax-comments">Comments</dfn> must start with the
1.1       mike      764:   four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
                    765:   MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title="">&lt;!--</code>). Following this sequence, the comment may
                    766:   have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
                    767:   restriction that the text must not start with a single U+003E
                    768:   GREATER-THAN SIGN ('&gt;') character, nor start with a U+002D
                    769:   HYPHEN-MINUS (<code title="">-</code>) character followed by a
                    770:   U+003E GREATER-THAN SIGN ('&gt;') character, nor contain two
                    771:   consecutive U+002D HYPHEN-MINUS (<code title="">-</code>)
                    772:   characters, nor end with a U+002D HYPHEN-MINUS (<code title="">-</code>) character. Finally, the comment must be ended by
                    773:   the three character sequence U+002D HYPHEN-MINUS, U+002D
1.123     mike      774:   HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--&gt;</code>).</p><div class="impl">
1.1       mike      775: 
1.159     mike      776:   <h3 id="parsing"><span class="secno">9.2 </span>Parsing HTML documents</h3><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1       mike      777: 
                    778:   <p><i>This section only applies to user agents, data mining tools,
                    779:   and conformance checkers.</i></p>
                    780: 
                    781:   <p class="note">The rules for parsing XML documents into DOM trees
                    782:   are covered by the next section, entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
                    783:   syntax</a>".</p>
                    784: 
                    785:   <p>For <a href="dom.html#html-documents">HTML documents</a>, user agents must use the parsing
                    786:   rules described in this section to generate the DOM trees. Together,
                    787:   these rules define what is referred to as the <dfn id="html-parser">HTML
                    788:   parser</dfn>.</p>
                    789: 
                    790:   <div class="note">
                    791: 
                    792:    <p>While the HTML syntax described in this specification bears a
                    793:    close resemblance to SGML and XML, it is a separate language with
                    794:    its own parsing rules.</p>
                    795: 
1.183     mike      796:    <p>Some earlier versions of HTML (in particular from HTML2 to
                    797:    HTML4) were based on SGML and used SGML parsing rules. However, few
1.1       mike      798:    (if any) web browsers ever implemented true SGML parsing for HTML
                    799:    documents; the only user agents to strictly handle HTML as an SGML
                    800:    application have historically been validators. The resulting
                    801:    confusion &#8212; with validators claiming documents to have one
                    802:    representation while widely deployed Web browsers interoperably
                    803:    implemented a different representation &#8212; has wasted decades
                    804:    of productivity. This version of HTML thus returns to a non-SGML
                    805:    basis.</p>
                    806: 
                    807:    <p>Authors interested in using SGML tools in their authoring
                    808:    pipeline are encouraged to use XML tools and the XML serialization
                    809:    of HTML.</p>
                    810: 
                    811:   </div>
                    812: 
                    813:   <p>This specification defines the parsing rules for HTML documents,
                    814:   whether they are syntactically correct or not. Certain points in the
                    815:   parsing algorithm are said to be <dfn id="parse-error" title="parse error">parse
                    816:   errors</dfn>. The error handling for parse errors is well-defined:
                    817:   user agents must either act as described below when encountering
                    818:   such problems, or must abort processing at the first error that they
                    819:   encounter for which they do not wish to apply the rules described
                    820:   below.</p>
                    821: 
                    822:   <p>Conformance checkers must report at least one parse error
                    823:   condition to the user if one or more parse error conditions exist in
                    824:   the document and must not report parse error conditions if none
                    825:   exist in the document. Conformance checkers may report more than one
1.174     mike      826:   parse error condition if more than one parse error condition exists
1.1       mike      827:   in the document. Conformance checkers are not required to recover
                    828:   from parse errors.</p>
                    829: 
                    830:   <p class="note">Parse errors are only errors with the
                    831:   <em>syntax</em> of HTML. In addition to checking for parse errors,
                    832:   conformance checkers will also verify that the document obeys all
                    833:   the other conformance requirements described in this
                    834:   specification.</p>
                    835: 
                    836:   <p>For the purposes of conformance checkers, if a resource is
                    837:   determined to be in <a href="#syntax">the HTML syntax</a>, then it is an
                    838:   <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                    839: 
1.266     mike      840:   </div><div class="impl">
1.1       mike      841: 
                    842:   <h4 id="overview-of-the-parsing-model"><span class="secno">9.2.1 </span>Overview of the parsing model</h4>
                    843: 
                    844:   <p>The input to the HTML parsing process consists of a stream of
                    845:   Unicode characters, which is passed through a
                    846:   <a href="#tokenization">tokenization</a> stage followed by a <a href="#tree-construction">tree
                    847:   construction</a> stage. The output is a <code>Document</code>
                    848:   object.</p>
                    849: 
                    850:   <p class="note">Implementations that <a href="infrastructure.html#non-scripted">do not
                    851:   support scripting</a> do not have to actually create a DOM
                    852:   <code>Document</code> object, but the DOM tree in such cases is
                    853:   still used as the model for the rest of the specification.</p>
                    854: 
                    855:   <p>In the common case, the data handled by the tokenization stage
1.159     mike      856:   comes from the network, but <a href="embedded-content-0.html#dynamic-markup-insertion" title="dynamic markup
                    857:   insertion">it can also come from script</a>, e.g. using the <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code> API.</p>
1.1       mike      858: 
                    859:   <p><img alt="" src="images/parsing-model-overview.png"></p>
                    860: 
                    861:   <p id="nestedParsing">There is only one set of states for the
                    862:   tokenizer stage and the tree construction stage, but the tree
                    863:   construction stage is reentrant, meaning that while the tree
                    864:   construction stage is handling one token, the tokenizer might be
                    865:   resumed, causing further tokens to be emitted and processed before
                    866:   the first token's processing is complete.</p>
                    867: 
                    868:   <div class="example">
                    869: 
                    870:    <p>In the following example, the tree construction stage will be
                    871:    called upon to handle a "p" start tag token while handling the
                    872:    "script" start tag token:</p>
                    873: 
                    874:    <pre>...
                    875: &lt;script&gt;
                    876:  document.write('&lt;p&gt;');
                    877: &lt;/script&gt;
                    878: ...</pre>
                    879: 
                    880:   </div>
                    881: 
                    882:   <p>To handle these cases, parsers have a <dfn id="script-nesting-level">script nesting
                    883:   level</dfn>, which must be initially set to zero, and a <dfn id="parser-pause-flag">parser
                    884:   pause flag</dfn>, which must be initially set to false.</p>
                    885: 
1.266     mike      886:   </div><div class="impl">
1.1       mike      887: 
                    888:   <h4 id="the-input-stream"><span class="secno">9.2.2 </span>The <dfn>input stream</dfn></h4>
                    889: 
                    890:   <p>The stream of Unicode characters that comprises the input to the
                    891:   tokenization stage will be initially seen by the user agent as a
                    892:   stream of bytes (typically coming over the network or from the local
                    893:   file system). The bytes encode the actual characters according to a
                    894:   particular <em>character encoding</em>, which the user agent must
                    895:   use to decode the bytes into characters.</p>
                    896: 
                    897:   <p class="note">For XML documents, the algorithm user agents must
                    898:   use to determine the character encoding is given by the XML
1.104     mike      899:   specification. This section does not apply to XML documents. <a href="references.html#refsXML">[XML]</a></p>
1.1       mike      900: 
                    901: 
1.168     mike      902:   <h5 id="determining-the-character-encoding"><span class="secno">9.2.2.1 </span>Determining the character encoding</h5><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p>
1.1       mike      903: 
                    904:   <p>In some cases, it might be impractical to unambiguously determine
                    905:   the encoding before parsing the document. Because of this, this
                    906:   specification provides for a two-pass mechanism with an optional
                    907:   pre-scan. Implementations are allowed, as described below, to apply
                    908:   a simplified parsing algorithm to whatever bytes they have available
                    909:   before beginning to parse the document. Then, the real parser is
                    910:   started, using a tentative encoding derived from this pre-parse and
                    911:   other out-of-band metadata. If, while the document is being loaded,
                    912:   the user agent discovers an encoding declaration that conflicts with
                    913:   this information, then the parser can get reinvoked to perform a
                    914:   parse of the document with the real encoding.</p>
                    915: 
                    916:   <p id="documentEncoding">User agents must use the following
                    917:   algorithm (the <dfn id="encoding-sniffing-algorithm">encoding sniffing algorithm</dfn>) to determine
                    918:   the character encoding to use when decoding a document in the first
                    919:   pass. This algorithm takes as input any out-of-band metadata
                    920:   available to the user agent (e.g. the <a href="infrastructure.html#content-type" title="Content-Type">Content-Type metadata</a> of the document)
                    921:   and all the bytes available so far, and returns an encoding and a
                    922:   <dfn id="concept-encoding-confidence" title="concept-encoding-confidence">confidence</dfn>. The
                    923:   confidence is either <i>tentative</i>, <i>certain</i>, or
                    924:   <i>irrelevant</i>. The encoding used, and whether the confidence in
                    925:   that encoding is <i>tentative</i> or <i>certain</i>, is <a href="#meta-charset-during-parse">used during the parsing</a> to
                    926:   determine whether to <a href="#change-the-encoding">change the encoding</a>. If no
                    927:   encoding is necessary, e.g. because the parser is operating on a
                    928:   stream of Unicode characters and doesn't have to use an encoding at
                    929:   all, then the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                    930:   <i>irrelevant</i>.</p>
                    931: 
                    932:   <ol><li><p>If the transport layer specifies an encoding, and it is
                    933:    supported, return that encoding with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                    934:    <i>certain</i>, and abort these steps.</p></li>
                    935: 
                    936:    <li><p>The user agent may wait for more bytes of the resource to be
                    937:    available, either in this step or at any later step in this
                    938:    algorithm. For instance, a user agent might wait 500ms or 512
                    939:    bytes, whichever came first. In general preparsing the source to
                    940:    find the encoding improves performance, as it reduces the need to
                    941:    throw away the data structures used when parsing upon finding the
                    942:    encoding information. However, if the user agent delays too long to
                    943:    obtain data to determine the encoding, then the cost of the delay
                    944:    could outweigh any performance improvements from the
                    945:    preparse.</p></li>
                    946: 
                    947:    <li><p>For each of the rows in the following table, starting with
                    948:    the first one and going down, if there are as many or more bytes
                    949:    available than the number of bytes in the first column, and the
                    950:    first bytes of the file match the bytes given in the first column,
                    951:    then return the encoding given in the cell in the second column of
                    952:    that row, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                    953:    <i>certain</i>, and abort these steps:</p>
                    954: 
                    955:     <!-- this table is present in several forms in this file; keep them in sync -->
                    956:     <table><thead><tr><th>Bytes in Hexadecimal
                    957:        </th><th>Encoding
                    958:      </th></tr></thead><tbody><!-- nobody uses this
                    959:       <tr>
                    960:        <td>00 00 FE FF
                    961:        <td>UTF-32BE
                    962:       <tr>
                    963:        <td>FF FE 00 00
                    964:        <td>UTF-32LE
                    965: --><tr><td>FE FF
                    966:        </td><td>UTF-16BE
                    967:       </td></tr><tr><td>FF FE
                    968:        </td><td>UTF-16LE
                    969:       </td></tr><tr><td>EF BB BF
                    970:        </td><td>UTF-8
                    971: <!-- nobody uses this
                    972:       <tr>
                    973:        <td>DD 73 66 73
                    974:        <td>UTF-EBCDIC
                    975: -->
                    976:     </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
                    977:    (BOMs).</p></li>
                    978: 
                    979:    <li><p>Otherwise, the user agent will have to search for explicit
                    980:    character encoding information in the file itself. This should
                    981:    proceed as follows:
                    982: 
                    983:     </p><p>Let <var title="">position</var> be a pointer to a byte in the
                    984:     input stream, initially pointing at the first byte. If at any
                    985:     point during these substeps the user agent either runs out of
                    986:     bytes or decides that scanning further bytes would not be
                    987:     efficient, then skip to the next step of the overall character
                    988:     encoding detection algorithm. User agents may decide that scanning
                    989:     <em>any</em> bytes is not efficient, in which case these substeps
                    990:     are entirely skipped.</p>
                    991: 
                    992:     <p>Now, repeat the following "two" steps until the algorithm
                    993:     aborts (either because user agent aborts, as described above, or
                    994:     because a character encoding is found):</p>
                    995: 
                    996:     <ol><li><p>If <var title="">position</var> points to:</p>
                    997: 
                    998:       <dl class="switch"><dt>A sequence of bytes starting with: 0x3C 0x21 0x2D 0x2D (ASCII '&lt;!--')</dt>
                    999:        <dd>
                   1000: 
                   1001:         <p>Advance the <var title="">position</var> pointer so that it
                   1002:         points at the first 0x3E byte which is preceded by two 0x2D
                   1003:         bytes (i.e. at the end of an ASCII '--&gt;' sequence) and comes
                   1004:         after the 0x3C byte that was found. (The two 0x2D bytes can be
                   1005:         the same as the those in the '&lt;!--' sequence.)</p>
                   1006: 
                   1007:        </dd>
                   1008: 
                   1009:        <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>
                   1010:        <dd>
                   1011: 
                   1012:         <ol><li><p>Advance the <var title="">position</var> pointer so
                   1013:          that it points at the next 0x09, 0x0A, 0x0C, 0x0D, 0x20, or
                   1014:          0x2F byte (the one in sequence of characters matched
                   1015:          above).</p></li>
                   1016: 
                   1017:          <li><p><a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">Get
                   1018:          an attribute</a> and its value. If no attribute was
                   1019:          sniffed, then skip this inner set of steps, and jump to the
                   1020:          second step in the overall "two step" algorithm.</p></li>
                   1021: 
                   1022:          <li><p>If the attribute's name is neither "<code title="">charset</code>" nor "<code title="">content</code>",
                   1023:          then return to step 2 in these inner steps.</p></li>
                   1024: 
                   1025:          <li><p>If the attribute's name is "<code title="">charset</code>", let <var title="">charset</var> be
                   1026:          the attribute's value, interpreted as a character
                   1027:          encoding.</p></li>
                   1028: 
                   1029:          <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
                   1030:          extracting an encoding from a Content-Type</a>, giving the
                   1031:          attribute's value as the string to parse. If an encoding is
                   1032:          returned, let <var title="">charset</var> be that
                   1033:          encoding. Otherwise, return to step 2 in these inner
                   1034:          steps.</p></li>
                   1035: 
                   1036:          <li><p>If <var title="">charset</var> is a UTF-16 encoding,
                   1037:          change the value of <var title="">charset</var> to
                   1038:          UTF-8.</p></li>
                   1039: 
                   1040:          <li><p>If <var title="">charset</var> is a supported
                   1041:          character encoding, then return the given encoding, with
                   1042:          <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1043:          <i>tentative</i>, and abort all these steps.</p></li>
                   1044: 
                   1045:          <li><p>Otherwise, return to step 2 in these inner
                   1046:          steps.</p></li>
                   1047: 
                   1048:         </ol></dd>
                   1049: 
                   1050:        <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>
                   1051:        <dd>
                   1052: 
                   1053:         <ol><li><p>Advance the <var title="">position</var> pointer so
                   1054:          that it points at the next 0x09 (ASCII TAB), 0x0A (ASCII LF),
                   1055:          0x0C (ASCII FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E
                   1056:          (ASCII '&gt;') byte.</p></li>
                   1057: 
                   1058:          <li><p>Repeatedly <a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
                   1059:          attribute</a> until no further attributes can be found,
                   1060:          then jump to the second step in the overall "two step"
                   1061:          algorithm.</p></li>
                   1062: 
                   1063:         </ol></dd>
                   1064: 
                   1065:        <dt>A sequence of bytes starting with: 0x3C 0x21 (ASCII '&lt;!')</dt>
                   1066:        <dt>A sequence of bytes starting with: 0x3C 0x2F (ASCII '&lt;/')</dt>
                   1067:        <dt>A sequence of bytes starting with: 0x3C 0x3F (ASCII '&lt;?')</dt>
                   1068:        <dd>
                   1069: 
                   1070:         <p>Advance the <var title="">position</var> pointer so that it
                   1071:         points at the first 0x3E byte (ASCII '&gt;') that comes after the
                   1072:         0x3C byte that was found.</p>
                   1073: 
                   1074:        </dd>
                   1075: 
                   1076:        <dt>Any other byte</dt>
                   1077:        <dd>
                   1078: 
                   1079:         <p>Do nothing with that byte.</p>
                   1080: 
                   1081:        </dd>
                   1082: 
                   1083:       </dl></li>
                   1084: 
                   1085:      <li>Move <var title="">position</var> so it points at the next
                   1086:      byte in the input stream, and return to the first step of this
                   1087:      "two step" algorithm.</li>
                   1088: 
                   1089:     </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
                   1090:     attribute</dfn>, it means doing this:</p>
                   1091: 
                   1092:     <ol><li><p>If the byte at <var title="">position</var> is one of 0x09
                   1093:      (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII FF), 0x0D (ASCII CR),
                   1094:      0x20 (ASCII space), or 0x2F (ASCII '/') then advance <var title="">position</var> to the next byte and redo this
                   1095:      substep.</p></li>
                   1096: 
                   1097:      <li><p>If the byte at <var title="">position</var> is 0x3E (ASCII
                   1098:      '&gt;'), then abort the "get an attribute" algorithm. There isn't
                   1099:      one.</p></li>
                   1100: 
                   1101:      <li><p>Otherwise, the byte at <var title="">position</var> is the
                   1102:      start of the attribute name. Let <var title="">attribute
                   1103:      name</var> and <var title="">attribute value</var> be the empty
                   1104:      string.</p></li>
                   1105: 
                   1106:      <li><p><i>Attribute name</i>: Process the byte at <var title="">position</var> as follows:</p>
                   1107: 
                   1108:       <dl class="switch"><dt>If it is 0x3D (ASCII '='), and the <var title="">attribute
                   1109:        name</var> is longer than the empty string</dt>
                   1110: 
                   1111:        <dd>Advance <var title="">position</var> to the next byte and
                   1112:        jump to the step below labeled <i>value</i>.</dd>
                   1113: 
                   1114:        <dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
                   1115:        FF), 0x0D (ASCII CR), or 0x20 (ASCII space)</dt>
                   1116: 
                   1117:        <dd>Jump to the step below labeled <i>spaces</i>.</dd>
                   1118: 
                   1119:        <dt>If it is 0x2F (ASCII '/') or 0x3E (ASCII '&gt;')</dt>
                   1120: 
                   1121:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1122:        name is the value of <var title="">attribute name</var>, its
                   1123:        value is the empty string.</dd>
                   1124: 
                   1125:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1126:        'Z')</dt>
                   1127: 
                   1128:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1129:        name</var> (where <var title="">b</var> is the value of the
                   1130:        byte at <var title="">position</var>).</dd>
                   1131: 
                   1132:        <dt>Anything else</dt>
                   1133: 
                   1134:        <dd>Append the Unicode character with the same code point as the
                   1135:        value of the byte at <var title="">position</var>) to <var title="">attribute name</var>. (It doesn't actually matter how
                   1136:        bytes outside the ASCII range are handled here, since only
                   1137:        ASCII characters can contribute to the detection of a character
                   1138:        encoding.)</dd>
                   1139: 
                   1140:       </dl></li>
                   1141: 
                   1142:      <li><p>Advance <var title="">position</var> to the next byte and
                   1143:      return to the previous step.</p></li>
                   1144: 
                   1145:      <li><p><i>Spaces</i>: If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
                   1146:      LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
                   1147:      advance <var title="">position</var> to the next byte, then,
                   1148:      repeat this step.</p></li>
                   1149: 
                   1150:      <li><p>If the byte at <var title="">position</var> is
                   1151:      <em>not</em> 0x3D (ASCII '='), abort the "get an attribute"
                   1152:      algorithm. The attribute's name is the value of <var title="">attribute name</var>, its value is the empty
                   1153:      string.</p></li>
                   1154: 
                   1155:      <li><p>Advance <var title="">position</var> past the 0x3D (ASCII
                   1156:      '=') byte.</p></li>
                   1157: 
                   1158:      <li><p><i>Value:</i> If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
                   1159:      LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
                   1160:      advance <var title="">position</var> to the next byte, then,
                   1161:      repeat this step.</p></li>
                   1162: 
                   1163:      <li><p>Process the byte at <var title="">position</var> as
                   1164:      follows:</p>
                   1165: 
                   1166:       <dl class="switch"><dt>If it is 0x22 (ASCII '"') or 0x27 ("'")</dt>
                   1167: 
                   1168:        <dd>
                   1169: 
                   1170:         <ol><li>Let <var title="">b</var> be the value of the byte at
                   1171:          <var title="">position</var>.</li>
                   1172: 
                   1173:          <li>Advance <var title="">position</var> to the next
                   1174:          byte.</li>
                   1175: 
                   1176:          <li>If the value of the byte at <var title="">position</var>
                   1177:          is the value of <var title="">b</var>, then advance <var title="">position</var> to the next byte and abort the "get
                   1178:          an attribute" algorithm. The attribute's name is the value of
                   1179:          <var title="">attribute name</var>, and its value is the
                   1180:          value of <var title="">attribute value</var>.</li>
                   1181: 
                   1182:          <li>Otherwise, if the value of the byte at <var title="">position</var> is in the range 0x41 (ASCII 'A') to
                   1183:          0x5A (ASCII 'Z'), then append a Unicode character to <var title="">attribute value</var> whose code point is 0x20 more
                   1184:          than the value of the byte at <var title="">position</var>.</li>
                   1185: 
                   1186:          <li>Otherwise, append a Unicode character to <var title="">attribute value</var> whose code point is the same as
                   1187:          the value of the byte at <var title="">position</var>.</li>
                   1188: 
                   1189:          <li>Return to the second step in these substeps.</li>
                   1190: 
                   1191:         </ol></dd>
                   1192: 
                   1193:        <dt>If it is 0x3E (ASCII '&gt;')</dt>
                   1194: 
                   1195:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1196:        name is the value of <var title="">attribute name</var>, its
                   1197:        value is the empty string.</dd>
                   1198: 
                   1199: 
                   1200:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1201:        'Z')</dt>
                   1202: 
                   1203:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1204:        value</var> (where <var title="">b</var> is the value of the
                   1205:        byte at <var title="">position</var>). Advance <var title="">position</var> to the next byte.</dd>
                   1206: 
                   1207:        <dt>Anything else</dt>
                   1208: 
                   1209:        <dd>Append the Unicode character with the same code point as the
                   1210:        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>
                   1211: 
                   1212:       </dl></li>
                   1213: 
                   1214:      <li><p>Process the byte at <var title="">position</var> as
                   1215:      follows:</p>
                   1216: 
                   1217:       <dl class="switch"><dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
                   1218:        FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E (ASCII
                   1219:        '&gt;')</dt>
                   1220: 
                   1221:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1222:        name is the value of <var title="">attribute name</var> and its
                   1223:        value is the value of <var title="">attribute value</var>.</dd>
                   1224: 
                   1225:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1226:        'Z')</dt>
                   1227: 
                   1228:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1229:        value</var> (where <var title="">b</var> is the value of the
                   1230:        byte at <var title="">position</var>).</dd>
                   1231: 
                   1232:        <dt>Anything else</dt>
                   1233: 
                   1234:        <dd>Append the Unicode character with the same code point as the
                   1235:        value of the byte at <var title="">position</var>) to <var title="">attribute value</var>.</dd>
                   1236: 
                   1237:       </dl></li>
                   1238: 
                   1239:      <li><p>Advance <var title="">position</var> to the next byte and
                   1240:      return to the previous step.</p></li>
                   1241: 
                   1242:     </ol><p>For the sake of interoperability, user agents should not use a
                   1243:     pre-scan algorithm that returns different results than the one
                   1244:     described above. (But, if you do, please at least let us know, so
                   1245:     that we can improve this algorithm and benefit everyone...)</p>
                   1246: 
                   1247:    </li>
                   1248: 
                   1249:    <li><p>If the user agent has information on the likely encoding for
                   1250:    this page, e.g. based on the encoding of the page when it was last
                   1251:    visited, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1252:    <i>tentative</i>, and abort these steps.</p></li>
                   1253: 
                   1254:    <li><p>The user agent may attempt to autodetect the character
                   1255:    encoding from applying frequency analysis or other algorithms to
                   1256:    the data stream. If autodetection succeeds in determining a
                   1257:    character encoding, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1.104     mike     1258:    <i>tentative</i>, and abort these steps. <a href="references.html#refsUNIVCHARDET">[UNIVCHARDET]</a></p></li>
1.1       mike     1259: 
                   1260:    <li><p>Otherwise, return an implementation-defined or
                   1261:    user-specified default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1262:    <i>tentative</i>. In non-legacy environments, the more
                   1263:    comprehensive <code title="">UTF-8</code> encoding is
                   1264:    recommended. Due to its use in legacy content, <code title="">windows-1252</code> is recommended as a default in
1.187     mike     1265:    predominantly Western demographics instead.</p></li>
1.1       mike     1266: 
                   1267:   </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
                   1268:   be set to the value returned from this algorithm, at the same time
                   1269:   as the user agent uses the returned value to select the decoder to
                   1270:   use for the input stream.</p>
                   1271: 
                   1272: 
1.237     mike     1273:   <h5 id="character-encodings-0"><span class="secno">9.2.2.2 </span>Character encodings</h5><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p>
1.1       mike     1274: 
1.237     mike     1275:   <p>User agents must at a minimum support the UTF-8 and Windows-1252
                   1276:   encodings, but may support more.</p>
                   1277: 
                   1278:   <p class="note">It is not unusual for Web browsers to support dozens
                   1279:   if not upwards of a hundred distinct character encodings.</p>
                   1280: 
                   1281:   <p>User agents must support the preferred MIME name of every
                   1282:   character encoding they support that has a preferred MIME name, and
                   1283:   should support all the IANA-registered aliases of every character
                   1284:   encoding they support. <a href="references.html#refsIANACHARSET">[IANACHARSET]</a></p>
                   1285: 
                   1286:   <p>When comparing a string specifying a character encoding with the
                   1287:   name or alias of a character encoding to determine if they are
                   1288:   equal, user agents must remove any leading or trailing <a href="infrastructure.html#space-character" title="space character">space characters</a> in both names, and
                   1289:   then perform the comparison in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   1290:   case-insensitive</a> manner.</p>
                   1291: 
                   1292: <!-- this bit will be replaced by actual alias registrations in due course -->
                   1293: 
                   1294:   <p>In addition, user agents must support the aliases given in the
                   1295:   following table for every character encoding they support, so that
                   1296:   labels from the first column are treated as equivalent to the labels
                   1297:   given in the corresponding cell from the second column on the same
                   1298:   row.</p>
                   1299: 
                   1300:   <table><caption>Additional character encoding aliases</caption>
                   1301:    <thead><tr><th> Alias </th><th> Corresponding encoding </th><th> References
                   1302:    </th></tr></thead><tbody><tr><td> x-sjis </td><td> windows-31J </td><td>
                   1303:          <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
                   1304:          <a href="references.html#refsWIN31J">[WIN31J]</a>
                   1305:     </td></tr><tr><td> windows-932 </td><td> windows-31J </td><td>
                   1306:          <a href="references.html#refsWIN31J">[WIN31J]</a>
                   1307:     </td></tr><tr><td> x-x-big5 </td><td> Big5 </td><td>
                   1308:          <a href="references.html#refsBIG5">[BIG5]</a>
                   1309:    </td></tr></tbody></table><!-- end of bit that will be replaced by actual alias registrations in due course --><hr><p>When a user agent would otherwise use an encoding given in the
                   1310:   first column of the following table to either convert content to
                   1311:   Unicode characters or convert Unicode characters to bytes, it must
                   1312:   instead use the encoding given in the cell in the second column of
                   1313:   the same row. When a byte or sequence of bytes is treated
                   1314:   differently due to this encoding aliasing, it is said to have been
                   1315:   <dfn id="misinterpreted-for-compatibility">misinterpreted for compatibility</dfn>.</p>
                   1316: 
                   1317:   <table><caption>Character encoding overrides</caption>
                   1318:    <thead><tr><th> Input encoding </th><th> Replacement encoding </th><th> References
                   1319:    </th></tr></thead><tbody><!-- how about EUC-JP? --><tr><td> EUC-KR </td><td> windows-949 </td><td>
                   1320:          <a href="references.html#refsEUCKR">[EUCKR]</a>
                   1321:          <a href="references.html#refsWIN949">[WIN949]</a>
                   1322:     </td></tr><tr><td> GB2312 </td><td> GBK </td><td>
                   1323:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1324:          <a href="references.html#refsGBK">[GBK]</a>
                   1325:     </td></tr><tr><td> GB_2312-80 </td><td> GBK </td><td>
                   1326:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1327:          <a href="references.html#refsGBK">[GBK]</a>
                   1328:     </td></tr><tr><td> ISO-8859-1 </td><td> windows-1252 </td><td>
                   1329:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1330:          <a href="references.html#refsWIN1252">[WIN1252]</a>
                   1331:     </td></tr><tr><td> ISO-8859-9 </td><td> windows-1254 </td><td>
                   1332:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1333:          <a href="references.html#refsWIN1254">[WIN1254]</a>
                   1334:     </td></tr><tr><td> ISO-8859-11 </td><td> windows-874 </td><td>
                   1335:          <a href="references.html#refsISO885911">[ISO885911]</a>
                   1336:          <a href="references.html#refsWIN874">[WIN874]</a>
                   1337:     </td></tr><tr><td> KS_C_5601-1987 </td><td> windows-949 </td><td>
                   1338:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1339:          <a href="references.html#refsWIN949">[WIN949]</a>
                   1340:     </td></tr><tr><td> Shift_JIS </td><td> windows-31J </td><td>
                   1341:          <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
                   1342:          <a href="references.html#refsWIN31J">[WIN31J]</a>
                   1343:     </td></tr><tr><td> TIS-620 </td><td> windows-874 </td><td>
                   1344:          <a href="references.html#refsTIS620">[TIS620]</a>
                   1345:          <a href="references.html#refsWIN874">[WIN874]</a>
                   1346:     </td></tr><tr><td> US-ASCII </td><td> windows-1252 </td><td>
                   1347:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1348:          <a href="references.html#refsWIN1252">[WIN1252]</a>
                   1349:    </td></tr></tbody></table><p class="note">The requirement to treat certain encodings as other
                   1350:   encodings according to the table above is a <a href="introduction.html#willful-violation">willful
                   1351:   violation</a> of the W3C Character Model specification, motivated
                   1352:   by a desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
                   1353: 
                   1354:   <p>When a user agent is to use the UTF-16 encoding but no BOM has
                   1355:   been found, user agents must default to UTF-16LE.</p>
                   1356: 
                   1357:   <p class="note">The requirement to default UTF-16 to LE rather than
                   1358:   BE is a <a href="introduction.html#willful-violation">willful violation</a> of RFC 2781, motivated by a
                   1359:   desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
                   1360: 
                   1361:   <hr><p>User agents must not support the CESU-8, UTF-7, BOCU-1 and SCSU
                   1362:   encodings. <a href="references.html#refsCESU8">[CESU8]</a> <a href="references.html#refsUTF7">[UTF7]</a> <a href="references.html#refsBOCU1">[BOCU1]</a> <a href="references.html#refsSCSU">[SCSU]</a></p>
                   1363: 
                   1364:   <p>Support for encodings based on EBCDIC is not recommended. This
                   1365:   encoding is rarely used for publicly-facing Web content.</p>
                   1366: 
                   1367:   <p>Support for UTF-32 is not recommended. This encoding is rarely
                   1368:   used, and frequently implemented incorrectly.</p>
                   1369: 
                   1370:   <p class="note">This specification does not make any attempt to
                   1371:   support EBCDIC-based encodings and UTF-32 in its algorithms; support
                   1372:   and use of these encodings can thus lead to unexpected behavior in
                   1373:   implementations of this specification.</p>
                   1374: 
                   1375: 
                   1376: 
                   1377:   <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.3 </span>Preprocessing the input stream</h5>
1.1       mike     1378: 
                   1379:   <p>Given an encoding, the bytes in the input stream must be
                   1380:   converted to Unicode characters for the tokenizer, as described by
                   1381:   the rules for that encoding, except that the leading U+FEFF BYTE
                   1382:   ORDER MARK character, if any, must not be stripped by the encoding
                   1383:   layer (it is stripped by the rule below).</p> <!-- this is to
                   1384:   prevent two leading BOMs from being both stripped, once by the
                   1385:   decoder, and once by the parser -->
                   1386: 
                   1387:   <p>Bytes or sequences of bytes in the original byte stream that
                   1388:   could not be converted to Unicode characters must be converted to
                   1389:   U+FFFD REPLACEMENT CHARACTER code points.</p>
                   1390: 
                   1391:   <p class="note">Bytes or sequences of bytes in the original byte
                   1392:   stream that did not conform to the encoding specification
                   1393:   (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
                   1394:   errors that conformance checkers are expected to report.</p>
                   1395: 
                   1396:   <p>Any byte or sequences of bytes in the original byte stream that
1.237     mike     1397:   is <a href="#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
1.1       mike     1398:   error</a>.</p>
                   1399: 
                   1400:   <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
                   1401:   any are present.</p>
                   1402: 
                   1403:   <p>All U+0000 NULL characters in the input must be replaced by
                   1404:   U+FFFD REPLACEMENT CHARACTERs. Any occurrences of such characters is
                   1405:   a <a href="#parse-error">parse error</a>.</p>
                   1406: 
                   1407:   <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
                   1408:   <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
                   1409:   CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
                   1410:   <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+D800
                   1411:   to U+DFFF<!-- surrogates not allowed -->, U+FDD0 to U+FDEF, and
                   1412:   characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF, U+2FFFE,
                   1413:   U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE, U+5FFFF,
                   1414:   U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF, U+9FFFE,
                   1415:   U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE, U+CFFFF,
                   1416:   U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF, U+10FFFE, and
                   1417:   U+10FFFF are <a href="#parse-error" title="parse error">parse errors</a>. (These
                   1418:   are all control characters or permanently undefined Unicode
                   1419:   characters.)</p>
                   1420: 
                   1421:   <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
                   1422:   characters are treated specially. Any CR characters that are
                   1423:   followed by LF characters must be removed, and any CR characters not
                   1424:   followed by LF characters must be converted to LF characters. Thus,
                   1425:   newlines in HTML DOMs are represented by LF characters, and there
                   1426:   are never any CR characters in the input to the
                   1427:   <a href="#tokenization">tokenization</a> stage.</p>
                   1428: 
                   1429:   <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
                   1430:   input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
                   1431:   the <i><a href="#next-input-character">next input character</a></i> is the first character in the
                   1432:   input. The <dfn id="current-input-character">current input character</dfn> is the last character
                   1433:   to have been <i><a href="#consumed">consumed</a></i>.</p>
                   1434: 
                   1435:   <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
                   1436:   character or just before the end of the input stream) where content
1.159     mike     1437:   inserted using <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code> is actually
1.1       mike     1438:   inserted. The insertion point is relative to the position of the
                   1439:   character immediately after it, it is not an absolute offset into
                   1440:   the input stream. Initially, the insertion point is
1.10      mike     1441:   undefined.</p>
1.1       mike     1442: 
                   1443:   <p>The "EOF" character in the tables below is a conceptual character
                   1444:   representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
1.159     mike     1445:   is a <a href="embedded-content-0.html#script-created-parser">script-created parser</a>, then the end of the
1.1       mike     1446:   <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
1.159     mike     1447:   character</dfn> (inserted by the <code title="dom-document-close"><a href="embedded-content-0.html#dom-document-close">document.close()</a></code> method) is
1.1       mike     1448:   consumed. Otherwise, the "EOF" character is not a real character in
                   1449:   the stream, but rather the lack of any further characters.</p>
                   1450: 
                   1451: 
1.237     mike     1452:   <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.4 </span>Changing the encoding while parsing</h5>
1.1       mike     1453: 
                   1454:   <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
                   1455:   encoding</dfn>, it must run the following steps. This might happen
                   1456:   if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
                   1457:   failed to find an encoding, or if it found an encoding that was not
                   1458:   the actual encoding of the file.</p>
                   1459: 
                   1460:   <ol><li>If the new encoding is identical or equivalent to the encoding
                   1461:    that is already being used to interpret the input stream, then set
                   1462:    the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1463:    <i>certain</i> and abort these steps. This happens when the
                   1464:    encoding information found in the file matches what the
                   1465:    <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
                   1466:    encoding, and in the second pass through the parser if the first
                   1467:    pass found that the encoding sniffing algorithm described in the
                   1468:    earlier section failed to find the right encoding.</li>
                   1469: 
                   1470:    <li>If the encoding that is already being used to interpret the
                   1471:    input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1472:    <i>certain</i> and abort these steps. The new encoding is ignored;
                   1473:    if it was anything but the same encoding, then it would be clearly
                   1474:    incorrect.</li>
                   1475: 
                   1476:    <li>If the new encoding is a UTF-16 encoding, change it to
                   1477:    UTF-8.</li>
                   1478: 
                   1479:    <li>If all the bytes up to the last byte converted by the current
                   1480:    decoder have the same Unicode interpretations in both the current
                   1481:    encoding and the new encoding, and if the user agent supports
                   1482:    changing the converter on the fly, then the user agent may change
                   1483:    to the new converter for the encoding on the fly. Set the
                   1484:    <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
                   1485:    convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1486:    <i>certain</i>, and abort these steps.</li>
                   1487: 
                   1488:    <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
                   1489:    <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
                   1490:    browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
                   1491:    sniffing algorithm</a> and instead just set the encoding to the
                   1492:    new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1493:    <i>certain</i>. Whenever possible, this should be done without
                   1494:    actually contacting the network layer (the bytes should be
                   1495:    re-parsed from memory), even if, e.g., the document is marked as
                   1496:    not being cacheable. If this is not possible and contacting the
                   1497:    network layer would involve repeating a request that uses a method
                   1498:    other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
                   1499:    equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1500:    <i>certain</i> and ignore the new encoding. The resource will be
                   1501:    misinterpreted. User agents may notify the user of the situation,
                   1502:    to aid in application development.</li>
                   1503: 
1.266     mike     1504:   </ol></div><div class="impl">
                   1505: 
                   1506:   <h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4>
1.1       mike     1507: 
                   1508:   <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5>
                   1509: 
                   1510:   <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
                   1511:   the primary operation of the tree construction stage.</p>
                   1512: 
                   1513:   <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
                   1514:   "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
                   1515:   "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
                   1516:   "<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     1517:   "<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     1518:   "<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>",
                   1519:   "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
                   1520:   "<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
                   1521:   table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
                   1522:   foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
                   1523:   body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
                   1524:   frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
                   1525:   frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
                   1526:   after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
                   1527:   frameset</a>" during the course of the parsing, as described in
                   1528:   the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
                   1529:   how tokens are processed and whether CDATA sections are
                   1530:   supported.</p>
                   1531: 
                   1532:   <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
                   1533:   head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   1534:   body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
                   1535:   table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   1536:   body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
                   1537:   "<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
                   1538:   that the other modes defer to them at various times. When the
                   1539:   algorithm below says that the user agent is to do something
                   1540:   "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
                   1541:   mode", where <var title="">m</var> is one of these modes, the user
                   1542:   agent must use the rules described under the <var title="">m</var>
                   1543:   <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
                   1544:   <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>
                   1545:   to a new value.</p>
                   1546: 
                   1547:   <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.91      mike     1548:   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     1549:   <dfn id="original-insertion-mode">original insertion mode</dfn> is also set. This is the
                   1550:   insertion mode to which the tree construction stage will return.</p>
                   1551: 
                   1552:   <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
                   1553:   mode: in foreign content">in foreign content</a>", the
                   1554:   <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
                   1555:   is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1556:   foreign content">in foreign content</a>" mode to handle HTML
                   1557:   (i.e. not foreign) content.</p>
                   1558: 
                   1559:   <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
                   1560:   mode appropriately</dfn>, it means the UA must follow these
                   1561:   steps:</p>
                   1562: 
                   1563:   <ol><li>Let <var title="">last</var> be false.</li>
                   1564: 
                   1565:    <li>Let <var title="">node</var> be the last node in the
                   1566:    <a href="#stack-of-open-elements">stack of open elements</a>.</li>
                   1567: 
                   1568:    <li>If <var title="">node</var> is the first node in the stack of
                   1569:    open elements, then set <var title="">last</var> to true and set
                   1570:    <var title="">node</var> to the <var title="">context</var>
                   1571:    element. (<a href="#fragment-case">fragment case</a>)</li>
                   1572: 
                   1573:    <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
                   1574:    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
                   1575:    steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1576: 
                   1577:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
                   1578:    <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
                   1579:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
                   1580:    mode: in cell">in cell</a>" and abort these steps.</li>
                   1581: 
                   1582:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
                   1583:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
                   1584:    mode: in row">in row</a>" and abort these steps.</li>
                   1585: 
                   1586:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
                   1587:    <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
                   1588:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
                   1589:    table body">in table body</a>" and abort these steps.</li>
                   1590: 
                   1591:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
                   1592:    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
                   1593:    these steps.</li>
                   1594: 
                   1595:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
                   1596:    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
                   1597:    abort these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1598: 
                   1599:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   1600:    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
                   1601:    steps.</li>
                   1602: 
                   1603:    <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
                   1604:    namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then switch the
                   1605:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1606:    foreign content">in foreign content</a>", let the
                   1607:    <a href="#secondary-insertion-mode">secondary insertion mode</a> be "<a href="#parsing-main-inbody" title="insertion
                   1608:    mode: in body">in body</a>", and abort these steps.</li>
                   1609: 
1.159     mike     1610:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element-0">head</a></code> element,
1.1       mike     1611:    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
                   1612:    these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- This is only
                   1613:    here for now in case people think that the spec accidentally
                   1614:    omitted it and try to "fix" it. Note that noscript-in-head is also
                   1615:    handled this way. This is all intentional. The only thing it
                   1616:    doesn't handle is the scripting-disabled fragment parsing case for
                   1617:    a <head> element containing a <noscript> which itself contains
                   1618:    something other than a <link> or a <style> element; you'd expect
                   1619:    that to break out of the <noscript> but it doesn't. This is an edge
                   1620:    case that doesn't affect the spec, since the algorithm for fragment
                   1621:    parsing is only used for innerHTML/outerHTML/insertAdjacentHTML(),
                   1622:    where we know scripting is enabled. (XXX except maybe if innerHTML
                   1623:    is set from another browsing context on a document with designMode
                   1624:    set?) -->
                   1625: 
1.159     mike     1626:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element-0">body</a></code> element,
1.1       mike     1627:    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
                   1628:    steps.</li>
                   1629: 
1.5       mike     1630:    <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.1       mike     1631:    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
                   1632:    these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1633: 
1.159     mike     1634:    <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element-0">html</a></code> element,
1.1       mike     1635:    then: if the <a href="#head-element-pointer"><code title="">head</code> element
                   1636:    pointer</a> is null, switch the <a href="#insertion-mode">insertion mode</a> to
                   1637:    "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
                   1638:    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
                   1639:    case, abort these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- XXX
                   1640:    can the head element pointer ever be non-null when we're going
                   1641:    through these steps? -->
                   1642: 
                   1643:    <li>If <var title="">last</var> is true, then switch the
                   1644:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
                   1645:    body">in body</a>" and abort these steps. (<a href="#fragment-case">fragment
                   1646:    case</a>)</li>
                   1647: 
                   1648:    <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
                   1649:    elements</a>.</li>
                   1650: 
                   1651:    <li>Return to step 3.</li>
                   1652: 
                   1653:   </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5>
                   1654: 
                   1655:   <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
                   1656:   stack grows downwards; the topmost node on the stack is the first
                   1657:   one added to the stack, and the bottommost node of the stack is the
                   1658:   most recently added node in the stack (notwithstanding when the
                   1659:   stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
                   1660: 
                   1661:   <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
                   1662:   html</a>" <a href="#insertion-mode">insertion mode</a> creates the
1.159     mike     1663:   <code><a href="semantics.html#the-html-element-0">html</a></code> root element node, which is then added to the
1.1       mike     1664:   stack.</p>
                   1665: 
                   1666:   <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
1.159     mike     1667:   elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1       mike     1668:   element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
                   1669:   parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
                   1670:   case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
                   1671:   html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
                   1672: 
1.159     mike     1673:   <p>The <code><a href="semantics.html#the-html-element-0">html</a></code> node, however it is created, is the topmost
1.1       mike     1674:   node of the stack. It never gets popped off the stack.</p>
                   1675: 
                   1676:   <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
                   1677:   stack.</p>
                   1678: 
                   1679:   <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
                   1680:   element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
                   1681:   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
                   1682:   open elements</a> (<a href="#fragment-case">fragment case</a>), then the
                   1683:   <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
1.159     mike     1684:   of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code> element).</p>
1.1       mike     1685: 
                   1686:   <p>Elements in the stack fall into the following categories:</p>
                   1687: 
                   1688:   <dl><dt><dfn id="special">Special</dfn></dt>
                   1689: 
                   1690:    <dd><p>The following HTML elements have varying levels of special
                   1691:    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>,
                   1692:    <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     1693:    <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.159     mike     1694:    <code><a href="semantics.html#the-blockquote-element">blockquote</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="semantics.html#the-br-element">br</a></code>,
1.5       mike     1695:    <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     1696:    <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
                   1697:    <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>,
                   1698:    <code><a href="obsolete.html#dir">dir</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, <code><a href="semantics.html#the-dl-element">dl</a></code>,
1.159     mike     1699:    <code><a href="semantics.html#the-dt-element">dt</a></code>, <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>, <code><a href="forms.html#the-fieldset-element">fieldset</a></code>,
                   1700:    <code><a href="text-level-semantics.html#the-figure-element">figure</a></code>, <code><a href="semantics.html#the-footer-element">footer</a></code>, <code><a href="forms.html#the-form-element">form</a></code>,
1.86      mike     1701:    <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>,
                   1702:    <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h2</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h3</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h4</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h5</a></code>,
1.159     mike     1703:    <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h6</a></code>, <code><a href="semantics.html#the-head-element-0">head</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>,
                   1704:    <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>, <!--
1.86      mike     1705:    <code>image</code>, (commented out because this isn't an element
                   1706:    that can end up on the stack, so it doesn't matter) -->
1.159     mike     1707:    <code><a href="text-level-semantics.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="obsolete.html#isindex-0">isindex</a></code>,
1.86      mike     1708:    <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>,
                   1709:    <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>,
                   1710:    <code><a href="obsolete.html#noembed">noembed</a></code>, <code><a href="obsolete.html#noframes">noframes</a></code>, <code><a href="semantics.html#the-noscript-element">noscript</a></code>,
1.159     mike     1711:    <code><a href="semantics.html#the-ol-element">ol</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>, <code><a href="text-level-semantics.html#the-param-element">param</a></code>,
1.86      mike     1712:    <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>,
                   1713:    <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>,
                   1714:    <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="forms.html#the-textarea-element">textarea</a></code>,
1.159     mike     1715:    <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, <code><a href="semantics.html#the-title-element-0">title</a></code>,
1.174     mike     1716:    <code><a href="tabular-data.html#the-tr-element">tr</a></code>, <code><a href="semantics.html#the-ul-element">ul</a></code>, <code>wbr</code>, and
                   1717:    <code><a href="obsolete.html#xmp">xmp</a></code>.</p></dd>
1.1       mike     1718: 
                   1719:    <dt><dfn id="scoping">Scoping</dfn></dt>
                   1720:    <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
                   1721:    an element in scope">scopes</a> for various parts of the
1.5       mike     1722:    parsing: <code><a href="obsolete.html#the-applet-element">applet</a></code>, <code><a href="forms.html#the-button-element">button</a></code>,
1.159     mike     1723:    <code><a href="tabular-data.html#the-caption-element">caption</a></code>, <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="obsolete.html#the-marquee-element">marquee</a></code>,
                   1724:    <code><a href="text-level-semantics.html#the-object-element">object</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>, <code><a href="tabular-data.html#the-td-element">td</a></code>,
1.1       mike     1725:    <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
                   1726: 
                   1727:    <dt><dfn id="formatting">Formatting</dfn></dt>
                   1728:    <dd><p>The following HTML elements are those that end up in the
                   1729:    <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     1730:    <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>,
                   1731:    <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>,
                   1732:    <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>,
                   1733:    <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
                   1734:    <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1       mike     1735: 
                   1736:    <dt><dfn id="phrasing">Phrasing</dfn></dt>
                   1737:    <dd><p>All other elements found while parsing an HTML
                   1738:    document.</p></dd>
                   1739: 
1.234     mike     1740:   </dl><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-the-specific-scope" title="has an element in the specific scope">have an element in a
                   1741:   specific scope</dfn> consisting of a list of element types <var title="">list</var> when the following algorithm terminates in a
                   1742:   match state:</p>
1.1       mike     1743: 
                   1744:   <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   1745:    node</a> (the bottommost node of the stack).</p></li>
                   1746: 
                   1747:    <li><p>If <var title="">node</var> is the target node, terminate in
                   1748:    a match state.</p></li>
                   1749: 
1.234     mike     1750:    <li><p>Otherwise, if <var title="">node</var> is one of the element
                   1751:    types in <var title="">list</var>, terminate in a failure
                   1752:    state.</p></li>
1.1       mike     1753: 
                   1754:    <li><p>Otherwise, set <var title="">node</var> to the previous
                   1755:    entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
                   1756:    2. (This will never fail, since the loop will always terminate in
                   1757:    the previous step if the top of the stack &#8212; an
1.159     mike     1758:    <code><a href="semantics.html#the-html-element-0">html</a></code> element &#8212; is reached.)</p></li>
1.1       mike     1759: 
1.234     mike     1760:   </ol><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-scope" title="has an element in scope">have an element in scope</dfn> when
                   1761:   it <a href="#has-an-element-in-the-specific-scope">has an element in the specific scope</a> consisting
                   1762:   of the following element types:</p>
                   1763: 
                   1764:   <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
                   1765:    <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
                   1766:    <li><code><a href="semantics.html#the-html-element-0">html</a></code> in the HTML namespace</li> <!-- (This can only happen if the <var title="">node</var> is the topmost node of the <span>stack of open elements</span>, and prevents the next step from being invoked if there are no more elements in the stack.) -->
                   1767:    <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1768:    <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
                   1769:    <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
                   1770:    <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
                   1771:    <li><code><a href="obsolete.html#the-marquee-element">marquee</a></code> in the HTML namespace</li>
                   1772:    <li><code><a href="text-level-semantics.html#the-object-element">object</a></code> in the HTML namespace</li>
                   1773:    <li><code title="">foreignObject</code> in the SVG namespace</li>
                   1774:   </ul><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-list-item-scope" title="has an element in list item scope">have an element in list
                   1775:   item scope</dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
                   1776:   scope</a> consisting of the following element types:</p>
                   1777: 
                   1778:   <ul class="brief"><li>All the element types listed above for the <i><a href="#has-an-element-in-scope">has an element
                   1779:    in scope</a></i> algorithm.</li>
                   1780:    <li><code><a href="semantics.html#the-ol-element">ol</a></code> in the HTML namespace</li>
                   1781:    <li><code><a href="semantics.html#the-ul-element">ul</a></code> in the HTML namespace</li>
                   1782:   </ul><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-table-scope" title="has an element in table scope">have an element in <em>table
                   1783:   scope</em></dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
                   1784:   scope</a> consisting of the following element types:</p>
                   1785: 
                   1786:   <ul class="brief"><li><code><a href="semantics.html#the-html-element-0">html</a></code> in the HTML namespace</li> <!-- (This can only happen if the <var title="">node</var> is the topmost node of the <span>stack of open elements</span>, and prevents the next step from being invoked if there are no more elements in the stack.) -->
                   1787:    <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1788:   </ul><p>Nothing happens if at any time any of the elements in the
1.1       mike     1789:   <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
                   1790:   or removed from, the <code>Document</code> tree. In particular, the
                   1791:   stack is not changed in this situation. This can cause, amongst
                   1792:   other strange effects, content to be appended to nodes that are no
                   1793:   longer in the DOM.</p>
                   1794: 
                   1795:   <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
                   1796:   the stack is manipulated in a random-access fashion.</p>
                   1797: 
                   1798: 
                   1799:   <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5>
                   1800: 
                   1801:   <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
                   1802:   empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
                   1803: 
                   1804:   <p>The list contains elements in the <a href="#formatting">formatting</a>
                   1805:   category, and scope markers. The scope markers are inserted when
1.159     mike     1806:   entering <code><a href="obsolete.html#the-applet-element">applet</a></code> elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code>
1.1       mike     1807:   elements, marquees, table cells, and table captions, and are used to
1.5       mike     1808:   prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.159     mike     1809:   elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code> elements, marquees, and
1.1       mike     1810:   tables.</p>
                   1811: 
                   1812:   <p class="note">The scope markers are unrelated to the concept of an
                   1813:   element being <a href="#has-an-element-in-scope" title="has an element in scope">in
                   1814:   scope</a>.</p>
                   1815: 
                   1816:   <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1817:   elements</a> is associated with the token for which it was
                   1818:   created, so that further elements can be created for that token if
                   1819:   necessary.</p>
                   1820: 
                   1821:   <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
                   1822:   active formatting elements</dfn>, the UA must perform the following
                   1823:   steps:</p>
                   1824: 
                   1825:   <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1826:    elements</a>, then there is nothing to reconstruct; stop this
                   1827:    algorithm.</li>
                   1828: 
                   1829:    <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
                   1830:    active formatting elements</a> is a marker, or if it is an
                   1831:    element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
                   1832:    there is nothing to reconstruct; stop this algorithm.</li>
                   1833: 
                   1834:    <li>Let <var title="">entry</var> be the last (most recently added)
                   1835:    element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1836:    elements</a>.</li>
                   1837: 
                   1838:    <li>If there are no entries before <var title="">entry</var> in the
                   1839:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
                   1840:    8.</li>
                   1841: 
                   1842:    <li>Let <var title="">entry</var> be the entry one earlier than
                   1843:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1844:    elements</a>.</li>
                   1845: 
                   1846:    <li>If <var title="">entry</var> is neither a marker nor an element
                   1847:    that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
                   1848:    4.</li>
                   1849: 
                   1850:    <li>Let <var title="">entry</var> be the element one later than
                   1851:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1852:    elements</a>.</li>
                   1853: 
                   1854:    <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   1855:    element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
                   1856: 
                   1857:    <li>Append <var title="">new element</var> to the <a href="#current-node">current
                   1858:    node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
                   1859:    elements</a> so that it is the new <a href="#current-node">current
                   1860:    node</a>.</li>
                   1861: 
                   1862:    <li>Replace the entry for <var title="">entry</var> in the list
                   1863:    with an entry for <var title="">new element</var>.</li>
                   1864: 
                   1865:    <li>If the entry for <var title="">new element</var> in the
                   1866:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
                   1867:    entry in the list, return to step 7.</li>
                   1868: 
                   1869:   </ol><p>This has the effect of reopening all the formatting elements that
                   1870:   were opened in the current body, cell, or caption (whichever is
                   1871:   youngest) that haven't been explicitly closed.</p>
                   1872: 
                   1873:   <p class="note">The way this specification is written, the
                   1874:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
                   1875:   elements in chronological order with the least recently added
                   1876:   element first and the most recently added element last (except for
                   1877:   while steps 8 to 11 of the above algorithm are being executed, of
                   1878:   course).</p>
                   1879: 
                   1880:   <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
                   1881:   active formatting elements up to the last marker</dfn>, the UA must
                   1882:   perform the following steps:</p>
                   1883: 
                   1884:   <ol><li>Let <var title="">entry</var> be the last (most recently added)
                   1885:    entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
                   1886: 
                   1887:    <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
                   1888:    formatting elements</a>.</li>
                   1889: 
                   1890:    <li>If <var title="">entry</var> was a marker, then stop the
                   1891:    algorithm at this point. The list has been cleared up to the last
                   1892:    marker.</li>
                   1893: 
                   1894:    <li>Go to step 1.</li>
                   1895: 
                   1896:   </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5>
                   1897: 
                   1898:   <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
                   1899:   pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
                   1900:   pointer</dfn> are both null.</p>
                   1901: 
1.159     mike     1902:   <p>Once a <code><a href="semantics.html#the-head-element-0">head</a></code> element has been parsed (whether
1.1       mike     1903:   implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
                   1904:   element pointer</a> gets set to point to this node.</p>
                   1905: 
                   1906:   <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   1907:   points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
                   1908:   whose end tag has not yet been seen. It is used to make form
                   1909:   controls associate with forms in the face of dramatically bad
                   1910:   markup, for historical reasons.</p>
                   1911: 
                   1912: 
                   1913:   <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5>
                   1914: 
                   1915:   <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
                   1916:   <code>Document</code> with which the parser is associated when the
                   1917:   parser was created, and "disabled" otherwise.</p>
                   1918: 
                   1919:   <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
                   1920:   when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
                   1921:   parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
                   1922:   don't execute in that case.</p>
                   1923: 
                   1924:   <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
                   1925:   created. It is set to "not ok" after certain tokens are seen.</p>
                   1926: 
1.266     mike     1927:   </div><div class="impl">
1.1       mike     1928: 
1.159     mike     1929:   <h4 id="tokenization"><span class="secno">9.2.4 </span><dfn>Tokenization</dfn></h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p>
1.1       mike     1930: 
                   1931:   <p>Implementations must act as if they used the following state
                   1932:   machine to tokenize HTML. The state machine must start in the
                   1933:   <a href="#data-state">data state</a>. Most states consume a single character,
                   1934:   which may have various side-effects, and either switches the state
                   1935:   machine to a new state to <em>reconsume</em> the same character, or
                   1936:   switches it to a new state (to consume the next character), or
                   1937:   repeats the same state (to consume the next character). Some states
                   1938:   have more complicated behavior and can consume several characters
                   1939:   before switching to another state.</p>
                   1940: 
                   1941:   <p>The exact behavior of certain states depends on a <dfn id="content-model-flag">content
                   1942:   model flag</dfn> that is set after certain tokens are emitted. The
1.91      mike     1943:   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
                   1944:   state. In the RCDATA and RAWTEXT states, a further <dfn id="escape-flag">escape
1.1       mike     1945:   flag</dfn> is used to control the behavior of the tokenizer. It is
                   1946:   either true or false, and initially must be set to the false
                   1947:   state. The <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
                   1948:   elements</a> also affects tokenization.</p>
                   1949: 
                   1950:   <p>The output of the tokenization step is a series of zero or more
                   1951:   of the following tokens: DOCTYPE, start tag, end tag, comment,
                   1952:   character, end-of-file. DOCTYPE tokens have a name, a public
                   1953:   identifier, a system identifier, and a <i>force-quirks
                   1954:   flag</i>. When a DOCTYPE token is created, its name, public
                   1955:   identifier, and system identifier must be marked as missing (which
                   1956:   is a distinct state from the empty string), and the <i>force-quirks
                   1957:   flag</i> must be set to <i>off</i> (its other state is
                   1958:   <i>on</i>). Start and end tag tokens have a tag name, a
                   1959:   <i>self-closing flag</i>, and a list of attributes, each of which
                   1960:   has a name and a value. When a start or end tag token is created,
                   1961:   its <i>self-closing flag</i> must be unset (its other state is that
                   1962:   it be set), and its attributes list must be empty. Comment and
                   1963:   character tokens have data.</p>
                   1964: 
                   1965:   <p>When a token is emitted, it must immediately be handled by the
                   1966:   <a href="#tree-construction">tree construction</a> stage. The tree construction stage
                   1967:   can affect the state of the <a href="#content-model-flag">content model flag</a>, and can
                   1968:   insert additional characters into the stream. (For example, the
                   1969:   <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
1.159     mike     1970:   using the <a href="embedded-content-0.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
1.1       mike     1971:   characters into the stream being tokenized.)</p>
                   1972: 
                   1973:   <p>When a start tag token is emitted with its <i>self-closing
                   1974:   flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
                   1975:   self-closing flag">acknowledged</dfn> when it is processed by the
                   1976:   tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
                   1977: 
                   1978:   <p>When an end tag token is emitted, the <a href="#content-model-flag">content model
                   1979:   flag</a> must be switched to the PCDATA state.</p>
                   1980: 
                   1981:   <p>When an end tag token is emitted with attributes, that is a
                   1982:   <a href="#parse-error">parse error</a>.</p>
                   1983: 
                   1984:   <p>When an end tag token is emitted with its <i>self-closing
                   1985:   flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
                   1986: 
                   1987:   <p>Before each step of the tokenizer, the user agent must first
                   1988:   check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
                   1989:   tokenizer must abort the processing of any nested invocations of the
                   1990:   tokenizer, yielding control back to the caller. If it is false, then
                   1991:   the user agent may then check to see if either one of the scripts in
                   1992:   the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will execute as soon as
                   1993:   possible</a> or the first script in the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts
                   1994:   that will execute asynchronously</a>, has <a href="semantics.html#completed-loading">completed
                   1995:   loading</a>. If one has, then it must be <a href="semantics.html#executing-a-script-block" title="executing a
                   1996:   script block">executed</a> and removed from its list.</p>
                   1997: 
                   1998:   <p>The tokenizer state machine consists of the states defined in the
                   1999:   following subsections.</p>
                   2000: 
                   2001:   <!-- XXX should go through these reordering the entries so that
                   2002:   they're in some consistent order, like, by Unicode, errors last, or
                   2003:   something -->
                   2004: 
                   2005:   <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5>
                   2006: 
                   2007:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2008: 
                   2009:   <dl class="switch"><dt>U+0026 AMPERSAND (&amp;)</dt>
                   2010:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to one of the
                   2011:    PCDATA or RCDATA states and the <a href="#escape-flag">escape flag</a> is
                   2012:    false: switch to the <a href="#character-reference-data-state">character reference data
1.56      mike     2013:    state</a>.</dd>
                   2014:    <dd>Otherwise: treat it as per the "anything else" entry
                   2015:    below.</dd>
1.1       mike     2016: 
                   2017:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2018:    <dd>
                   2019: 
                   2020:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2021:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     2022:     is false, and there are at least three characters before this
                   2023:     one in the input stream, and the last four characters in the
                   2024:     input stream, including this one, are U+003C LESS-THAN SIGN,
                   2025:     U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, and U+002D
                   2026:     HYPHEN-MINUS ("&lt;!--"), then set the <a href="#escape-flag">escape flag</a>
                   2027:     to true.</p>
                   2028: 
                   2029:     <p>In any case, emit the input character as a character
                   2030:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   2031: 
                   2032:    </dd>
                   2033: 
                   2034:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2035:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   2036:    state: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   2037:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2038:    RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     2039:    is false: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   2040:    <dd>Otherwise: treat it as per the "anything else" entry
                   2041:    below.</dd>
                   2042: 
                   2043:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2044:    <dd>
                   2045: 
                   2046:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2047:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape
1.1       mike     2048:     flag</a> is true, and the last three characters in the input
                   2049:     stream including this one are U+002D HYPHEN-MINUS, U+002D
                   2050:     HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("--&gt;"), set the
                   2051:     <a href="#escape-flag">escape flag</a> to false.</p> <!-- no need to check
                   2052:     that there are enough characters, since you can only run into
                   2053:     this if the flag is true in the first place, which requires four
                   2054:     characters. -->
                   2055: 
                   2056:     <p>In any case, emit the input character as a character
                   2057:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   2058: 
                   2059:    </dd>
                   2060: 
                   2061:    <dt>EOF</dt>
                   2062:    <dd>Emit an end-of-file token.</dd>
                   2063: 
                   2064:    <dt>Anything else</dt>
                   2065:    <dd>Emit the input character as a character token. Stay in the
                   2066:    <a href="#data-state">data state</a>.</dd>
                   2067: 
                   2068:   </dl><h5 id="character-reference-data-state"><span class="secno">9.2.4.2 </span><dfn>Character reference data state</dfn></h5>
                   2069: 
                   2070:   <p><i>(This cannot happen if the <a href="#content-model-flag">content model flag</a>
1.91      mike     2071:   is set to the RAWTEXT state.)</i></p>
1.1       mike     2072: 
                   2073:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
                   2074:   <a href="#additional-allowed-character">additional allowed character</a>.</p>
                   2075: 
                   2076:   <p>If nothing is returned, emit a U+0026 AMPERSAND character
                   2077:   token.</p>
                   2078: 
                   2079:   <p>Otherwise, emit the character token that was returned.</p>
                   2080: 
                   2081:   <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
                   2082: 
                   2083: 
                   2084:   <h5 id="tag-open-state"><span class="secno">9.2.4.3 </span><dfn>Tag open state</dfn></h5>
                   2085: 
                   2086:   <p>The behavior of this state depends on the <a href="#content-model-flag">content model
                   2087:   flag</a>.</p>
                   2088: 
                   2089:   <dl><dt>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA
1.91      mike     2090:    or RAWTEXT states</dt>
1.1       mike     2091: 
                   2092:    <dd>
                   2093: 
                   2094:     <p>Consume the <a href="#next-input-character">next input character</a>. If it is a
                   2095:     U+002F SOLIDUS (/) character, switch to the <a href="#close-tag-open-state">close tag open
                   2096:     state</a>. Otherwise, emit a U+003C LESS-THAN SIGN character
                   2097:     token and reconsume the <a href="#current-input-character">current input character</a> in the
                   2098:     <a href="#data-state">data state</a>.</p>
                   2099: 
                   2100:    </dd>
                   2101: 
                   2102:    <dt>If the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   2103:    state</dt>
                   2104: 
                   2105:    <dd>
                   2106: 
                   2107:     <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2108: 
                   2109:     <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2110:      <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
                   2111: 
                   2112:      <dt>U+002F SOLIDUS (/)</dt>
                   2113:      <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
                   2114: 
                   2115:      <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2116:      <dd>Create a new start tag token, set its tag name to the
                   2117:      lowercase version of the input character (add 0x0020 to the
                   2118:      character's code point), then switch to the <a href="#tag-name-state">tag name
                   2119:      state</a>. (Don't emit the token yet; further details will
                   2120:      be filled in before it is emitted.)</dd>
                   2121: 
                   2122:      <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2123:      <dd>Create a new start tag token, set its tag name to the input
                   2124:      character, then switch to the <a href="#tag-name-state">tag name
                   2125:      state</a>. (Don't emit the token yet; further details will
                   2126:      be filled in before it is emitted.)</dd>
                   2127: 
                   2128:      <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2129:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2130:      character token and a U+003E GREATER-THAN SIGN character
                   2131:      token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2132: 
                   2133:      <dt>U+003F QUESTION MARK (?)</dt>
                   2134:      <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2135:      comment state</a>.</dd>
                   2136: 
                   2137:      <dt>Anything else</dt>
                   2138:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2139:      character token and reconsume the <a href="#current-input-character">current input character</a> in the
                   2140:      <a href="#data-state">data state</a>.</dd>
                   2141: 
                   2142:     </dl></dd>
                   2143: 
                   2144:   </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.4 </span><dfn>Close tag open state</dfn></h5>
                   2145: 
                   2146:   <p>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA or
1.91      mike     2147:   RAWTEXT states but no start tag token has ever been emitted by this
1.1       mike     2148:   instance of the tokenizer (<a href="#fragment-case">fragment case</a>), or, if the
1.91      mike     2149:   <a href="#content-model-flag">content model flag</a> is set to the RCDATA or RAWTEXT states
1.1       mike     2150:   and the next few characters do not match the tag name of the last
                   2151:   start tag token emitted (compared in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2152:   case-insensitive</a> manner), or if they do but they are not
                   2153:   immediately followed by one of the following characters:</p>
                   2154: 
                   2155:   <ul class="brief"><li>U+0009 CHARACTER TABULATION</li>
                   2156:    <li>U+000A LINE FEED (LF)</li>
                   2157:    <li>U+000C FORM FEED (FF)</li>
                   2158:    <!--<li>U+000D CARRIAGE RETURN (CR)</li>-->
                   2159:    <li>U+0020 SPACE</li>
                   2160:    <li>U+003E GREATER-THAN SIGN (&gt;)</li>
                   2161:    <li>U+002F SOLIDUS (/)</li>
                   2162:    <li>EOF</li>
                   2163:   </ul><p>...then emit a U+003C LESS-THAN SIGN character token, a U+002F
                   2164:   SOLIDUS character token, and switch to the <a href="#data-state">data state</a>
                   2165:   to process the <a href="#next-input-character">next input character</a>.</p>
                   2166: 
                   2167:   <p>Otherwise, if the <a href="#content-model-flag">content model flag</a> is set to the
                   2168:   PCDATA state, or if the next few characters <em>do</em> match that tag
                   2169:   name, consume the <a href="#next-input-character">next input character</a>:</p>
                   2170: 
                   2171:   <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2172:    <dd>Create a new end tag token, set its tag name to the lowercase
                   2173:    version of the input character (add 0x0020 to the character's
                   2174:    code point), then switch to the <a href="#tag-name-state">tag name
                   2175:    state</a>. (Don't emit the token yet; further details will be
                   2176:    filled in before it is emitted.)</dd>
                   2177: 
                   2178:    <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2179:    <dd>Create a new end tag token, set its tag name to the input
                   2180:    character, then switch to the <a href="#tag-name-state">tag name state</a>. (Don't
                   2181:    emit the token yet; further details will be filled in before it
                   2182:    is emitted.)</dd>
                   2183: 
                   2184:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2185:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
                   2186:    state</a>.</dd>
                   2187: 
                   2188:    <dt>EOF</dt>
                   2189:    <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2190:    character token and a U+002F SOLIDUS character token. Reconsume
                   2191:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2192: 
                   2193:    <dt>Anything else</dt>
                   2194:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2195:    comment state</a>.</dd>
                   2196: 
                   2197:   </dl><h5 id="tag-name-state"><span class="secno">9.2.4.5 </span><dfn>Tag name state</dfn></h5>
                   2198: 
                   2199:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2200: 
                   2201:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2202:    <dt>U+000A LINE FEED (LF)</dt>
                   2203:    <dt>U+000C FORM FEED (FF)</dt>
                   2204:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2205:    <dt>U+0020 SPACE</dt>
                   2206:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2207: 
                   2208:    <dt>U+002F SOLIDUS (/)</dt>
                   2209:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2210: 
                   2211:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2212:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2213:    state</a>.</dd>
                   2214: 
                   2215:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2216:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2217:    (add 0x0020 to the character's code point) to the current tag
                   2218:    token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2219: 
                   2220:    <dt>EOF</dt>
                   2221:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2222:    <a href="#data-state">data state</a>.</dd>
                   2223: 
                   2224:    <dt>Anything else</dt>
                   2225:    <dd>Append the <a href="#current-input-character">current input character</a> to the current tag token's
                   2226:    tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2227: 
                   2228:   </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.6 </span><dfn>Before attribute name state</dfn></h5>
                   2229: 
                   2230:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2231: 
                   2232:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2233:    <dt>U+000A LINE FEED (LF)</dt>
                   2234:    <dt>U+000C FORM FEED (FF)</dt>
                   2235:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2236:    <dt>U+0020 SPACE</dt>
                   2237:    <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2238: 
                   2239:    <dt>U+002F SOLIDUS (/)</dt>
                   2240:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2241: 
                   2242:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2243:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2244:    state</a>.</dd>
                   2245: 
                   2246:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2247:    <dd>Start a new attribute in the current tag token. Set that
                   2248:    attribute's name to the lowercase version of the <a href="#current-input-character">current input
                   2249:    character</a> (add 0x0020 to the character's code point), and its
                   2250:    value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2251:    state</a>.</dd>
                   2252: 
                   2253:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2254:    <dt>U+0027 APOSTROPHE (')</dt>
                   2255:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2256:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2257:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2258:    entry below.</dd>
                   2259: 
                   2260:    <dt>EOF</dt>
                   2261:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2262:    <a href="#data-state">data state</a>.</dd>
                   2263: 
                   2264:    <dt>Anything else</dt>
                   2265:    <dd>Start a new attribute in the current tag token. Set that
                   2266:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2267:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2268:    state</a>.</dd>
                   2269: 
                   2270:   </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.7 </span><dfn>Attribute name state</dfn></h5>
                   2271: 
                   2272:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2273: 
                   2274:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2275:    <dt>U+000A LINE FEED (LF)</dt>
                   2276:    <dt>U+000C FORM FEED (FF)</dt>
                   2277:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2278:    <dt>U+0020 SPACE</dt>
                   2279:    <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2280: 
                   2281:    <dt>U+002F SOLIDUS (/)</dt>
                   2282:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2283: 
                   2284:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2285:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2286: 
                   2287:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2288:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2289:    state</a>.</dd>
                   2290: 
                   2291:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2292:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2293:    (add 0x0020 to the character's code point) to the current
                   2294:    attribute's name. Stay in the <a href="#attribute-name-state">attribute name
                   2295:    state</a>.</dd>
                   2296: 
                   2297:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2298:    <dt>U+0027 APOSTROPHE (')</dt>
                   2299:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2300:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2301:    entry below.</dd>
                   2302: 
                   2303:    <dt>EOF</dt>
                   2304:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2305:    <a href="#data-state">data state</a>.</dd>
                   2306: 
                   2307:    <dt>Anything else</dt>
                   2308:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2309:    name. Stay in the <a href="#attribute-name-state">attribute name state</a>.</dd>
                   2310: 
                   2311:   </dl><p>When the user agent leaves the attribute name state (and before
                   2312:   emitting the tag token, if appropriate), the complete attribute's
                   2313:   name must be compared to the other attributes on the same token;
                   2314:   if there is already an attribute on the token with the exact same
                   2315:   name, then this is a <a href="#parse-error">parse error</a> and the new
                   2316:   attribute must be dropped, along with the value that gets
                   2317:   associated with it (if any).</p>
                   2318: 
                   2319: 
                   2320:   <h5 id="after-attribute-name-state"><span class="secno">9.2.4.8 </span><dfn>After attribute name state</dfn></h5>
                   2321: 
                   2322:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2323: 
                   2324:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2325:    <dt>U+000A LINE FEED (LF)</dt>
                   2326:    <dt>U+000C FORM FEED (FF)</dt>
                   2327:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2328:    <dt>U+0020 SPACE</dt>
                   2329:    <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2330: 
                   2331:    <dt>U+002F SOLIDUS (/)</dt>
                   2332:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2333: 
                   2334:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2335:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2336: 
                   2337:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2338:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2339:    state</a>.</dd>
                   2340: 
                   2341:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2342:    <dd>Start a new attribute in the current tag token. Set that
                   2343:    attribute's name to the lowercase version of the <a href="#current-input-character">current input character</a>
                   2344:    (add 0x0020 to the character's code point), and its value to
                   2345:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2346:    state</a>.</dd>
                   2347: 
                   2348:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2349:    <dt>U+0027 APOSTROPHE (')</dt>
                   2350:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2351:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2352:    entry below.</dd>
                   2353: 
                   2354:    <dt>EOF</dt>
                   2355:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2356:    <a href="#data-state">data state</a>.</dd>
                   2357: 
                   2358:    <dt>Anything else</dt>
                   2359:    <dd>Start a new attribute in the current tag token. Set that
                   2360:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2361:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2362:    state</a>.</dd>
                   2363: 
                   2364:   </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.9 </span><dfn>Before attribute value state</dfn></h5>
                   2365: 
                   2366:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2367: 
                   2368:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2369:    <dt>U+000A LINE FEED (LF)</dt>
                   2370:    <dt>U+000C FORM FEED (FF)</dt>
                   2371:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2372:    <dt>U+0020 SPACE</dt>
                   2373:    <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2374: 
                   2375:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2376:    <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
                   2377: 
                   2378:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2379:    <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
                   2380:    and reconsume this input character.</dd>
                   2381: 
                   2382:    <dt>U+0027 APOSTROPHE (')</dt>
                   2383:    <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
                   2384: 
                   2385:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2386:    <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
                   2387:    the <a href="#data-state">data state</a>.</dd>
                   2388: 
                   2389:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2390:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2391:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2392:    entry below.</dd>
                   2393: 
                   2394:    <dt>EOF</dt>
                   2395:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2396:    <a href="#data-state">data state</a>.</dd>
                   2397: 
                   2398:    <dt>Anything else</dt>
                   2399:    <dd>Append the <a href="#current-input-character">current input character</a> to the current
                   2400:    attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2401:    state</a>.</dd>
                   2402: 
                   2403:   </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.10 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
                   2404: 
                   2405:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2406: 
                   2407:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2408:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2409:    state</a>.</dd>
                   2410: 
                   2411:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2412:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2413:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2414:    being U+0022 QUOTATION MARK (").</dd>
                   2415: 
                   2416:    <dt>EOF</dt>
                   2417:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2418:    <a href="#data-state">data state</a>.</dd>
                   2419: 
                   2420:    <dt>Anything else</dt>
                   2421:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2422:    value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted)
                   2423:    state</a>.</dd>
                   2424: 
                   2425:   </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.11 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
                   2426: 
                   2427:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2428: 
                   2429:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   2430:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2431:    state</a>.</dd>
                   2432: 
                   2433:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2434:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2435:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2436:    being U+0027 APOSTROPHE (').</dd>
                   2437: 
                   2438:    <dt>EOF</dt>
                   2439:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2440:    <a href="#data-state">data state</a>.</dd>
                   2441: 
                   2442:    <dt>Anything else</dt>
                   2443:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2444:    value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted)
                   2445:    state</a>.</dd>
                   2446: 
                   2447:   </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.12 </span><dfn>Attribute value (unquoted) state</dfn></h5>
                   2448: 
                   2449:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2450: 
                   2451:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2452:    <dt>U+000A LINE FEED (LF)</dt>
                   2453:    <dt>U+000C FORM FEED (FF)</dt>
                   2454:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2455:    <dt>U+0020 SPACE</dt>
                   2456:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2457: 
                   2458:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2459:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2460:    state</a>, with no <a href="#additional-allowed-character">additional allowed
                   2461:    character</a>.</dd>
                   2462: 
                   2463:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2464:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2465:    state</a>.</dd>
                   2466: 
                   2467:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2468:    <dt>U+0027 APOSTROPHE (')</dt>
                   2469:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2470:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2471:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2472:    entry below.</dd>
                   2473: 
                   2474:    <dt>EOF</dt>
                   2475:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2476:    <a href="#data-state">data state</a>.</dd>
                   2477: 
                   2478:    <dt>Anything else</dt>
                   2479:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2480:    value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2481:    state</a>.</dd>
                   2482: 
                   2483:   </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>
                   2484: 
                   2485:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
                   2486: 
                   2487:   <p>If nothing is returned, append a U+0026 AMPERSAND character to
                   2488:   the current attribute's value.</p>
                   2489: 
                   2490:   <p>Otherwise, append the returned character token to the current
                   2491:   attribute's value.</p>
                   2492: 
                   2493:   <p>Finally, switch back to the attribute value state that you were
                   2494:   in when were switched into this state.</p>
                   2495: 
                   2496: 
                   2497:   <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.14 </span><dfn>After attribute value (quoted) state</dfn></h5>
                   2498: 
                   2499:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2500: 
                   2501:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2502:    <dt>U+000A LINE FEED (LF)</dt>
                   2503:    <dt>U+000C FORM FEED (FF)</dt>
                   2504:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2505:    <dt>U+0020 SPACE</dt>
                   2506:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2507: 
                   2508:    <dt>U+002F SOLIDUS (/)</dt>
                   2509:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2510: 
                   2511:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2512:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2513:    state</a>.</dd>
                   2514: 
                   2515:    <dt>EOF</dt>
                   2516:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2517:    <a href="#data-state">data state</a>.</dd>
                   2518: 
                   2519:    <dt>Anything else</dt>
                   2520:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2521:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2522: 
                   2523:   </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.15 </span><dfn>Self-closing start tag state</dfn></h5>
                   2524: 
                   2525:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2526: 
                   2527:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2528:    <dd>Set the <i>self-closing flag</i> of the current tag
                   2529:    token. Emit the current tag token. Switch to the <a href="#data-state">data
                   2530:    state</a>.</dd>
                   2531: 
                   2532:    <dt>EOF</dt>
                   2533:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2534:    <a href="#data-state">data state</a>.</dd>
                   2535: 
                   2536:    <dt>Anything else</dt>
                   2537:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2538:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2539: 
                   2540:   </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.16 </span><dfn>Bogus comment state</dfn></h5>
                   2541: 
                   2542:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2543:   flag</a> is set to the PCDATA state.)</i></p>
                   2544: 
                   2545:   <p>Consume every character up to and including the first U+003E
                   2546:   GREATER-THAN SIGN character (&gt;) or the end of the file (EOF),
                   2547:   whichever comes first. Emit a comment token whose data is the
                   2548:   concatenation of all the characters starting from and including
                   2549:   the character that caused the state machine to switch into the
                   2550:   bogus comment state, up to and including the character immediately
                   2551:   before the last consumed character (i.e. up to the character just
                   2552:   before the U+003E or EOF character). (If the comment was started
                   2553:   by the end of the file (EOF), the token is empty.)</p>
                   2554: 
                   2555:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   2556: 
                   2557:   <p>If the end of the file was reached, reconsume the EOF
                   2558:   character.</p>
                   2559: 
                   2560: 
                   2561:   <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.17 </span><dfn>Markup declaration open state</dfn></h5>
                   2562: 
                   2563:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2564:   flag</a> is set to the PCDATA state.)</i></p>
                   2565: 
                   2566:   <p>If the next two characters are both U+002D HYPHEN-MINUS (-)
                   2567:   characters, consume those two characters, create a comment token
                   2568:   whose data is the empty string, and switch to the <a href="#comment-start-state">comment
                   2569:   start state</a>.</p>
                   2570: 
                   2571:   <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2572:   case-insensitive</a> match for the word "DOCTYPE", then consume
                   2573:   those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
                   2574: 
                   2575:   <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
                   2576:   content</a>" and the <a href="#current-node">current node</a> is not an element
                   2577:   in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
                   2578:   an <span>ASCII case-sensitive</span> match for the string "[CDATA["
                   2579:   (the five uppercase letters "CDATA" with a U+005B LEFT SQUARE
                   2580:   BRACKET character before and after), then consume those characters
1.91      mike     2581:   and switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1       mike     2582: 
                   2583:   <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
                   2584:   <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
                   2585:   consumed, if any, is the first character that will be in the
                   2586:   comment.</p>
                   2587: 
                   2588: 
                   2589:   <h5 id="comment-start-state"><span class="secno">9.2.4.18 </span><dfn>Comment start state</dfn></h5>
                   2590: 
                   2591:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2592: 
                   2593:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2594:    <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
                   2595: 
                   2596:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2597:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
                   2598:    <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
                   2599:    -->
                   2600: 
                   2601:    <dt>EOF</dt>
                   2602:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2603:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2604: 
                   2605:    <dt>Anything else</dt>
                   2606:    <dd>Append the input character to the comment token's
                   2607:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2608: 
                   2609:   </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.19 </span><dfn>Comment start dash state</dfn></h5>
                   2610: 
                   2611:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2612: 
                   2613:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2614:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2615: 
                   2616:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2617:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
                   2618:    the <a href="#data-state">data state</a>.</dd>
                   2619: 
                   2620:    <dt>EOF</dt>
                   2621:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2622:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2623:    in comment end state -->
                   2624: 
                   2625:    <dt>Anything else</dt>
                   2626:    <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
                   2627:    character to the comment token's data. Switch to the
                   2628:    <a href="#comment-state">comment state</a>.</dd>
                   2629: 
                   2630:   </dl><h5 id="comment-state"><span class="secno">9.2.4.20 </span><dfn id="comment">Comment state</dfn></h5>
                   2631: 
                   2632:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2633: 
                   2634:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2635:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
                   2636: 
                   2637:    <dt>EOF</dt>
                   2638:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2639:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2640:    in comment end state -->
                   2641: 
                   2642:    <dt>Anything else</dt>
                   2643:    <dd>Append the input character to the comment token's data. Stay
                   2644:    in the <a href="#comment-state">comment state</a>.</dd>
                   2645: 
                   2646:   </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.21 </span><dfn>Comment end dash state</dfn></h5>
                   2647: 
                   2648:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2649: 
                   2650:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2651:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2652: 
                   2653:    <dt>EOF</dt>
                   2654:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2655:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2656:    in comment end state -->
                   2657: 
                   2658:    <dt>Anything else</dt>
                   2659:    <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
                   2660:    character to the comment token's data. Switch to the
                   2661:    <a href="#comment-state">comment state</a>.</dd>
                   2662: 
                   2663:   </dl><h5 id="comment-end-state"><span class="secno">9.2.4.22 </span><dfn>Comment end state</dfn></h5>
                   2664: 
                   2665:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2666: 
                   2667:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2668:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2669:    state</a>.</dd>
                   2670: 
                   2671:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2672:    <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
                   2673:    (-) character to the comment token's data. Stay in the
                   2674:    <a href="#comment-end-state">comment end state</a>.</dd>
                   2675: 
                   2676:    <dt>U+0009 CHARACTER TABULATION</dt>
                   2677:    <dt>U+000A LINE FEED (LF)</dt>
                   2678:    <dt>U+000C FORM FEED (FF)</dt>
                   2679:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2680:    <dt>U+0020 SPACE</dt>
                   2681:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2682:    characters and the input character to the comment token's
                   2683:    data. Switch to the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2684: 
                   2685:    <dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2686:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
                   2687:    state</a>.</dd>
                   2688: 
                   2689:    <dt>EOF</dt>
                   2690:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2691:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
                   2692:    security reasons: otherwise, hostile user could put a <script> in
                   2693:    a comment e.g. in a blog comment and then DOS the server so that
                   2694:    the end tag isn't read, and then the commented <script> tag would
                   2695:    be treated as live code -->
                   2696: 
                   2697:    <dt>Anything else</dt>
                   2698:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2699:    characters and the input character to the comment token's
                   2700:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2701: 
                   2702:   </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.23 </span><dfn>Comment end bang state</dfn></h5>
                   2703: 
                   2704:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2705: 
                   2706:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2707:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2708:    state</a>.</dd>
                   2709: 
                   2710:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2711:    <dd>Append two U+002D HYPHEN-MINUS (-) characters and a U+0021
                   2712:    EXCLAMATION MARK (!) character to the comment token's data. Switch
                   2713:    to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2714: 
                   2715:    <dt>EOF</dt>
                   2716:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2717:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2718:    comment in comment end state -->
                   2719: 
                   2720:    <dt>Anything else</dt>
                   2721:    <dd>Append two U+002D HYPHEN-MINUS (-) characters, a U+0021
                   2722:    EXCLAMATION MARK (!) character, and the input character to the
                   2723:    comment token's data. Switch to the <a href="#comment-state">comment
                   2724:    state</a>.</dd>
                   2725: 
                   2726:   </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.24 </span><dfn>Comment end space state</dfn></h5>
                   2727: 
                   2728:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2729: 
                   2730:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2731:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2732:    state</a>.</dd>
                   2733: 
                   2734:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2735:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2736: 
                   2737:    <dt>U+0009 CHARACTER TABULATION</dt>
                   2738:    <dt>U+000A LINE FEED (LF)</dt>
                   2739:    <dt>U+000C FORM FEED (FF)</dt>
                   2740:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2741:    <dt>U+0020 SPACE</dt>
                   2742:    <dd>Append the input character to the comment token's data. Stay in
                   2743:    the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2744: 
                   2745:    <dt>EOF</dt>
                   2746:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2747:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2748:    comment in comment end state -->
                   2749: 
                   2750:    <dt>Anything else</dt>
                   2751:    <dd>Append the input character to the comment token's data. Switch
                   2752:    to the <a href="#comment-state">comment state</a>.</dd>
                   2753: 
                   2754:   </dl><h5 id="doctype-state"><span class="secno">9.2.4.25 </span><dfn>DOCTYPE state</dfn></h5>
                   2755: 
                   2756:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2757: 
                   2758:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2759:    <dt>U+000A LINE FEED (LF)</dt>
                   2760:    <dt>U+000C FORM FEED (FF)</dt>
                   2761:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2762:    <dt>U+0020 SPACE</dt>
                   2763:    <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2764: 
                   2765:    <dt>EOF</dt>
                   2766:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2767:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2768:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2769: 
                   2770:    <dt>Anything else</dt>
                   2771:    <dd><a href="#parse-error">Parse error</a>. Reconsume the current
                   2772:    character in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2773: 
                   2774:   </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.26 </span><dfn>Before DOCTYPE name state</dfn></h5>
                   2775: 
                   2776:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2777: 
                   2778:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2779:    <dt>U+000A LINE FEED (LF)</dt>
                   2780:    <dt>U+000C FORM FEED (FF)</dt>
                   2781:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2782:    <dt>U+0020 SPACE</dt>
                   2783:    <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2784: 
                   2785:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2786:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2787:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
                   2788:    the <a href="#data-state">data state</a>.</dd>
                   2789: 
                   2790:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2791:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2792:    lowercase version of the input character (add 0x0020 to the
                   2793:    character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2794:    state</a>.</dd>
                   2795: 
                   2796:    <dt>EOF</dt>
                   2797:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2798:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2799:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2800: 
                   2801:    <dt>Anything else</dt>
                   2802:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2803:    <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2804:    state</a>.</dd>
                   2805: 
                   2806:   </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.27 </span><dfn>DOCTYPE name state</dfn></h5>
                   2807: 
                   2808:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2809: 
                   2810:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2811:    <dt>U+000A LINE FEED (LF)</dt>
                   2812:    <dt>U+000C FORM FEED (FF)</dt>
                   2813:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2814:    <dt>U+0020 SPACE</dt>
                   2815:    <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   2816: 
                   2817:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2818:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2819:    state</a>.</dd>
                   2820: 
                   2821:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2822:    <dd>Append the lowercase version of the input character (add 0x0020
                   2823:    to the character's code point) to the current DOCTYPE token's
                   2824:    name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   2825: 
                   2826:    <dt>EOF</dt>
                   2827:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2828:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2829:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2830: 
                   2831:    <dt>Anything else</dt>
                   2832:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2833:    token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   2834: 
                   2835:   </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.28 </span><dfn>After DOCTYPE name state</dfn></h5>
                   2836: 
                   2837:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2838: 
                   2839:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2840:    <dt>U+000A LINE FEED (LF)</dt>
                   2841:    <dt>U+000C FORM FEED (FF)</dt>
                   2842:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2843:    <dt>U+0020 SPACE</dt>
                   2844:    <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   2845: 
                   2846:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2847:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2848:    state</a>.</dd>
                   2849: 
                   2850:    <dt>EOF</dt>
                   2851:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2852:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2853:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2854: 
                   2855:    <dt>Anything else</dt>
                   2856:    <dd>
                   2857: 
                   2858:     <p>If the six characters starting from the <a href="#current-input-character">current input
                   2859:     character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
                   2860:     for the word "PUBLIC", then consume those characters and switch to
                   2861:     the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</p>
                   2862: 
                   2863:     <p>Otherwise, if the six characters starting from the
                   2864:     <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2865:     case-insensitive</a> match for the word "SYSTEM", then consume
                   2866:     those characters and switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system
                   2867:     identifier state</a>.</p>
                   2868: 
                   2869:     <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
                   2870:     DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
                   2871:     the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
                   2872: 
                   2873:    </dd>
                   2874: 
                   2875:   </dl><h5 id="before-doctype-public-identifier-state"><span class="secno">9.2.4.29 </span><dfn>Before DOCTYPE public identifier state</dfn></h5>
                   2876: 
                   2877:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2878: 
                   2879:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2880:    <dt>U+000A LINE FEED (LF)</dt>
                   2881:    <dt>U+000C FORM FEED (FF)</dt>
                   2882:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2883:    <dt>U+0020 SPACE</dt>
                   2884:    <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
                   2885: 
                   2886:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2887:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   2888:    (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
                   2889:    (double-quoted) state</a>.</dd>
                   2890: 
                   2891:    <dt>U+0027 APOSTROPHE (')</dt>
                   2892:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   2893:    (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
                   2894:    (single-quoted) state</a>.</dd>
                   2895: 
                   2896:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2897:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2898:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2899:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2900: 
                   2901:    <dt>EOF</dt>
                   2902:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2903:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2904:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2905: 
                   2906:    <dt>Anything else</dt>
                   2907:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2908:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   2909:    DOCTYPE state</a>.</dd>
                   2910: 
                   2911:   </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>
                   2912: 
                   2913:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2914: 
                   2915:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2916:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   2917: 
                   2918:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2919:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2920:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2921:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2922: 
                   2923:    <dt>EOF</dt>
                   2924:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2925:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2926:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2927: 
                   2928:    <dt>Anything else</dt>
                   2929:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2930:    token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
                   2931:    identifier (double-quoted) state</a>.</dd>
                   2932: 
                   2933:   </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>
                   2934: 
                   2935:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2936: 
                   2937:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   2938:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   2939: 
                   2940:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2941:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2942:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2943:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2944: 
                   2945:    <dt>EOF</dt>
                   2946:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2947:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2948:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2949: 
                   2950:    <dt>Anything else</dt>
                   2951:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2952:    token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
                   2953:    identifier (single-quoted) state</a>.</dd>
                   2954: 
                   2955:   </dl><h5 id="after-doctype-public-identifier-state"><span class="secno">9.2.4.32 </span><dfn>After DOCTYPE public identifier state</dfn></h5>
                   2956: 
                   2957:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2958: 
                   2959:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2960:    <dt>U+000A LINE FEED (LF)</dt>
                   2961:    <dt>U+000C FORM FEED (FF)</dt>
                   2962:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2963:    <dt>U+0020 SPACE</dt>
                   2964:    <dd>Stay in the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   2965: 
                   2966:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2967:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   2968:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   2969:    (double-quoted) state</a>.</dd>
                   2970: 
                   2971:    <dt>U+0027 APOSTROPHE (')</dt>
                   2972:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   2973:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   2974:    (single-quoted) state</a>.</dd>
                   2975: 
                   2976:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2977:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2978:    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="before-doctype-system-identifier-state"><span class="secno">9.2.4.33 </span><dfn>Before DOCTYPE system identifier 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+0009 CHARACTER TABULATION</dt>
                   2995:    <dt>U+000A LINE FEED (LF)</dt>
                   2996:    <dt>U+000C FORM FEED (FF)</dt>
                   2997:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2998:    <dt>U+0020 SPACE</dt>
                   2999:    <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
                   3000: 
                   3001:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3002:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3003:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   3004:    (double-quoted) state</a>.</dd>
                   3005: 
                   3006:    <dt>U+0027 APOSTROPHE (')</dt>
                   3007:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3008:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   3009:    (single-quoted) state</a>.</dd>
                   3010: 
                   3011:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3012:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3013:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3014:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3015: 
                   3016:    <dt>EOF</dt>
                   3017:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3018:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3019:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3020: 
                   3021:    <dt>Anything else</dt>
                   3022:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3023:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3024:    DOCTYPE state</a>.</dd>
                   3025: 
                   3026:   </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>
                   3027: 
                   3028:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3029: 
                   3030:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   3031:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3032: 
                   3033:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3034:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3035:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3036:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3037: 
                   3038:    <dt>EOF</dt>
                   3039:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3040:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3041:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3042: 
                   3043:    <dt>Anything else</dt>
                   3044:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3045:    token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
                   3046:    identifier (double-quoted) state</a>.</dd>
                   3047: 
                   3048:   </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>
                   3049: 
                   3050:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3051: 
                   3052:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   3053:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3054: 
                   3055:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3056:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3057:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3058:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3059: 
                   3060:    <dt>EOF</dt>
                   3061:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3062:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3063:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3064: 
                   3065:    <dt>Anything else</dt>
                   3066:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3067:    token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
                   3068:    identifier (single-quoted) state</a>.</dd>
                   3069: 
                   3070:   </dl><h5 id="after-doctype-system-identifier-state"><span class="secno">9.2.4.36 </span><dfn>After DOCTYPE system identifier state</dfn></h5>
                   3071: 
                   3072:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3073: 
                   3074:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3075:    <dt>U+000A LINE FEED (LF)</dt>
                   3076:    <dt>U+000C FORM FEED (FF)</dt>
                   3077:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3078:    <dt>U+0020 SPACE</dt>
                   3079:    <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3080: 
                   3081:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3082:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3083:    state</a>.</dd>
                   3084: 
                   3085:    <dt>EOF</dt>
                   3086:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3087:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3088:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3089: 
                   3090:    <dt>Anything else</dt>
                   3091:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
                   3092:    state</a>. (This does <em>not</em> set the DOCTYPE token's
                   3093:    <i>force-quirks flag</i> to <i>on</i>.)</dd>
                   3094: 
                   3095:   </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.37 </span><dfn>Bogus DOCTYPE state</dfn></h5>
                   3096: 
                   3097:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3098: 
                   3099:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3100:    <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
                   3101:    state</a>.</dd>
                   3102: 
                   3103:    <dt>EOF</dt>
                   3104:    <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
                   3105:    <a href="#data-state">data state</a>.</dd>
                   3106: 
                   3107:    <dt>Anything else</dt>
                   3108:    <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
                   3109: 
                   3110:   </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.38 </span><dfn>CDATA section state</dfn></h5>
                   3111: 
                   3112:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
1.91      mike     3113:   flag</a> is set to the PCDATA state.)</i></p>
1.1       mike     3114: 
                   3115:   <p>Consume every character up to the next occurrence of the three
                   3116:   character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
                   3117:   BRACKET U+003E GREATER-THAN SIGN (<code title="">]]&gt;</code>), or the
                   3118:   end of the file (EOF), whichever comes first. Emit a series of
                   3119:   character tokens consisting of all the characters consumed except
                   3120:   the matching three character sequence at the end (if one was found
                   3121:   before the end of the file).</p>
                   3122: 
                   3123:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   3124: 
                   3125:   <p>If the end of the file was reached, reconsume the EOF
                   3126:   character.</p>
                   3127: 
                   3128: 
                   3129: 
                   3130:   <h5 id="tokenizing-character-references"><span class="secno">9.2.4.39 </span>Tokenizing character references</h5>
                   3131: 
                   3132:   <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
                   3133:   reference</dfn>. This definition is used when parsing character
                   3134:   references <a href="#character-reference-data-state" title="character reference data state">in
                   3135:   text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
                   3136:   state">in attributes</a>.</p>
                   3137: 
                   3138:   <p>The behavior depends on the identity of the next character (the
                   3139:   one immediately after the U+0026 AMPERSAND character):</p>
                   3140: 
                   3141:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3142:    <dt>U+000A LINE FEED (LF)</dt>
                   3143:    <dt>U+000C FORM FEED (FF)</dt>
                   3144:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3145:    <dt>U+0020 SPACE</dt>
                   3146:    <dt>U+003C LESS-THAN SIGN</dt>
                   3147:    <dt>U+0026 AMPERSAND</dt>
                   3148:    <dt>EOF</dt>
                   3149:    <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
                   3150: 
                   3151:    <dd>Not a character reference. No characters are consumed, and
                   3152:    nothing is returned. (This is not an error, either.)</dd>
                   3153: 
                   3154: 
                   3155:    <dt>U+0023 NUMBER SIGN (#)</dt>
                   3156: 
                   3157:    <dd>
                   3158: 
                   3159:     <p>Consume the U+0023 NUMBER SIGN.</p>
                   3160: 
                   3161:     <p>The behavior further depends on the character after the U+0023
                   3162:     NUMBER SIGN:</p>
                   3163: 
                   3164:     <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
                   3165:      <dt>U+0058 LATIN CAPITAL LETTER X</dt>
                   3166: 
                   3167:      <dd>
                   3168: 
                   3169:       <p>Consume the X.</p>
                   3170: 
                   3171:       <p>Follow the steps below, but using the range of characters
                   3172:       U+0030 DIGIT ZERO through to U+0039 DIGIT NINE, U+0061 LATIN
                   3173:       SMALL LETTER A through to U+0066 LATIN SMALL LETTER F, and
                   3174:       U+0041 LATIN CAPITAL LETTER A, through to U+0046 LATIN CAPITAL
                   3175:       LETTER F (in other words, 0-9, A-F, a-f).</p>
                   3176: 
                   3177:       <p>When it comes to interpreting the number, interpret it as a
                   3178:       hexadecimal number.</p>
                   3179: 
                   3180:      </dd>
                   3181: 
                   3182: 
                   3183:      <dt>Anything else</dt>
                   3184: 
                   3185:      <dd>
                   3186: 
                   3187:       <p>Follow the steps below, but using the range of characters
                   3188:       U+0030 DIGIT ZERO through to U+0039 DIGIT NINE (i.e. just
                   3189:       0-9).</p>
                   3190: 
                   3191:       <p>When it comes to interpreting the number, interpret it as a
                   3192:       decimal number.</p>
                   3193: 
                   3194:      </dd>
                   3195: 
                   3196:     </dl><p>Consume as many characters as match the range of characters
                   3197:     given above.</p>
                   3198: 
                   3199:     <p>If no characters match the range, then don't consume any
                   3200:     characters (and unconsume the U+0023 NUMBER SIGN character and, if
                   3201:     appropriate, the X character). This is a <a href="#parse-error">parse
                   3202:     error</a>; nothing is returned.</p>
                   3203: 
                   3204:     <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
                   3205:     that too. If it isn't, there is a <a href="#parse-error">parse
                   3206:     error</a>.</p>
                   3207: 
                   3208:     <p>If one or more characters match the range, then take them all
                   3209:     and interpret the string of characters as a number (either
                   3210:     hexadecimal or decimal as appropriate).</p>
                   3211: 
                   3212:     <p>If that number is one of the numbers in the first column of the
                   3213:     following table, then this is a <a href="#parse-error">parse error</a>. Find the
                   3214:     row with that number in the first column, and return a character
                   3215:     token for the Unicode character given in the second column of that
                   3216:     row.</p>
                   3217: 
                   3218:     <table><thead><tr><th>Number </th><th colspan="2">Unicode character
                   3219:      </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
                   3220:       </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
                   3221:       </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN ('&#8364;')
                   3222:       </td></tr><tr><td>0x81 </td><td>U+0081 </td><td>&lt;control&gt;
                   3223:       </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK ('&#8218;')
                   3224:       </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK ('&#402;')
                   3225:       </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK ('&#8222;')
                   3226:       </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS ('&#8230;')
                   3227:       </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER ('&#8224;')
                   3228:       </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER ('&#8225;')
                   3229:       </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT ('&#710;')
                   3230:       </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN ('&#8240;')
                   3231:       </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON ('&#352;')
                   3232:       </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK ('&#8249;')
                   3233:       </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE ('&#338;')
                   3234:       </td></tr><tr><td>0x8D </td><td>U+008D </td><td>&lt;control&gt;
                   3235:       </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON ('&#381;')
                   3236:       </td></tr><tr><td>0x8F </td><td>U+008F </td><td>&lt;control&gt;
                   3237:       </td></tr><tr><td>0x90 </td><td>U+0090 </td><td>&lt;control&gt;
                   3238:       </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK ('&#8216;')
                   3239:       </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK ('&#8217;')
                   3240:       </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK ('&#8220;')
                   3241:       </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK ('&#8221;')
                   3242:       </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET ('&#8226;')
                   3243:       </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH ('&#8211;')
                   3244:       </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH ('&#8212;')
                   3245:       </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE ('&#732;')
                   3246:       </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN ('&#8482;')
                   3247:       </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON ('&#353;')
                   3248:       </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK ('&#8250;')
                   3249:       </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE ('&#339;')
                   3250:       </td></tr><tr><td>0x9D </td><td>U+009D </td><td>&lt;control&gt;
                   3251:       </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON ('&#382;')
                   3252:       </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS ('&#376;')
1.18      mike     3253:     </td></tr></tbody></table><p>Otherwise, if the number is greater than 0x10FFFF, then this is
                   3254:     a <a href="#parse-error">parse error</a>. Return a U+FFFD REPLACEMENT
                   3255:     CHARACTER.</p>
                   3256: 
                   3257:     <p>Otherwise, return a character token for the Unicode character
1.1       mike     3258:     whose code point is that number.
                   3259: 
                   3260:     <!-- this is the same as the equivalent list in the input stream
                   3261:     section -->
                   3262:     If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
                   3263:     allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
                   3264:     allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
                   3265:     0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xD800 to
                   3266:     0xDFFF<!-- surrogates not allowed -->, 0xFDD0 to 0xFDEF, or is one
                   3267:     of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF,
                   3268:     0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF, 0x6FFFE,
                   3269:     0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE, 0x9FFFF,
                   3270:     0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE,
                   3271:     0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF, 0x10FFFE, or
1.18      mike     3272:     0x10FFFF, then this is a <a href="#parse-error">parse error</a>.</p>
1.1       mike     3273: 
                   3274:    </dd>
                   3275: 
                   3276: 
                   3277:    <dt>Anything else</dt>
                   3278: 
                   3279:    <dd>
                   3280: 
                   3281:     <p>Consume the maximum number of characters possible, with the
                   3282:     consumed characters matching one of the identifiers in the first
                   3283:     column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
                   3284:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
                   3285: 
                   3286:     <p>If no match can be made, then this is a <a href="#parse-error">parse
                   3287:     error</a>. No characters are consumed, and nothing is
                   3288:     returned.</p>
                   3289: 
                   3290:     <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>
                   3291: 
                   3292:     <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
                   3293:     attribute</a>, and the last character matched is not a U+003B
                   3294:     SEMICOLON (<code title="">;</code>), and the next character is in
                   3295:     the range U+0030 DIGIT ZERO to U+0039 DIGIT NINE, U+0041 LATIN
                   3296:     CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z, or U+0061 LATIN
                   3297:     SMALL LETTER A to U+007A LATIN SMALL LETTER Z, then, for
                   3298:     historical reasons, all the characters that were matched after the
                   3299:     U+0026 AMPERSAND (&amp;) must be unconsumed, and nothing is
                   3300:     returned.</p>
                   3301: 
                   3302:     <p>Otherwise, return a character token for the character
                   3303:     corresponding to the character reference name (as given by the
                   3304:     second column of the <a href="named-character-references.html#named-character-references">named character references</a>
                   3305:     table).</p>
                   3306: 
                   3307:     <div class="example">
                   3308: 
                   3309:      <p>If the markup contains <code title="">I'm &amp;notit; I tell
                   3310:      you</code>, the character reference is parsed as "not", as in,
                   3311:      <code title="">I'm &#172;it; I tell you</code>. But if the markup
                   3312:      was <code title="">I'm &amp;notin; I tell you</code>, the
                   3313:      character reference would be parsed as "notin;", resulting in
                   3314:      <code title="">I'm &#8713; I tell you</code>.</p>
                   3315: 
                   3316:     </div>
                   3317: 
                   3318:    </dd>
                   3319: 
1.266     mike     3320:   </dl></div><div class="impl">
                   3321: 
                   3322:   <h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4>
1.1       mike     3323: 
                   3324:   <p>The input to the tree construction stage is a sequence of tokens
                   3325:   from the <a href="#tokenization">tokenization</a> stage. The tree construction
                   3326:   stage is associated with a DOM <code>Document</code> object when a
                   3327:   parser is created. The "output" of this stage consists of
                   3328:   dynamically modifying or extending that document's DOM tree.</p>
                   3329: 
                   3330:   <p>This specification does not define when an interactive user agent
                   3331:   has to render the <code>Document</code> so that it is available to
                   3332:   the user, or when it has to begin accepting user input.</p>
                   3333: 
                   3334:   <p>As each token is emitted from the tokenizer, the user agent must
                   3335:   process the token according to the rules given in the section
                   3336:   corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
                   3337: 
                   3338:   <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
                   3339:   character</dfn> into a node, if that node has a child immediately
                   3340:   before where the character is to be inserted, and that child is a
                   3341:   <code>Text</code> node, and that <code>Text</code> node was the last
                   3342:   node that the parser inserted into the document, then the character
                   3343:   must be appended to that <code>Text</code> node; otherwise, a new
                   3344:   <code>Text</code> node whose data is just that character must be
                   3345:   inserted in the appropriate place.</p>
                   3346: 
                   3347:   <div class="example">
                   3348: 
                   3349:    <p>Here are some sample inputs to the parser and the corresponding
                   3350:    number of text nodes that they result in, assuming a user agent
                   3351:    that executes scripts.</p>
                   3352: 
                   3353:    <table><thead><tr><th>Input </th><th>Number of text nodes
                   3354:     </th></tr></thead><tbody><tr><td><pre>A&lt;script&gt;
                   3355: var&#160;script&#160;=&#160;document.getElementsByTagName('script')[0];
                   3356: document.body.removeChild(script);
                   3357: &lt;/script&gt;B</pre>
                   3358:       </td><td>Two adjacent text nodes in the document, containing "A" and "B".
                   3359:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3360: var&#160;text&#160;=&#160;document.createTextNode('B');
                   3361: document.body.appendChild(text);
                   3362: &lt;/script&gt;C</pre>
                   3363:       </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
                   3364:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3365: var&#160;text&#160;=&#160;document.getElementsByTagName('script')[0].firstChild;
                   3366: text.data&#160;=&#160;'B';
                   3367: document.body.appendChild(text);
                   3368: &lt;/script&gt;B</pre>
                   3369:       </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
                   3370:      </td></tr><tr><td><pre>A&lt;table&gt;B&lt;tr&gt;C&lt;/tr&gt;C&lt;/table&gt;</pre>
                   3371:       </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>.)
                   3372:      </td></tr><tr><td><pre>A&lt;table&gt;&lt;tr&gt;&#160;B&lt;/tr&gt;&#160;B&lt;/table&gt;</pre>
                   3373:       </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>.)
                   3374:      </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>
                   3375:       </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.)
                   3376:    </td></tr></tbody></table></div>
                   3377: 
                   3378:   <p id="mutation-during-parsing">DOM mutation events must not fire
                   3379:   for changes caused by the UA parsing the document. (Conceptually,
                   3380:   the parser is not mutating the DOM, it is constructing it.) This
1.159     mike     3381:   includes the parsing of any content inserted using <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code> and <code title="dom-document-writeln"><a href="embedded-content-0.html#dom-document-writeln">document.writeln()</a></code> calls. <a href="references.html#refsDOMEVENTS">[DOMEVENTS]</a></p>
1.1       mike     3382: 
                   3383:   <p class="note">Not all of the tag names mentioned below are
                   3384:   conformant tag names in this specification; many are included to
                   3385:   handle legacy content. They still form part of the algorithm that
                   3386:   implementations are required to implement to claim conformance.</p>
                   3387: 
                   3388:   <p class="note">The algorithm described below places no limit on the
                   3389:   depth of the DOM tree generated, or on the length of tag names,
                   3390:   attribute names, attribute values, text nodes, etc. While
                   3391:   implementors are encouraged to avoid arbitrary limits, it is
                   3392:   recognized that <a href="infrastructure.html#hardwareLimitations">practical
                   3393:   concerns</a> will likely force user agents to impose nesting
                   3394:   depths.</p>
                   3395: 
                   3396: 
                   3397:   <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5>
                   3398: 
                   3399:   <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
                   3400:   element for the token">create an element for a token</dfn> in a
                   3401:   particular namespace, the UA must create a node implementing the
                   3402:   interface appropriate for the element type corresponding to the tag
                   3403:   name of the token in the given namespace (as given in the
                   3404:   specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
                   3405:   element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
                   3406:   defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
                   3407:   the tag name being the name of that element, with the node being in
                   3408:   the given namespace, and with the attributes on the node being those
                   3409:   given in the given token.</p>
                   3410: 
                   3411:   <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
                   3412:   namespace</a> that is not defined in this specification is
1.44      mike     3413:   <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1       mike     3414:   interface is not defined by that namespace's specification must use
                   3415:   the interface <code>Element</code>.</p>
                   3416: 
                   3417:   <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
                   3418:   created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
                   3419:   invoked once the attributes are set. (This initializes the element's
                   3420:   <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
                   3421:   attributes.)</p>
                   3422: 
                   3423:   <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
                   3424:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3425:   for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
                   3426:   append this node to the <a href="#current-node">current node</a>, and push it onto
                   3427:   the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3428:   <a href="#current-node">current node</a>.</p>
                   3429: 
                   3430:   <p>The steps below may also require that the UA insert an HTML
                   3431:   element in a particular place, in which case the UA must follow the
                   3432:   same steps except that it must insert or append the new node in the
                   3433:   location specified instead of appending it to the <a href="#current-node">current
                   3434:   node</a>. (This happens in particular during the parsing of
                   3435:   tables with invalid content.)</p>
                   3436: 
                   3437:   <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
                   3438:   algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
                   3439:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
                   3440:   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
                   3441:   <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
                   3442:   created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
                   3443:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
                   3444:   inserting it wherever it is to be inserted.</p>
                   3445: 
                   3446:   <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
                   3447:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3448:   for the token</a> in the given namespace, and then append this
                   3449:   node to the <a href="#current-node">current node</a>, and push it onto the
                   3450:   <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3451:   <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>
                   3452:   whose value is not exactly the same as the element's namespace, that
                   3453:   is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
                   3454:   element has an <code title="">xmlns:xlink</code> attribute in the
                   3455:   <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
                   3456:   Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
                   3457: 
                   3458:   <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
                   3459:   attributes</dfn> for a token, then, if the token has an attribute
                   3460:   named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
                   3461: 
                   3462:   <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
                   3463:   attributes</dfn> for a token, then, for each attribute on the token
                   3464:   whose attribute name is one of the ones in the first column of the
                   3465:   following table, change the attribute's name to the name given in
                   3466:   the corresponding cell in the second column. (This fixes the case of
                   3467:   SVG attributes that are not all lowercase.)</p>
                   3468: 
                   3469:   <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
                   3470:    </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
                   3471:     </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
                   3472:     </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
                   3473:     </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
                   3474:     </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
                   3475:     </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
                   3476:     </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
                   3477:     </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
                   3478:     </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
                   3479:     </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
                   3480:     </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
                   3481:     </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
                   3482:     </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
                   3483:     </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   3484:     </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
                   3485:     </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
                   3486:     </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
                   3487:     </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
                   3488:     </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
                   3489:     </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
                   3490:     </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
                   3491:     </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
                   3492:     </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
                   3493:     </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
                   3494:     </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
                   3495:     </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
                   3496:     </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
                   3497:     </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
                   3498:     </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
                   3499:     </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
                   3500:     </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
                   3501:     </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
                   3502:     </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
                   3503:     </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
                   3504:     </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
                   3505:     </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
                   3506:     </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
                   3507:     </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
                   3508:     </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
                   3509:     </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
                   3510:     </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
                   3511:     </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
                   3512:     </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
                   3513:     </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
                   3514:     </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
                   3515:     </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
                   3516:     </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
                   3517:     </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
                   3518:     </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
                   3519:     </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
                   3520:     </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
                   3521:     </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
                   3522:     </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
                   3523:     </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
                   3524:     </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
                   3525:     </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
                   3526:     </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
                   3527:     </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
                   3528:     </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
                   3529:     </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
                   3530:     </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
                   3531:     </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
                   3532:   </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
                   3533:   foreign attributes</dfn> for a token, then, if any of the attributes
                   3534:   on the token match the strings given in the first column of the
                   3535:   following table, let the attribute be a namespaced attribute, with
                   3536:   the prefix being the string given in the corresponding cell in the
                   3537:   second column, the local name being the string given in the
                   3538:   corresponding cell in the third column, and the namespace being the
                   3539:   namespace given in the corresponding cell in the fourth
                   3540:   column. (This fixes the use of namespaced attributes, in particular
                   3541:   <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
                   3542:   the <span>XML namespace</span></a>.)</p>
                   3543: 
                   3544:   <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
                   3545:    </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>
                   3546:     </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>
                   3547:     </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>
                   3548:     </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>
                   3549:     </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>
                   3550:     </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>
                   3551:     </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>
                   3552:     </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 -->
                   3553:     </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>
                   3554:     </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>
                   3555:     </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>
                   3556:     </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     3557:   </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     3558:   <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
                   3559:   following steps. These algorithms are always invoked in response to
                   3560:   a start tag token.</p>
                   3561: 
                   3562:   <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
                   3563: 
1.91      mike     3564:    <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
                   3565:    text element parsing algorithm</a>, switch the tokenizer's
                   3566:    <a href="#content-model-flag">content model flag</a> to the RAWTEXT state; otherwise the
1.1       mike     3567:    algorithm invoked was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing
                   3568:    algorithm</a>, switch the tokenizer's <a href="#content-model-flag">content model
                   3569:    flag</a> to the RCDATA state.</p></li>
                   3570: 
                   3571:    <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   3572:    <a href="#insertion-mode">insertion mode</a>.</p>
                   3573: 
1.91      mike     3574:    </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
                   3575:    RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     3576: 
                   3577:   </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>
                   3578: 
                   3579:   <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
                   3580:   tags</dfn>, then, while the <a href="#current-node">current node</a> is a
                   3581:   <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
                   3582:   <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
                   3583:   <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
                   3584:   <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
                   3585:   pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   3586:   elements</a>.</p>
                   3587: 
                   3588:   <p>If a step requires the UA to generate implied end tags but lists
                   3589:   an element to exclude from the process, then the UA must perform the
                   3590:   above steps as if that element was not in the above list.</p>
                   3591: 
                   3592: 
                   3593:   <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5>
                   3594: 
                   3595:   <p>Foster parenting happens when content is misnested in tables.</p>
                   3596: 
                   3597:   <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
                   3598:   parent">foster parented</dfn>, the node <var title="">node</var>
                   3599:   must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3600: 
                   3601:   <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
                   3602:   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
                   3603:   elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
                   3604:   such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3605:   the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
                   3606:   case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
                   3607:   element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
1.159     mike     3608:   <code><a href="semantics.html#the-html-element-0">html</a></code> element). Otherwise, if there is a
1.1       mike     3609:   <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
                   3610:   elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3611:   <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
                   3612:   node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
                   3613:   the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3614:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   3615: 
                   3616:   <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
                   3617:   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
                   3618:   elements</a>, then <var title="">node</var> must be inserted
                   3619:   immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3620:   the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
                   3621:   element</a></i>; otherwise, <var title="">node</var> must be
                   3622:   <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3623: 
                   3624: 
                   3625: 
                   3626:   <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>
                   3627: 
                   3628:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
                   3629:   mode: initial">initial</a>", tokens must be handled as follows:</p>
                   3630: 
                   3631:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3632:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3633:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3634:    <dd>
                   3635:     <p>Ignore the token.</p>
                   3636:    </dd>
                   3637: 
                   3638:    <dt>A comment token</dt>
                   3639:    <dd>
                   3640:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   3641:     object with the <code title="">data</code> attribute set to the
                   3642:     data given in the comment token.</p>
                   3643:    </dd>
                   3644: 
                   3645:    <dt>A DOCTYPE token</dt>
                   3646:    <dd>
                   3647: 
                   3648:     <p>If the DOCTYPE token's name is not a
                   3649:     <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
                   3650:     missing, or the token's system identifier is neither missing nor a
                   3651:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
                   3652:     "<code>about:legacy-compat</code>", and none of the sets of
                   3653:     conditions in the following list are matched, then there is a
                   3654:     <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
                   3655:     following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
                   3656:     permitted DOCTYPE</dfn>.</p>
                   3657: 
                   3658:     <ul><!-- only things that trigger no-quirks mode and were valid in
                   3659:      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     3660:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3661:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.0//EN</code>", and the
                   3662:      token's system identifier is either missing or the
                   3663:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
                   3664: 
                   3665:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3666:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3667:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.01//EN</code>", and the
                   3668:      token's system identifier is either missing or the
                   3669:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
                   3670: 
                   3671:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3672:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3673:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.0&#160;Strict//EN</code>",
                   3674:      and the token's system identifier is the
                   3675:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
                   3676: 
                   3677:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3678:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3679:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.1//EN</code>", and the
                   3680:      token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
                   3681:      string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
                   3682: 
                   3683:     </ul><p>Conformance checkers may, based on the values (including
                   3684:     presence or lack thereof) of the DOCTYPE token's name, public
                   3685:     identifier, or system identifier, switch to a conformance checking
                   3686:     mode for another language (e.g. based on the DOCTYPE token a
                   3687:     conformance checker could recognize that the document is an
1.183     mike     3688:     HTML4-era document, and defer to an HTML4 conformance
1.1       mike     3689:     checker.)</p>
                   3690: 
                   3691:     <p>Append a <code>DocumentType</code> node to the
                   3692:     <code>Document</code> node, with the <code title="">name</code>
                   3693:     attribute set to the name given in the DOCTYPE token, or the empty
                   3694:     string if the name was missing; the <code title="">publicId</code>
                   3695:     attribute set to the public identifier given in the DOCTYPE token,
                   3696:     or the empty string if the public identifier was missing; the
                   3697:     <code title="">systemId</code> attribute set to the system
                   3698:     identifier given in the DOCTYPE token, or the empty string if the
                   3699:     system identifier was missing; and the other attributes specific
                   3700:     to <code>DocumentType</code> objects set to null and empty lists
                   3701:     as appropriate. Associate the <code>DocumentType</code> node with
                   3702:     the <code>Document</code> object so that it is returned as the
                   3703:     value of the <code title="">doctype</code> attribute of the
                   3704:     <code>Document</code> object.</p>
                   3705: 
                   3706:     <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
                   3707:     one of the conditions in the following list, then set the
                   3708:     <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
                   3709: 
                   3710:     <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
                   3711:      <li> The name is set to anything other than "<code title="">HTML</code>". </li>
                   3712:      <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
                   3713:      <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   3714:      <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   3715:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
                   3716:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
                   3717:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
                   3718:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
                   3719:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
                   3720:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
                   3721:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
                   3722:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
                   3723:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
                   3724:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   3725:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
                   3726:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
                   3727:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
                   3728:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
                   3729:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
                   3730:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
                   3731:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
                   3732:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
                   3733:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
                   3734:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
                   3735:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
                   3736:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
                   3737:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
                   3738:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
                   3739:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
                   3740:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
                   3741:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
                   3742:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
                   3743:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
                   3744:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
                   3745:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
                   3746:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
                   3747:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
                   3748:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
                   3749:      <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
                   3750:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
                   3751:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
                   3752:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
                   3753:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
                   3754:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
                   3755:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
                   3756:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
                   3757:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
                   3758:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
                   3759:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
                   3760:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
                   3761:      <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
                   3762:      <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
                   3763:      <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
                   3764:      <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
                   3765:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
                   3766:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
                   3767:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
                   3768:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
                   3769:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   3770:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
                   3771:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
                   3772:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
                   3773:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
                   3774:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
                   3775:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
                   3776:      <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
                   3777:      <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
                   3778:    <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
                   3779:      <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
                   3780:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
                   3781:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
                   3782:      <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
                   3783:      <li> The public identifier is set to: "<code title="">HTML</code>" </li>
                   3784:      <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
                   3785:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   3786:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   3787:     </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
                   3788:     in the following list, then set the <code>Document</code> to
                   3789:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
                   3790: 
                   3791:     <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
                   3792:      <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
                   3793:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   3794:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   3795:     </ul><p>The name, system identifier, and public identifier strings must
                   3796:     be compared to the values given in the lists above in an
                   3797:     <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
                   3798:     whose value is the empty string is not considered missing for the
                   3799:     purposes of the conditions above.</p>
                   3800: 
                   3801:     <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>
                   3802: 
                   3803:    </dd>
                   3804: 
                   3805:    <dt>Anything else</dt>
                   3806:    <dd>
                   3807: 
                   3808:     <p><a href="#parse-error">Parse error</a>.</p>
                   3809: 
                   3810:     <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
                   3811: 
                   3812:     <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
                   3813:     reprocess the current token.</p>
                   3814: 
                   3815:    </dd>
                   3816: 
                   3817:   </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>
                   3818: 
                   3819:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
                   3820:   mode: before html">before html</a>", tokens must be handled as follows:</p>
                   3821: 
                   3822:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   3823:    <dd>
                   3824:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3825:    </dd>
                   3826: 
                   3827:    <dt>A comment token</dt>
                   3828:    <dd>
                   3829:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   3830:     object with the <code title="">data</code> attribute set to the
                   3831:     data given in the comment token.</p>
                   3832:    </dd>
                   3833: 
                   3834:    <dt>A character token that is one of U+0009 CHARACTER
                   3835:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3836:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3837:    <dd>
                   3838:     <p>Ignore the token.</p>
                   3839:    </dd>
                   3840: 
                   3841:    <dt>A start tag whose tag name is "html"</dt>
                   3842:    <dd>
                   3843: 
                   3844:     <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
                   3845:     namespace</a>. Append it to the <code>Document</code>
                   3846:     object. Put this element in the <a href="#stack-of-open-elements">stack of open
                   3847:     elements</a>.</p>
                   3848: 
                   3849:     <p id="parser-appcache">If the <code>Document</code> is being
                   3850:     loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
                   3851:     <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
                   3852:     has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
                   3853:     then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
                   3854:     attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
                   3855:     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     3856:     algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
                   3857:     any <a href="infrastructure.html#url-fragment" title="url-fragment">&lt;fragment&gt;</a> component
                   3858:     removed; otherwise, if there is no such attribute or resolving it
                   3859:     fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
                   3860:     cache selection algorithm</a> with no manifest. The algorithm
                   3861:     must be passed the <code>Document</code> object.</p>
1.1       mike     3862: 
                   3863:     <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>
                   3864: 
                   3865:    </dd>
                   3866: 
                   3867:    <dt>Anything else</dt>
                   3868:    <dd>
                   3869: 
1.159     mike     3870:     <p>Create an <code><a href="semantics.html#the-html-element-0">html</a></code> element. Append it to the
1.1       mike     3871:     <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
                   3872:     of open elements</a>.</p>
                   3873: 
                   3874:     <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
                   3875:     context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
                   3876:     algorithm</a> with no manifest, passing it the
                   3877:     <code>Document</code> object.</p>
                   3878: 
                   3879:     <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
                   3880:     reprocess the current token.</p>
                   3881: 
                   3882:     <p class="XXX">Should probably make end tags be ignored, so
                   3883:     that "&lt;/head&gt;&lt;!-- --&gt;&lt;html&gt;" puts the comment before the
                   3884:     root node (or should we?)</p>
                   3885: 
                   3886:    </dd>
                   3887: 
                   3888:   </dl><p>The root element can end up being removed from the
                   3889:   <code>Document</code> object, e.g. by scripts; nothing in particular
                   3890:   happens in such cases, content continues being appended to the nodes
                   3891:   as described in the next section.</p>
                   3892: 
                   3893: 
                   3894:   <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>
                   3895: 
                   3896:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
                   3897:   mode: before head">before head</a>", tokens must be handled as follows:</p>
                   3898: 
                   3899:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3900:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3901:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3902:    <dd>
                   3903:     <p>Ignore the token.</p> <!-- :-( -->
                   3904:    </dd>
                   3905: 
                   3906:    <dt>A comment token</dt>
                   3907:    <dd>
                   3908:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   3909:     node</a> with the <code title="">data</code> attribute set to
                   3910:     the data given in the comment token.</p>
                   3911:    </dd>
                   3912: 
                   3913:    <dt>A DOCTYPE token</dt>
                   3914:    <dd>
                   3915:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3916:    </dd>
                   3917: 
                   3918:    <dt>A start tag whose tag name is "html"</dt>
                   3919:    <dd>
                   3920:     <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
                   3921:     mode</a>.</p>
                   3922:    </dd>
                   3923: 
                   3924:    <dt>A start tag whose tag name is "head"</dt>
                   3925:    <dd>
                   3926: 
                   3927:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   3928: 
                   3929:     <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
1.159     mike     3930:     to the newly created <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike     3931: 
                   3932:     <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>
                   3933: 
                   3934:    </dd>
                   3935: 
                   3936:    <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
                   3937:    <dd>
                   3938: 
                   3939:     <p>Act as if a start tag token with the tag name "head" and no
                   3940:     attributes had been seen, then reprocess the current token.</p>
                   3941: 
                   3942:    </dd>
                   3943: 
                   3944:    <dt>Any other end tag</dt>
                   3945:    <dd>
                   3946: 
                   3947:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3948: 
                   3949:    </dd>
                   3950: 
                   3951:    <dt>Anything else</dt>
                   3952:    <dd>
                   3953: 
                   3954:     <p>Act as if a start tag token with the tag name "head" and no
                   3955:     attributes had been seen, then reprocess the current
                   3956:     token.</p>
                   3957: 
                   3958:    </dd>
                   3959: 
                   3960:   </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>
                   3961: 
                   3962:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
                   3963:   mode: in head">in head</a>", tokens must be handled as follows:</p>
                   3964: 
                   3965:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3966:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3967:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3968:    <dd>
                   3969:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   3970:     the <a href="#current-node">current node</a>.</p>
                   3971:    </dd>
                   3972: 
                   3973:    <dt>A comment token</dt>
                   3974:    <dd>
                   3975:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   3976:     node</a> with the <code title="">data</code> attribute set to
                   3977:     the data given in the comment token.</p>
                   3978:    </dd>
                   3979: 
                   3980:    <dt>A DOCTYPE token</dt>
                   3981:    <dd>
                   3982:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3983:    </dd>
                   3984: 
                   3985:    <dt>A start tag whose tag name is "html"</dt>
                   3986:    <dd>
                   3987:     <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
                   3988:     mode</a>.</p>
                   3989:    </dd>
                   3990: 
                   3991:    <dt>A start tag whose tag name is one of: "base", "command",
                   3992:    "link"</dt>
                   3993:    <dd>
                   3994: 
                   3995:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   3996:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   3997:     elements</a>.</p>
                   3998: 
                   3999:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4000:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4001: 
                   4002:    </dd>
                   4003: 
                   4004:    <dt>A start tag whose tag name is "meta"</dt>
                   4005:    <dd>
                   4006: 
                   4007:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   4008:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   4009:     elements</a>.</p>
                   4010: 
                   4011:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4012:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4013: 
                   4014:     <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
                   4015:     value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   4016:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   4017:     encoding</a> to the encoding given by the value of the
                   4018:     <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
                   4019: 
                   4020:     <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
                   4021:     applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
                   4022:     Content-Type</a> to its value returns a supported encoding
                   4023:     <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   4024:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   4025:     encoding</a> to the encoding <var title="">encoding</var>.</p>
                   4026: 
                   4027:    </dd>
                   4028: 
                   4029:    <dt>A start tag whose tag name is "title"</dt>
                   4030:    <dd>
                   4031:     <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
                   4032:    </dd>
                   4033: 
                   4034:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   4035:    <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
                   4036:    <dd>
1.91      mike     4037:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     4038:    </dd>
                   4039: 
                   4040:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
                   4041:    <dd>
                   4042: 
                   4043:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4044: 
                   4045:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
                   4046:     noscript</a>".</p>
                   4047: 
                   4048:    </dd>
                   4049: 
                   4050:    <dt id="scriptTag">A start tag whose tag name is "script"</dt>
                   4051:    <dd>
                   4052: 
                   4053:     <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
                   4054:      <a href="#html-namespace-0">HTML namespace</a>.</p></li>
                   4055: 
                   4056:      <li>
                   4057: 
                   4058:       <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
                   4059: 
                   4060:       <p class="note">This ensures that, if the script is external,
1.159     mike     4061:       any <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>
1.1       mike     4062:       calls in the script will execute in-line, instead of blowing the
                   4063:       document away, as would happen in most other cases. It also
                   4064:       prevents the script from executing until the end tag is
                   4065:       seen.</p>
                   4066: 
                   4067:      </li>
                   4068: 
                   4069:      <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
                   4070:      fragment parsing algorithm</a>, then mark the
                   4071:      <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
                   4072:      executed"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
                   4073: 
                   4074:      <li><p>Append the new element to the <a href="#current-node">current node</a>
                   4075:      and push it onto the <a href="#stack-of-open-elements">stack of open
                   4076:      elements</a>.</p></li>
                   4077: 
                   4078:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
1.91      mike     4079:      the RAWTEXT state.</p></li>
1.1       mike     4080: 
                   4081:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   4082:      <a href="#insertion-mode">insertion mode</a>.</p>
                   4083: 
1.91      mike     4084:      </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
                   4085:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     4086: 
                   4087:     </ol></dd>
                   4088: 
                   4089:    <dt>An end tag whose tag name is "head"</dt>
                   4090:    <dd>
                   4091: 
                   4092:     <p>Pop the <a href="#current-node">current node</a> (which will be the
1.159     mike     4093:     <code><a href="semantics.html#the-head-element-0">head</a></code> element) off the <a href="#stack-of-open-elements">stack of open
1.1       mike     4094:     elements</a>.</p>
                   4095: 
                   4096:     <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>
                   4097: 
                   4098:    </dd>
                   4099: 
                   4100:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4101:    <dd>
                   4102:     <p>Act as described in the "anything else" entry below.</p>
                   4103:    </dd>
                   4104: 
                   4105:    <dt>A start tag whose tag name is "head"</dt>
                   4106:    <dt>Any other end tag</dt>
                   4107:    <dd>
                   4108:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4109:    </dd>
                   4110: 
                   4111:    <dt>Anything else</dt>
                   4112:    <dd>
                   4113: 
                   4114:     <!-- can't get here with an EOF and a fragment case -->
                   4115: 
                   4116:     <p>Act as if an end tag token with the tag name "head" had
                   4117:     been seen, and reprocess the current token.</p>
                   4118: 
                   4119:     <p class="XXX">In certain UAs, <a href="https://bugzilla.mozilla.org/attachment.cgi?id=180157&amp;action=view">some
                   4120:     elements</a> don't trigger the "in body" mode straight away,
                   4121:     but instead get put into the head. Do we want to copy
                   4122:     that?</p>
                   4123: 
                   4124:    </dd>
                   4125: 
                   4126:   </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>
                   4127: 
                   4128:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
                   4129:   mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
                   4130: 
                   4131:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   4132:    <dd>
                   4133:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4134:    </dd>
                   4135: 
                   4136:    <dt>A start tag whose tag name is "html"</dt>
                   4137:    <dd>
                   4138:     <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
                   4139:     mode</a>.</p>
                   4140:    </dd>
                   4141: 
                   4142:    <dt>An end tag whose tag name is "noscript"</dt>
                   4143:    <dd>
                   4144: 
                   4145:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   4146:     <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   4147:     elements</a>; the new <a href="#current-node">current node</a> will be a
1.159     mike     4148:     <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike     4149: 
                   4150:     <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>
                   4151: 
                   4152:    </dd>
                   4153: 
                   4154:    <dt>A character token that is one of U+0009 CHARACTER
                   4155:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4156:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4157:    <dt>A comment token</dt>
                   4158:    <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
                   4159:    <dd>
                   4160:     <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
                   4161:     mode</a>.</p>
                   4162:    </dd>
                   4163: 
                   4164:    <dt>An end tag whose tag name is "br"</dt>
                   4165:    <dd>
                   4166:     <p>Act as described in the "anything else" entry below.</p>
                   4167:    </dd>
                   4168: 
                   4169:    <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
                   4170:    <dt>Any other end tag</dt>
                   4171:    <dd>
                   4172:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4173:    </dd>
                   4174: 
                   4175:    <dt>Anything else</dt>
                   4176:    <dd>
                   4177: 
                   4178:     <!-- can't get here with an EOF and a fragment case -->
                   4179: 
                   4180:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   4181:     name "noscript" had been seen and reprocess the current
                   4182:     token.</p>
                   4183: 
                   4184:    </dd>
                   4185: 
                   4186:   </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>
                   4187: 
                   4188:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
                   4189:   mode: after head">after head</a>", tokens must be handled as follows:</p>
                   4190: 
                   4191:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4192:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4193:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4194:    <dd>
                   4195:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   4196:     the <a href="#current-node">current node</a>.</p>
                   4197:    </dd>
                   4198: 
                   4199:    <dt>A comment token</dt>
                   4200:    <dd>
                   4201:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4202:     node</a> with the <code title="">data</code> attribute set to
                   4203:     the data given in the comment token.</p>
                   4204:    </dd>
                   4205: 
                   4206:    <dt>A DOCTYPE token</dt>
                   4207:    <dd>
                   4208:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4209:    </dd>
                   4210: 
                   4211:    <dt>A start tag whose tag name is "html"</dt>
                   4212:    <dd>
                   4213:     <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
                   4214:     mode</a>.</p>
                   4215:    </dd>
                   4216: 
                   4217:    <dt>A start tag whose tag name is "body"</dt>
                   4218:    <dd>
                   4219: 
                   4220:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4221: 
                   4222:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4223: 
                   4224:     <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>
                   4225: 
                   4226:    </dd>
                   4227: 
                   4228:    <dt>A start tag whose tag name is "frameset"</dt>
                   4229:    <dd>
                   4230: 
                   4231:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4232: 
                   4233:     <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>
                   4234: 
                   4235:    </dd>
                   4236: 
                   4237:    <dt>A start tag token whose tag name is one of: "base", "link",
                   4238:    "meta", "noframes", "script", "style", "title"</dt>
                   4239:    <dd>
                   4240: 
                   4241:     <p><a href="#parse-error">Parse error</a>.</p>
                   4242: 
                   4243:     <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
                   4244:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4245: 
                   4246:     <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
                   4247:     mode</a>.</p>
                   4248: 
                   4249:     <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
                   4250:     of open elements</a>.</p>
                   4251: 
                   4252:     <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
                   4253:     pointer</a> cannot be null at this point.</p>
                   4254: 
                   4255:    </dd>
                   4256: 
                   4257:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4258:    <dd>
                   4259:     <p>Act as described in the "anything else" entry below.</p>
                   4260:    </dd>
                   4261: 
                   4262:    <dt>A start tag whose tag name is "head"</dt>
                   4263:    <dt>Any other end tag</dt>
                   4264:    <dd>
                   4265:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4266:    </dd>
                   4267: 
                   4268:    <dt>Anything else</dt>
                   4269:    <dd>
                   4270:     <p>Act as if a start tag token with the tag name "body" and no
                   4271:     attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
                   4272:     flag</a> back to "ok", and then reprocess the current
                   4273:     token.</p>
                   4274:    </dd>
                   4275: 
                   4276:   </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>
                   4277: 
                   4278:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
                   4279:   mode: in body">in body</a>", tokens must be handled as follows:</p>
                   4280: 
                   4281:   <dl class="switch"><dt>A character token</dt>
                   4282:    <dd>
                   4283: 
                   4284:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4285:     any.</p>
                   4286: 
                   4287:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   4288:     character</a> into the <a href="#current-node">current node</a>.</p>
                   4289: 
                   4290:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   4291:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   4292:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   4293:     flag</a> to "not ok".</p>
                   4294: 
                   4295:    </dd>
                   4296: 
                   4297:    <dt>A comment token</dt>
                   4298:    <dd>
                   4299:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4300:     node</a> with the <code title="">data</code> attribute set to
                   4301:     the data given in the comment token.</p>
                   4302:    </dd>
                   4303: 
                   4304:    <dt>A DOCTYPE token</dt>
                   4305:    <dd>
                   4306:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4307:    </dd>
                   4308: 
                   4309:    <dt>A start tag whose tag name is "html"</dt>
                   4310:    <dd>
                   4311:     <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
                   4312:     check to see if the attribute is already present on the top
                   4313:     element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
                   4314:     add the attribute and its corresponding value to that element.</p>
                   4315:    </dd>
                   4316: 
                   4317:    <dt>A start tag token whose tag name is one of: "base", "command",
                   4318:    "link", "meta", "noframes", "script", "style", "title"</dt>
                   4319:    <dd>
                   4320:     <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
                   4321:     mode</a>.</p>
                   4322:    </dd>
                   4323: 
                   4324:    <dt>A start tag whose tag name is "body"</dt>
                   4325:    <dd>
                   4326: 
                   4327:     <p><a href="#parse-error">Parse error</a>.</p>
                   4328: 
                   4329:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159     mike     4330:     elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1       mike     4331:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4332:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4333: 
                   4334:     <p>Otherwise, for each attribute on the token, check to see if
1.159     mike     4335:     the attribute is already present on the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1       mike     4336:     element (the second element) on the <a href="#stack-of-open-elements">stack of open
                   4337:     elements</a>. If it is not, add the attribute and its
                   4338:     corresponding value to that element.</p>
                   4339: 
                   4340:    </dd>
                   4341: 
                   4342:    <dt>A start tag whose tag name is "frameset"</dt>
                   4343:    <dd>
                   4344: 
                   4345:     <p><a href="#parse-error">Parse error</a>.</p>
                   4346: 
                   4347:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159     mike     4348:     elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1       mike     4349:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4350:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4351: 
                   4352:     <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
                   4353:     the token.</p>
                   4354: 
                   4355:     <p>Otherwise, run the following steps:</p>
                   4356: 
                   4357:     <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
                   4358:      elements</a> from its parent node, if it has one.</p></li>
                   4359: 
                   4360:      <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
                   4361:      open elements</a>, from the <a href="#current-node">current node</a> up to,
1.159     mike     4362:      but not including, the root <code><a href="semantics.html#the-html-element-0">html</a></code> element.</p>
1.1       mike     4363: 
                   4364:      </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   4365:      token.</p></li>
                   4366: 
                   4367:      <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>
                   4368: 
                   4369:     </li></ol></dd>
                   4370: 
                   4371:    <dt>An end-of-file token</dt>
                   4372:    <dd>
                   4373: 
                   4374:     <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
                   4375:     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>
                   4376:     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
                   4377:     <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
                   4378:     <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
                   4379:     <code><a href="tabular-data.html#the-thead-element">thead</a></code> element, a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the
1.159     mike     4380:     <code><a href="semantics.html#the-body-element-0">body</a></code> element, or the <code><a href="semantics.html#the-html-element-0">html</a></code> element, then
1.1       mike     4381:     this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
                   4382:     fragment cases) -->
                   4383: 
                   4384:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   4385: 
                   4386:    </dd>
                   4387: 
                   4388:    <dt>An end tag whose tag name is "body"</dt>
                   4389:    <dd>
                   4390: 
                   4391:     <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
                   4392:     in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
                   4393:     token.</p>
                   4394: 
                   4395:     <!-- if we get here, the insertion mode here is forcibly "in
                   4396:     body". -->
                   4397: 
                   4398:     <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
                   4399:     elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
                   4400:     <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
                   4401:     <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
                   4402:     <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
                   4403:     <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
                   4404:     <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
                   4405:     <code><a href="tabular-data.html#the-th-element">th</a></code> element, a <code><a href="tabular-data.html#the-thead-element">thead</a></code> element, a
1.159     mike     4406:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the <code><a href="semantics.html#the-body-element-0">body</a></code> element, or the
                   4407:     <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1       mike     4408:     error</a>.</p> <!-- (some of those are fragment cases, e.g. for
                   4409:     <tbody> you'd have hit the first paragraph since the <body>
                   4410:     wouldn't be in scope, unless it was a fragment case) -->
                   4411: 
                   4412:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   4413:     then we'd have to somehow keep track of its state when we switch
                   4414:     to after-body. -->
                   4415: 
                   4416:     <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>
                   4417: 
                   4418:    </dd>
                   4419: 
                   4420:    <dt>An end tag whose tag name is "html"</dt>
                   4421:    <dd>
                   4422: 
                   4423:     <p>Act as if an end tag with tag name "body" had been seen,
                   4424:     then, if that token wasn't ignored, reprocess the current
                   4425:     token.</p>
                   4426: 
                   4427:     <p class="note">The fake end tag token here can only be
                   4428:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   4429: 
                   4430:    </dd>
                   4431: 
                   4432:    <!-- start tags for non-phrasing flow content elements -->
                   4433: 
                   4434:    <!-- the normal ones -->
                   4435:    <dt>A start tag whose tag name is one of: "address", "article",
1.86      mike     4436:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
                   4437:    "details", "dialog", "dir", "div", "dl", "fieldset", "figure",
                   4438:    "footer", "header", "hgroup", "menu", "nav", "ol", "p", "section",
                   4439:    "ul"</dt>
1.1       mike     4440:    <dd>
                   4441: 
                   4442:     <!-- As of May 2008 this doesn't match any browser exactly, but is
                   4443:     as close to what IE does as I can get without doing the non-tree
                   4444:     DOM nonsense, and thus should actually afford better compatibility
                   4445:     when implemented by the other browsers. -->
                   4446: 
                   4447:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4448:     an element in scope">has a <code>p</code> element in
                   4449:     scope</a>, then act as if an end tag with the tag name
                   4450:     "p" had been seen.</p>
                   4451: 
                   4452:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4453: 
                   4454:    </dd>
                   4455: 
                   4456:    <!-- as normal, but close h1-h6 if it's the current node -->
                   4457:    <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
                   4458:    "h5", "h6"</dt>
                   4459:    <dd>
                   4460: 
                   4461:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4462:     an element in scope">has a <code>p</code> element in
                   4463:     scope</a>, then act as if an end tag with the tag name
                   4464:     "p" had been seen.</p>
                   4465: 
                   4466:     <p>If the <a href="#current-node">current node</a> is an element whose tag name
                   4467:     is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
                   4468:     <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
                   4469:     the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4470:     <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
                   4471: 
                   4472:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4473: 
                   4474:    </dd>
                   4475: 
                   4476:    <!-- as normal, but drops leading newline -->
                   4477:    <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
                   4478:    <dd>
                   4479: 
                   4480:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4481:     an element in scope">has a <code>p</code> element in
                   4482:     scope</a>, then act as if an end tag with the tag name
                   4483:     "p" had been seen.</p>
                   4484: 
                   4485:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4486: 
                   4487:     <p>If the next token is a U+000A LINE FEED (LF) character
                   4488:     token, then ignore that token and move on to the next
                   4489:     one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
                   4490:     ignored as an authoring convenience.)</p>
                   4491: 
                   4492:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4493: 
                   4494:    </dd>
                   4495: 
                   4496:    <!-- as normal, but interacts with the form element pointer -->
                   4497:    <dt>A start tag whose tag name is "form"</dt>
                   4498:    <dd>
                   4499: 
                   4500:     <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
                   4501:     pointer</a> is not null, then this is a <a href="#parse-error">parse
                   4502:     error</a>; ignore the token.</p>
                   4503: 
                   4504:     <p>Otherwise:</p>
                   4505: 
                   4506:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4507:     an element in scope">has a <code>p</code> element in
                   4508:     scope</a>, then act as if an end tag with the tag name
                   4509:     "p" had been seen.</p>
                   4510: 
                   4511:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
                   4512:     <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
                   4513:     point to the element created.</p>
                   4514: 
                   4515:    </dd>
                   4516: 
                   4517:    <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
                   4518:    <dt>A start tag whose tag name is "li"</dt>
                   4519:    <dd>
                   4520: 
                   4521:     <p>Run the following algorithm:</p>
                   4522: 
                   4523:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4524: 
                   4525:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4526:      node</a> (the bottommost node of the stack).</p></li>
                   4527: 
                   4528:      <li><p>If <var title="">node</var> is an <code><a href="semantics.html#the-li-element">li</a></code> element,
                   4529:      then act as if an end tag with the tag name "li" had
                   4530:      been seen, then jump to the last step.</p></li>
                   4531: 
                   4532:      <li><p><i>Loop</i>: If <var title="">node</var> is not in the
                   4533:      <a href="#formatting">formatting</a> category, and is not in the
                   4534:      <a href="#phrasing">phrasing</a> category, and is not an
                   4535:      <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>
                   4536:      element, then jump to the last step.</p></li> <!-- an element
                   4537:      <foo> is in this list if the following markup:
                   4538: 
                   4539:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
                   4540: 
                   4541:      ...results in the second <li> not being (in any way) a descendant
                   4542:      of the first <li>, or if <foo> is a formatting element that gets
                   4543:      reopened later. -->
                   4544: 
                   4545:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4546:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4547:      the step labeled <i>loop</i>.</p></li>
                   4548: 
                   4549:      <li>
                   4550: 
                   4551:       <p>This is the last step.</p>
                   4552: 
                   4553:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4554:       an element in scope">has a <code>p</code> element in
                   4555:       scope</a>, then act as if an end tag with the tag name
                   4556:       "p" had been seen.</p>
                   4557: 
                   4558:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4559:       token.</p>
                   4560: 
                   4561:      </li>
                   4562: 
                   4563:     </ol></dd>
                   4564: 
                   4565:    <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases  -->
                   4566:    <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
                   4567:    <dd>
                   4568: 
                   4569:     <p>Run the following algorithm:</p>
                   4570: 
                   4571:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4572: 
                   4573:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4574:      node</a> (the bottommost node of the stack).</p></li>
                   4575: 
                   4576:      <li><p><i>Loop</i>: If <var title="">node</var> is a
                   4577:      <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
                   4578:      tag with the same tag name as <var title="">node</var> had been
                   4579:      seen, then jump to the last step.</p></li>
                   4580: 
                   4581:      <li><p>If <var title="">node</var> is not in the
                   4582:      <a href="#formatting">formatting</a> category, and is not in the
                   4583:      <a href="#phrasing">phrasing</a> category, and is not an
                   4584:      <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>
                   4585:      element, then jump to the last step.</p></li> <!-- an element
                   4586:      <foo> is in this list if the following markup:
                   4587: 
                   4588:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
                   4589: 
                   4590:      ...results in the second <dt> not being (in any way) a descendant
                   4591:      of the first <dt>, or if <foo> is a formatting element that gets
                   4592:      reopened later. -->
                   4593: 
                   4594:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4595:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4596:      the step labeled <i>loop</i>.</p></li>
                   4597: 
                   4598:      <li>
                   4599: 
                   4600:       <p>This is the last step.</p>
                   4601: 
                   4602:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4603:       an element in scope">has a <code>p</code> element in
                   4604:       scope</a>, then act as if an end tag with the tag name
                   4605:       "p" had been seen.</p>
                   4606: 
                   4607:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4608:       token.</p>
                   4609: 
                   4610:      </li>
                   4611: 
                   4612:     </ol></dd>
                   4613: 
                   4614:    <!-- same as normal, but effectively ends parsing -->
                   4615:    <dt>A start tag whose tag name is "plaintext"</dt>
                   4616:    <dd>
                   4617: 
                   4618:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4619:     an element in scope">has a <code>p</code> element in
                   4620:     scope</a>, then act as if an end tag with the tag name
                   4621:     "p" had been seen.</p>
                   4622: 
                   4623:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4624: 
                   4625:     <p>Switch the <a href="#content-model-flag">content model flag</a> to the PLAINTEXT
                   4626:     state.</p>
                   4627: 
                   4628:     <p class="note">Once a start tag with the tag name "plaintext"
                   4629:     has been seen, that will be the last token ever seen other
                   4630:     than character tokens (and the end-of-file token), because
                   4631:     there is no way to switch the <a href="#content-model-flag">content model flag</a>
                   4632:     out of the PLAINTEXT state.</p>
                   4633: 
                   4634:    </dd>
                   4635: 
                   4636:    <!-- end tags for non-phrasing flow content elements -->
                   4637: 
                   4638:    <!-- the normal ones -->
                   4639:    <dt>An end tag whose tag name is one of: "address", "article",
1.86      mike     4640:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
                   4641:    "details", "dialog", "dir", "div", "dl", "fieldset", "figure",
                   4642:    "footer", "header", "hgroup", "listing", "menu", "nav", "ol",
                   4643:    "pre", "section", "ul"</dt>
1.1       mike     4644:    <dd>
                   4645: 
                   4646:     <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>
                   4647:     with the same tag name as that of the token, then this is a
                   4648:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4649: 
                   4650:     <p>Otherwise, run these steps:</p>
                   4651: 
                   4652:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4653: 
                   4654:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4655:      the same tag name as that of the token, then this is a
                   4656:      <a href="#parse-error">parse error</a>.</p></li>
                   4657: 
                   4658:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4659:      until an element with the same tag name as the token has been
                   4660:      popped from the stack.</p></li>
                   4661: 
                   4662:     </ol></dd>
                   4663: 
                   4664:    <!-- removes the form element pointer instead of the matching node -->
                   4665:    <dt>An end tag whose tag name is "form"</dt>
                   4666:    <dd>
                   4667: 
                   4668:     <p>Let <var title="">node</var> be the element that the
                   4669:     <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
                   4670:     to.</p>
                   4671: 
                   4672:     <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   4673:     to null.</p>
                   4674: 
                   4675:     <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
                   4676:     elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
                   4677:     scope">have <var title="">node</var> in scope</a>, then this is
                   4678:     a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4679: 
                   4680:     <p>Otherwise, run these steps:</p>
                   4681: 
                   4682:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4683: 
                   4684:      <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
                   4685:      error</a>.</p></li>
                   4686: 
                   4687:      <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
                   4688:      open elements</a>.</p></li>
                   4689: 
                   4690:     </ol></dd>
                   4691: 
                   4692:    <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
                   4693:    <dt>An end tag whose tag name is "p"</dt>
                   4694:    <dd>
                   4695: 
                   4696:     <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>
                   4697:     with the same tag name as that of the token, then this is a
                   4698:     <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
                   4699:     "p" had been seen, then reprocess the current token.</p>
                   4700: 
                   4701:     <p>Otherwise, run these steps:</p>
                   4702: 
                   4703:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4704:      for elements with the same tag name as the token.</p></li>
                   4705: 
                   4706:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4707:      the same tag name as that of the token, then this is a
                   4708:      <a href="#parse-error">parse error</a>.</p></li>
                   4709: 
                   4710:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4711:      until an element with the same tag name as the token has been
                   4712:      popped from the stack.</p></li>
                   4713: 
                   4714:     </ol></dd>
                   4715: 
1.234     mike     4716:    <!-- as normal, but needs care as the elements have optional tags, and are further scoped by <ol>/<ul> -->
                   4717:    <dt>An end tag whose tag name is "li"</dt>
                   4718:    <dd>
                   4719: 
                   4720:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-list-item-scope" title="has an element in list item scope">have an element in list
                   4721:     item scope</a> with the same tag name as that of the token,
                   4722:     then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4723: 
                   4724:     <p>Otherwise, run these steps:</p>
                   4725: 
                   4726:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4727:      for elements with the same tag name as the token.</p></li>
                   4728: 
                   4729:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4730:      the same tag name as that of the token, then this is a
                   4731:      <a href="#parse-error">parse error</a>.</p></li>
                   4732: 
                   4733:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4734:      until an element with the same tag name as the token has been
                   4735:      popped from the stack.</p></li>
                   4736: 
                   4737:     </ol></dd>
                   4738: 
1.1       mike     4739:    <!-- as normal, but needs care as the elements have optional tags -->
1.234     mike     4740:    <dt>An end tag whose tag name is one of: "dd", "dt"</dt>
1.1       mike     4741:    <dd>
                   4742: 
                   4743:     <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>
                   4744:     with the same tag name as that of the token, then this is a
                   4745:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4746: 
                   4747:     <p>Otherwise, run these steps:</p>
                   4748: 
                   4749:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4750:      for elements with the same tag name as the token.</p></li>
                   4751: 
                   4752:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4753:      the same tag name as that of the token, then this is a
                   4754:      <a href="#parse-error">parse error</a>.</p></li>
                   4755: 
                   4756:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4757:      until an element with the same tag name as the token has been
                   4758:      popped from the stack.</p></li>
                   4759: 
                   4760:     </ol></dd>
                   4761: 
                   4762:    <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
                   4763:    <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
                   4764:    <dd>
                   4765: 
                   4766:     <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>
                   4767:     whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
                   4768:     then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4769: 
                   4770:     <p>Otherwise, run these steps:</p>
                   4771: 
                   4772:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4773: 
                   4774:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4775:      the same tag name as that of the token, then this is a
                   4776:      <a href="#parse-error">parse error</a>.</p></li>
                   4777: 
                   4778:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4779:      until an element whose tag name is one of "h1", "h2", "h3", "h4",
                   4780:      "h5", or "h6" has been popped from the stack.</p></li>
                   4781: 
                   4782:     </ol></dd>
                   4783: 
                   4784:    <dt>An end tag whose tag name is "sarcasm"</dt>
                   4785:    <dd>
                   4786:     <p>Take a deep breath, then act as described in the "any other end
                   4787:     tag" entry below.</p>
                   4788:    </dd>
                   4789: 
                   4790:    <!-- ADOPTION AGENCY ELEMENTS
                   4791:         Mozilla-only: bdo blink del ins sub sup q
                   4792:         Safari-only: code dfn kbd nobr samp var wbr
                   4793:         Both: a b big em font i s small strike strong tt u -->
                   4794: 
                   4795:    <dt>A start tag whose tag name is "a"</dt>
                   4796:    <dd>
                   4797: 
                   4798:     <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
                   4799:     contains an element whose tag name is "a" between the end of
                   4800:     the list and the last marker on the list (or the start of the
                   4801:     list if there is no marker on the list), then this is a
                   4802:     <a href="#parse-error">parse error</a>; act as if an end tag with the tag
                   4803:     name "a" had been seen, then remove that element from the
                   4804:     <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
                   4805:     <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
                   4806:     already remove it (it might not have if the element is not
                   4807:     <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
                   4808:     scope</a>).</p>
                   4809: 
                   4810:     <p class="example">In the non-conforming stream
                   4811:     <code>&lt;a&#160;href="a"&gt;a&lt;table&gt;&lt;a&#160;href="b"&gt;b&lt;/table&gt;x</code>,
                   4812:     the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
                   4813:     the second one, and the "x" character would be inside a link
                   4814:     to "b", not to "a". This is despite the fact that the outer
                   4815:     <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
                   4816:     regular <code>&lt;/a&gt;</code> end tag at the start of the table
                   4817:     wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
                   4818: 
                   4819:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4820:     any.</p>
                   4821: 
                   4822:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4823:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4824:     elements</a>.</p>
                   4825: 
                   4826:    </dd>
                   4827: 
                   4828:    <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
                   4829:    "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
                   4830:    <dd>
                   4831: 
                   4832:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4833:     any.</p>
                   4834: 
                   4835:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4836:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4837:     elements</a>.</p>
                   4838: 
                   4839:    </dd>
                   4840: 
                   4841:    <dt>A start tag whose tag name is "nobr"</dt>
                   4842:    <dd>
                   4843: 
                   4844:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4845:     any.</p>
                   4846: 
                   4847:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   4848:     element in scope">has a <code>nobr</code> element in scope</a>,
                   4849:     then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
                   4850:     the tag name "nobr" had been seen, then once again
                   4851:     <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
                   4852:     any.</p>
                   4853: 
                   4854:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4855:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4856:     elements</a>.</p>
                   4857: 
                   4858:    </dd>
                   4859: 
                   4860:    <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
                   4861:    "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
                   4862:    "strike", "strong", "tt", "u"</dt>
                   4863:    <dd>
                   4864: 
                   4865:     <p>Follow these steps:</p>
                   4866: 
                   4867:     <ol><li>
                   4868: 
                   4869:       <p>Let the <var title="">formatting element</var> be the
                   4870:       last element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   4871:       elements</a> that:</p>
                   4872: 
                   4873:       <ul><li>is between the end of the list and the last scope
                   4874:        marker in the list, if any, or the start of the list
                   4875:        otherwise, and</li>
                   4876: 
                   4877:        <li>has the same tag name as the token.</li>
                   4878: 
                   4879:       </ul><p>If there is no such node, or, if that node is also in the
                   4880:       <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
                   4881:       <a href="#parse-error">parse error</a>; ignore the token, and abort these
                   4882:       steps.</p>
                   4883: 
                   4884:       <p>Otherwise, if there is such a node, but that node is not
                   4885:       in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
                   4886:       <a href="#parse-error">parse error</a>; remove the element from the list,
                   4887:       and abort these steps.</p>
                   4888: 
                   4889:       <p>Otherwise, there is a <var title="">formatting
                   4890:       element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
                   4891:       open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
                   4892:       element in scope">in scope</a>. If the element is not the
                   4893:       <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
                   4894:       error</a>. In any case, proceed with the algorithm as
                   4895:       written in the following steps.</p>
                   4896: 
                   4897:      </li>
                   4898: 
                   4899:      <li><p>Let the <var title="">furthest block</var> be the
                   4900:      topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
                   4901:      is lower in the stack than the <var title="">formatting
                   4902:      element</var>, and is not an element in the
                   4903:      <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
                   4904:      categories. There might not be one.</p></li>
                   4905: 
                   4906:      <li><p>If there is no <var title="">furthest block</var>,
                   4907:      then the UA must skip the subsequent steps and instead just
                   4908:      pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
                   4909:      elements</a>, from the <a href="#current-node">current node</a> up to and
                   4910:      including the <var title="">formatting element</var>, and
                   4911:      remove the <var title="">formatting element</var> from the
                   4912:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
                   4913: 
                   4914:      <li><p>Let the <var title="">common ancestor</var> be the element
                   4915:      immediately above the <var title="">formatting element</var> in the
                   4916:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   4917: 
                   4918:      <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
                   4919:      formatting elements</a> relative to the elements on either
                   4920:      side of it in the list.</p></li>
                   4921: 
                   4922:      <li>
                   4923: 
                   4924:       <p>Let <var title="">node</var> and <var title="">last node</var> be the
                   4925:       <var title="">furthest block</var>. Follow these steps:</p>
                   4926: 
                   4927:       <ol><li>Let <var title="">node</var> be the element immediately
                   4928:        above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
                   4929:        elements</a>.</li>
                   4930: 
                   4931:        <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
                   4932:        active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
                   4933:        elements</a> and then go back to step 1.</li>
                   4934: 
                   4935:        <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
                   4936:        in the overall algorithm.</li>
                   4937: 
                   4938:        <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
                   4939:        bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   4940:        elements</a>.</li>
                   4941: 
                   4942:        <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   4943:        element <var title="">node</var> was created, replace the entry
                   4944:        for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
                   4945:        formatting elements</a> with an entry for the new element,
                   4946:        replace the entry for <var title="">node</var> in the
                   4947:        <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
                   4948:        element, and let <var title="">node</var> be the new
                   4949:        element.</li>
                   4950: 
                   4951:        <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
                   4952:        parent node if any.</li>
                   4953: 
                   4954:        <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
                   4955: 
                   4956:        <li>Return to step 1 of this inner set of steps.</li>
                   4957: 
                   4958:       </ol></li>
                   4959: 
                   4960:      <li>
                   4961: 
                   4962:       <p>If the <var title="">common ancestor</var> node is a
                   4963:       <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>,
                   4964:       <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,
                   4965:       <a href="#foster-parent">foster parent</a> whatever <var title="">last
                   4966:       node</var> ended up being in the previous step, first removing
                   4967:       it from its previous parent node if any.</p>
                   4968: 
                   4969:       <p>Otherwise, append whatever <var title="">last node</var>
                   4970:       ended up being in the previous step to the <var title="">common
                   4971:       ancestor</var> node, first removing it from its previous parent
                   4972:       node if any.</p>
                   4973: 
                   4974:      </li>
                   4975: 
                   4976:      <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   4977:      <var title="">formatting element</var> was created.</p></li>
                   4978: 
                   4979:      <li><p>Take all of the child nodes of the <var title="">furthest
                   4980:      block</var> and append them to the element created in the last
                   4981:      step.</p></li>
                   4982: 
                   4983:      <li><p>Append that new element to the <var title="">furthest
                   4984:      block</var>.</p></li>
                   4985: 
                   4986:      <li><p>Remove the <var title="">formatting element</var> from the
                   4987:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
                   4988:      new element into the <a href="#list-of-active-formatting-elements">list of active formatting
                   4989:      elements</a> at the position of the aforementioned
                   4990:      bookmark.</p></li>
                   4991: 
                   4992:      <li><p>Remove the <var title="">formatting element</var> from the
                   4993:      <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
                   4994:      into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
                   4995:      the position of the <var title="">furthest block</var> in that
                   4996:      stack.</p></li>
                   4997: 
                   4998:      <li><p>Jump back to step 1 in this series of steps.</p></li>
                   4999: 
                   5000:     </ol><!--XXX
                   5001:     <div class="example">
                   5002:      <p class="XXX">Need an example.</p>
                   5003:     </div>
                   5004: --><p class="note">Because of the way this algorithm causes elements to
                   5005:     change parents, it has been dubbed the "adoption agency algorithm"
                   5006:     (in contrast with other possibly algorithms for dealing with
                   5007:     misnested content, which included the "incest algorithm", the
                   5008:     "secret affair algorithm", and the "Heisenberg algorithm").</p>
                   5009: 
                   5010:    </dd>
                   5011: 
                   5012:    <dt>A start tag whose tag name is "button"</dt>
                   5013:    <dd>
                   5014: 
                   5015:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5016:     an element in scope">has a <code>button</code> element in
                   5017:     scope</a>, then this is a <a href="#parse-error">parse error</a>;
                   5018:     act as if an end tag with the tag name "button" had been seen,
                   5019:     then reprocess the token.</p>
                   5020: 
                   5021:     <p>Otherwise:</p>
                   5022: 
                   5023:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5024:     any.</p>
                   5025: 
                   5026:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5027: 
                   5028:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5029:     formatting elements</a>.</p>
                   5030: 
                   5031:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5032: 
                   5033:    </dd>
                   5034: 
                   5035:    <dt>A start tag token whose tag name is one of: "applet",
                   5036:    "marquee", "object"</dt>
                   5037:    <dd>
                   5038: 
                   5039:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5040:     any.</p>
                   5041: 
                   5042:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5043: 
                   5044:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5045:     formatting elements</a>.</p>
                   5046: 
                   5047:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5048: 
                   5049:    </dd>
                   5050: 
                   5051:    <dt>An end tag token whose tag name is one of: "applet", "button",
                   5052:    "marquee", "object"</dt>
                   5053:    <dd>
                   5054: 
                   5055:     <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>
                   5056:     with the same tag name as that of the token, then this is a
                   5057:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   5058: 
                   5059:     <p>Otherwise, run these steps:</p>
                   5060: 
                   5061:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5062: 
                   5063:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   5064:      the same tag name as that of the token, then this is a
                   5065:      <a href="#parse-error">parse error</a>.</p></li>
                   5066: 
                   5067:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   5068:      until an element with the same tag name as the token has been
                   5069:      popped from the stack.</p></li>
                   5070: 
                   5071:      <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
                   5072:      last marker</a>.</li>
                   5073: 
                   5074:     </ol></dd>
                   5075: 
                   5076:    <dt>A start tag whose tag name is "table"</dt>
                   5077:    <dd>
                   5078: 
                   5079:     <p>If the <code>Document</code> is <em>not</em> set to
                   5080:     <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
                   5081:     elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
                   5082:     <code>p</code> element in scope</a>, then act as if an end tag
                   5083:     with the tag name "p" had been seen.</p> <!-- i hate myself (this
                   5084:     quirk was basically caused by acid2; if i'd realised we could
                   5085:     change the specs when i wrote acid2, we could have avoided having
                   5086:     any parsing-mode quirks) -Hixie -->
                   5087: 
                   5088:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5089: 
                   5090:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5091: 
                   5092:     <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>
                   5093: 
                   5094:    </dd>
                   5095: 
                   5096:    <dt>A start tag whose tag name is one of: "area", "basefont",
                   5097:    "bgsound", "br", "embed", "img", "input", "keygen", "spacer",
                   5098:    "wbr"</dt>
                   5099:    <dd>
                   5100: 
                   5101:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5102:     any.</p>
                   5103: 
                   5104:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5105:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5106:     elements</a>.</p>
                   5107: 
                   5108:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5109:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5110: 
                   5111:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
                   5112:     shouldn't really do it for <area>, <basefont>, <bgsound>, and
                   5113:     <spacer> -->
                   5114: 
                   5115:    </dd>
                   5116: 
                   5117:    <dt>A start tag whose tag name is one of: "param", "source"</dt>
                   5118:    <dd>
                   5119: 
                   5120:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5121:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5122:     elements</a>.</p>
                   5123: 
                   5124:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5125:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5126: 
                   5127:    </dd>
                   5128: 
                   5129:    <dt>A start tag whose tag name is "hr"</dt>
                   5130:    <dd>
                   5131: 
                   5132:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5133:     an element in scope">has a <code>p</code> element in
                   5134:     scope</a>, then act as if an end tag with the tag name
                   5135:     "p" had been seen.</p>
                   5136: 
                   5137:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5138:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5139:     elements</a>.</p>
                   5140: 
                   5141:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5142:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5143: 
                   5144:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5145: 
                   5146:    </dd>
                   5147: 
                   5148:    <dt>A start tag whose tag name is "image"</dt>
                   5149:    <dd>
                   5150:     <p><a href="#parse-error">Parse error</a>. Change the token's tag name
                   5151:     to "img" and reprocess it. (Don't ask.)</p> <!-- As of
                   5152:     2005-12, studies showed that around 0.2% of pages used the
                   5153:     <image> element. -->
                   5154:    </dd>
                   5155: 
                   5156:    <dt id="isindex">A start tag whose tag name is "isindex"</dt>
                   5157:    <dd>
                   5158: 
                   5159:     <p><a href="#parse-error">Parse error</a>.</p>
                   5160: 
                   5161:     <p>If the <a href="#form-element-pointer"><code title="">form</code> element
                   5162:     pointer</a> is not null, then ignore the token.</p>
                   5163: 
                   5164:     <p>Otherwise:</p>
                   5165: 
                   5166:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5167:     token's <i>self-closing flag</i></a>, if it is set.</p> <!--
                   5168:     purely to reduce the number of errors (we don't care if they
                   5169:     included the /, they're not supposed to be including the tag at
                   5170:     all! -->
                   5171: 
                   5172:     <p>Act as if a start tag token with the tag name "form" had been seen.</p>
                   5173: 
                   5174:     <p>If the token has an attribute called "action", set the
                   5175:     <code title="attr-form-action">action</code> attribute on the
                   5176:     resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
                   5177:     "action" attribute of the token.</p>
                   5178: 
                   5179:     <p>Act as if a start tag token with the tag name "hr" had been
                   5180:     seen.</p>
                   5181: 
                   5182:     <p>Act as if a start tag token with the tag name "label" had been
                   5183:     seen.</p>
                   5184: 
                   5185:     <p>Act as if a stream of character tokens had been seen (see below
                   5186:     for what they should say).</p>
                   5187: 
                   5188:     <p>Act as if a start tag token with the tag name "input" had been
                   5189:     seen, with all the attributes from the "isindex" token except
                   5190:     "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
                   5191:     <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
                   5192: 
                   5193:     <p>Act as if a stream of character tokens had been seen (see
                   5194:     below for what they should say).</p>
                   5195: 
                   5196:     <p>Act as if an end tag token with the tag name "label" had been
                   5197:     seen.</p>
                   5198: 
                   5199:     <p>Act as if a start tag token with the tag name "hr" had been
                   5200:     seen.</p>
                   5201: 
                   5202:     <p>Act as if an end tag token with the tag name "form" had been
                   5203:     seen.</p>
                   5204: 
                   5205:     <p>If the token has an attribute with the name "prompt", then the
                   5206:     first stream of characters must be the same string as given in
                   5207:     that attribute, and the second stream of characters must be
                   5208:     empty. Otherwise, the two streams of character tokens together
                   5209:     should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
                   5210:     equivalent of "This is a searchable index. Insert your search
                   5211:     keywords here: (input field)" in the user's preferred
                   5212:     language.</p>
                   5213: 
                   5214:    </dd>
                   5215: 
                   5216:    <dt>A start tag whose tag name is "textarea"</dt>
                   5217:    <dd>
                   5218: 
                   5219:     <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   5220:      token.</p></li>
                   5221: 
                   5222:      <li><p>If the next token is a U+000A LINE FEED (LF) character
                   5223:      token, then ignore that token and move on to the next
                   5224:      one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
                   5225:      ignored as an authoring convenience.)</p></li>
                   5226: 
                   5227:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
                   5228:      the RCDATA state.</p></li>
                   5229: 
                   5230:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
                   5231:      current <a href="#insertion-mode">insertion mode</a>.</p>
                   5232: 
                   5233:      </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
                   5234:      ok".</p></li>
                   5235: 
1.91      mike     5236:      <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
                   5237:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     5238: 
                   5239:     </ol></dd>
                   5240: 
                   5241:    <dt>A start tag whose tag name is "xmp"</dt>
                   5242:    <dd>
                   5243: 
1.233     mike     5244:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5245:     an element in scope">has a <code>p</code> element in
                   5246:     scope</a>, then act as if an end tag with the tag name
                   5247:     "p" had been seen.</p>
                   5248: 
1.1       mike     5249:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5250:     any.</p>
                   5251: 
                   5252:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5253: 
1.91      mike     5254:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5255: 
                   5256:    </dd>
                   5257: 
                   5258:    <dt>A start tag whose tag name is "iframe"</dt>
                   5259:    <dd>
                   5260: 
                   5261:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5262: 
1.91      mike     5263:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5264: 
                   5265:    </dd>
                   5266: 
                   5267:    <dt>A start tag whose tag name is "noembed"</dt>
                   5268:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   5269:    <dd>
                   5270: 
1.91      mike     5271:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5272: 
                   5273:    </dd>
                   5274: 
                   5275:    <dt>A start tag whose tag name is "select"</dt>
                   5276:    <dd>
                   5277: 
                   5278:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5279:     any.</p>
                   5280: 
                   5281:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5282: 
                   5283:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5284: 
                   5285:     <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>",
                   5286:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5287:     body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   5288:     row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   5289:     cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
                   5290:     "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
                   5291:     table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
                   5292:     to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
                   5293: 
                   5294:    </dd>
                   5295: 
                   5296:    <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
                   5297:    <dd>
                   5298: 
                   5299:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5300:     element in scope">has an <code>option</code> element in
                   5301:     scope</a>, then act as if an end tag with the tag name "option"
                   5302:     had been seen.</p>
                   5303: 
                   5304:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5305:     any.</p>
                   5306: 
                   5307:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5308: 
                   5309:    </dd>
                   5310: 
                   5311:    <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
                   5312:    <dd>
                   5313: 
                   5314:     <!-- the parsing rules for ruby really don't match IE much at all,
                   5315:          but in practice the markup used is very simple and so strict
                   5316:          compatibility with IE isn't required. For example, as defined
                   5317:          here we get very, very different behaviour than IE for
                   5318:          pathological cases like:
                   5319: 
                   5320:            <ruby><ol><li><p>a<rt>b
                   5321:            <ruby>a<rt>b<p>c
                   5322: 
                   5323:          But in practice most ruby markup falls into these cases:
                   5324: 
                   5325:            <ruby>a<rt>b</ruby>
                   5326:            <ruby>a<rp>b<rt>c<rp>d</ruby>
                   5327:            <ruby>a<rt>b</rt></ruby>
                   5328:            <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
                   5329: 
                   5330:     -->
                   5331: 
                   5332:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5333:     element in scope">has a <code>ruby</code> element in scope</a>,
                   5334:     then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
                   5335:     node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
                   5336:     <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
                   5337:     node</a> up to the node immediately before the bottommost
                   5338:     <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
                   5339:     elements</a>.</p>
                   5340: 
                   5341:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5342: 
                   5343:    </dd>
                   5344: 
                   5345:    <dt>An end tag whose tag name is "br"</dt>
                   5346:    <dd>
                   5347:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
                   5348:     the tag name "br" had been seen. Ignore the end tag token.</p>
                   5349:    </dd>
                   5350: 
                   5351:    <dt>A start tag whose tag name is "math"</dt>
                   5352:    <dd>
                   5353: 
                   5354:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5355:     any.</p>
                   5356: 
                   5357:     <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
                   5358:     fixes the case of MathML attributes that are not all
                   5359:     lowercase.)</p>
                   5360: 
                   5361:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5362:     fixes the use of namespaced attributes, in particular XLink.)</p>
                   5363: 
                   5364:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5365:     <a href="#mathml-namespace">MathML namespace</a>.</p>
                   5366: 
                   5367:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5368:     the following change would be implied, except we'd have to do it
                   5369:     even in the face of a self-closed tag:
                   5370:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5371:     -->
                   5372: 
                   5373:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5374:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5375:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5376:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5377: 
                   5378:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5379:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5380:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5381:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5382:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5383:     foreign content">in foreign content</a>".</p>
                   5384: 
                   5385:    </dd>
                   5386: 
                   5387:    <dt>A start tag whose tag name is "svg"</dt>
                   5388:    <dd>
                   5389: 
                   5390:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5391:     any.</p>
                   5392: 
                   5393:     <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
                   5394:     the case of SVG attributes that are not all lowercase.)</p>
                   5395: 
                   5396:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5397:     fixes the use of namespaced attributes, in particular XLink in
                   5398:     SVG.)</p>
                   5399: 
                   5400:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5401:     <a href="#svg-namespace">SVG namespace</a>.</p>
                   5402: 
                   5403:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5404:     the following change would be implied, except we'd have to do it
                   5405:     even in the face of a self-closed tag:
                   5406:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5407:     -->
                   5408: 
                   5409:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5410:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5411:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5412:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5413: 
                   5414:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5415:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5416:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5417:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5418:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5419:     foreign content">in foreign content</a>".</p>
                   5420: 
                   5421:    </dd>
                   5422: 
                   5423:    <dt>A start <!--or end--> tag whose tag name is one of: "caption",
                   5424:    "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
                   5425:    "thead", "tr"</dt>
                   5426:    <!--<dt>An end tag whose tag name is one of: "area", "base",
                   5427:    "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
                   5428:    "img", "input", "isindex", "keygen", "link", "meta", "noembed",
                   5429:    "noframes", "param", "script", "select", "source", "spacer",
                   5430:    "style", "table", "textarea", "title", "wbr"</dt>-->
                   5431:    <!--<dt>An end tag whose tag name is "noscript", if the
                   5432:    <span>scripting flag</span> is enabled</dt>-->
                   5433:    <dd>
                   5434:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5435:     <!-- end tags are commented out because since they can never end
                   5436:     up on the stack anyway, the default end tag clause will
                   5437:     automatically handle them. we don't want to have text in the spec
                   5438:     that is just an optimisation, as that detracts from the spec
                   5439:     itself -->
                   5440:    </dd>
                   5441: 
                   5442:    <dt>Any other start tag</dt>
                   5443:    <dd>
                   5444: 
                   5445:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5446:     any.</p>
                   5447: 
                   5448:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5449: 
                   5450:     <p class="note">This element will be a <a href="#phrasing">phrasing</a>
                   5451:     element.</p>
                   5452: 
                   5453:    </dd>
                   5454: 
                   5455:    <dt>Any other end tag</dt>
                   5456:    <dd>
                   5457: 
                   5458:     <p>Run the following steps:</p>
                   5459: 
                   5460:     <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   5461:      node</a> (the bottommost node of the stack).</p></li>
                   5462: 
                   5463:      <li><p>If <var title="">node</var> has the same tag name as
                   5464:      the end tag token, then:</p>
                   5465: 
                   5466:       <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5467: 
                   5468:        <li><p>If the tag name of the end tag token does not match
                   5469:        the tag name of the <a href="#current-node">current node</a>, this is a
                   5470:        <a href="#parse-error">parse error</a>.</p></li>
                   5471: 
                   5472:        <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
                   5473:        to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
                   5474: 
                   5475:       </ol></li>
                   5476: 
                   5477:      <li><p>Otherwise, if <var title="">node</var> is in neither the
                   5478:      <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
                   5479:      category, then this is a <a href="#parse-error">parse error</a>; ignore the
                   5480:      token, and abort these steps.</p></li>
                   5481: 
                   5482:      <li><p>Set <var title="">node</var> to the previous entry in the
                   5483:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   5484: 
                   5485:      <li><p>Return to step 2.</p></li>
                   5486: 
                   5487:     </ol></dd>
                   5488: 
1.91      mike     5489:   </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     5490: 
                   5491:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.91      mike     5492:   mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>", tokens must be
1.1       mike     5493:   handled as follows:</p>
                   5494: 
                   5495:   <dl class="switch"><dt>A character token</dt>
                   5496:    <dd>
                   5497: 
                   5498:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   5499:     character</a> into the <a href="#current-node">current node</a>.</p>
                   5500: 
                   5501:    </dd>
                   5502: 
                   5503:    <dt>An end-of-file token</dt>
                   5504:    <dd>
                   5505: 
                   5506:     <!-- can't be the fragment case -->
                   5507:     <p><a href="#parse-error">Parse error</a>.</p>
                   5508: 
                   5509:     <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
                   5510:     element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
                   5511:     executed"</a>.</p>
                   5512: 
                   5513:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5514:     elements</a>.</p>
                   5515: 
                   5516:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5517:     insertion mode</a> and reprocess the current token.</p>
                   5518: 
                   5519:    </dd>
                   5520: 
                   5521:    <dt>An end tag whose tag name is "script"</dt>
                   5522:    <dd>
                   5523: 
                   5524:     <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
                   5525:     (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
                   5526: 
                   5527:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5528:     elements</a>.</p>
                   5529: 
                   5530:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5531:     insertion mode</a>.</p>
                   5532: 
                   5533:     <p>Let the <var title="">old insertion point</var> have the
                   5534:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   5535:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   5536:     input character</a>.</p>
                   5537: 
                   5538:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5539:     one.</p>
                   5540: 
                   5541:     <p><a href="semantics.html#running-a-script" title="running a script">Run</a> the <var title="">script</var>. This might cause some script to execute,
1.159     mike     5542:     which might cause <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters
1.1       mike     5543:     to be inserted into the tokenizer</a>, and might cause the
                   5544:     tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
                   5545: 
                   5546:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5547:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   5548:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5549: 
                   5550:     <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
                   5551:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   5552:     might be the "undefined" value.)</p>
                   5553: 
                   5554:     <p id="scriptTagParserResumes">At this stage, if there is a
                   5555:     <a href="semantics.html#pending-external-script">pending external script</a>, then:</p>
                   5556: 
                   5557:     <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
                   5558: 
                   5559:      <dd>
                   5560: 
                   5561:       <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
                   5562:       processing of any nested invocations of the tokenizer, yielding
                   5563:       control back to the caller. (Tokenization will resume when the
                   5564:       caller returns to the "outer" tree construction stage.)</p>
                   5565: 
                   5566:       <p class="note">The tree construction stage of this particular
                   5567:       parser is <a href="#nestedParsing">being called reentrantly</a>,
1.159     mike     5568:       say from a call to <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>.</p>
1.1       mike     5569: 
                   5570:      </dd>
                   5571: 
                   5572: 
                   5573:      <dt>Otherwise:</dt>
                   5574: 
                   5575:      <dd>
                   5576: 
                   5577:       <p>Follow these steps:</p>
                   5578: 
                   5579:       <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-external-script">pending
                   5580:        external script</a>. There is no longer a <a href="semantics.html#pending-external-script">pending
                   5581:        external script</a>.</p></li>
                   5582: 
                   5583:        <li><p><a href="browsers.html#pause">Pause</a> until the script has <a href="semantics.html#completed-loading">completed
                   5584:        loading</a>.</p></li>
                   5585: 
                   5586:        <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
                   5587:        <a href="#next-input-character">next input character</a>.</p></li>
                   5588: 
                   5589:        <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
                   5590:        by one (it should be zero before this step, so this sets it to
                   5591:        one).</p></li>
                   5592: 
                   5593:        <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute the
                   5594:        script</a>.</p></li>
                   5595: 
                   5596:        <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
                   5597:        by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
                   5598:        zero (which it always should be at this point), then set the
                   5599:        <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5600: 
                   5601:        </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
                   5602:        again.</p></li>
                   5603: 
                   5604:        <li><p>If there is once again a <a href="semantics.html#pending-external-script">pending external
                   5605:        script</a>, then repeat these steps from step 1.</p></li>
                   5606: 
                   5607:       </ol></dd>
                   5608: 
                   5609:     </dl></dd>
                   5610: 
                   5611:    <dt>Any other end tag</dt>
                   5612:    <dd>
                   5613: 
                   5614:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5615:     elements</a>.</p>
                   5616: 
                   5617:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5618:     insertion mode</a>.</p>
                   5619: 
                   5620:    </dd>
                   5621: 
                   5622:   </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>
                   5623: 
                   5624:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
                   5625:   mode: in table">in table</a>", tokens must be handled as follows:</p>
                   5626: 
                   5627:   <dl class="switch"><dt>A character token</dt>
                   5628:    <dd>
                   5629: 
                   5630:      <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
                   5631:      be an empty list of tokens.</p>
                   5632: 
                   5633:      <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   5634:      <a href="#insertion-mode">insertion mode</a>.</p>
                   5635: 
                   5636:      <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
                   5637:      reprocess the token.</p>
                   5638: 
                   5639:    </dd>
                   5640: 
                   5641:    <dt>A comment token</dt>
                   5642:    <dd>
                   5643:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   5644:     node</a> with the <code title="">data</code> attribute set to
                   5645:     the data given in the comment token.</p>
                   5646:    </dd>
                   5647: 
                   5648:    <dt>A DOCTYPE token</dt>
                   5649:    <dd>
                   5650:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5651:    </dd>
                   5652: 
                   5653:    <dt>A start tag whose tag name is "caption"</dt>
                   5654:    <dd>
                   5655: 
                   5656:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5657:     below.)</p>
                   5658: 
                   5659:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5660:     formatting elements</a>.</p>
                   5661: 
                   5662:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5663:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
                   5664: 
                   5665:    </dd>
                   5666: 
                   5667:    <dt>A start tag whose tag name is "colgroup"</dt>
                   5668:    <dd>
                   5669: 
                   5670:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5671:     below.)</p>
                   5672: 
                   5673:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5674:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
                   5675:     group</a>".</p>
                   5676: 
                   5677:    </dd>
                   5678: 
                   5679:    <dt>A start tag whose tag name is "col"</dt>
                   5680:    <dd>
                   5681:     <p>Act as if a start tag token with the tag name "colgroup"
                   5682:     had been seen, then reprocess the current token.</p>
                   5683:    </dd>
                   5684: 
                   5685:    <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
                   5686:    <dd>
                   5687: 
                   5688:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5689:     below.)</p>
                   5690: 
                   5691:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5692:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5693:     body</a>".</p>
                   5694: 
                   5695:    </dd>
                   5696: 
                   5697:    <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
                   5698:    <dd>
                   5699:     <p>Act as if a start tag token with the tag name "tbody" had
                   5700:     been seen, then reprocess the current token.</p>
                   5701:    </dd>
                   5702: 
                   5703:    <dt>A start tag whose tag name is "table"</dt>
                   5704:    <dd>
                   5705: 
                   5706:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
                   5707:     the tag name "table" had been seen, then, if that token wasn't
                   5708:     ignored, reprocess the current token.</p>
                   5709: 
                   5710:     <p class="note">The fake end tag token here can only be
                   5711:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5712: 
                   5713:    </dd>
                   5714: 
                   5715:    <dt>An end tag whose tag name is "table"</dt>
                   5716:    <dd>
                   5717: 
                   5718:     <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
                   5719:     scope</a> with the same tag name as the token, this is a
                   5720:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5721:     case</a>)</p>
                   5722: 
                   5723:     <p>Otherwise:</p>
                   5724: 
                   5725:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
                   5726:     element has been popped from the stack.</p>
                   5727: 
                   5728:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   5729: 
                   5730:    </dd>
                   5731: 
                   5732:    <dt>An end tag whose tag name is one of: "body", "caption",
                   5733:    "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
                   5734:    "thead", "tr"</dt>
                   5735:    <dd>
                   5736:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5737:    </dd>
                   5738: 
                   5739:    <dt>A start tag whose tag name is one of: "style", "script"</dt>
                   5740:    <dd>
                   5741: 
                   5742:     <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
                   5743:     mode</a>.</p>
                   5744: 
                   5745:    </dd>
                   5746: 
                   5747:    <dt>A start tag whose tag name is "input"</dt>
                   5748:    <dd>
                   5749: 
                   5750:     <p>If the token does not have an attribute with the name "type",
                   5751:     or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   5752:     case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
                   5753:     else" entry below.</p>
                   5754: 
                   5755:     <p>Otherwise:</p>
                   5756: 
                   5757:     <p><a href="#parse-error">Parse error</a>.</p>
                   5758: 
                   5759:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5760: 
                   5761:     <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
                   5762:     open elements</a>.</p>
                   5763: 
                   5764:    </dd>
                   5765: 
                   5766:    <dt>An end-of-file token</dt>
                   5767:    <dd>
                   5768: 
                   5769:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     5770:     <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1       mike     5771:     error</a>.</p>
                   5772: 
                   5773:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   5774:     the <a href="#fragment-case">fragment case</a>.</p>
                   5775: 
                   5776:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   5777: 
                   5778:    </dd>
                   5779: 
                   5780:    <dt>Anything else</dt>
                   5781:    <dd>
                   5782: 
                   5783:     <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
                   5784:     rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   5785:     body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
                   5786:     <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   5787:     <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
                   5788:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
                   5789:     into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
                   5790: 
                   5791:    </dd>
                   5792: 
                   5793:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
                   5794:   back to a table context</dfn>, it means that the UA must, while
                   5795:   the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-table-element">table</a></code>
1.159     mike     5796:   element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1       mike     5797:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   5798: 
                   5799:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     5800:   <code><a href="semantics.html#the-html-element-0">html</a></code> element after this process is a <a href="#fragment-case">fragment
1.1       mike     5801:   case</a>.</p>
                   5802: 
                   5803: 
                   5804: 
                   5805:   <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>
                   5806: 
                   5807:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
                   5808:   mode: in table text">in table text</a>", tokens must be handled
                   5809:   as follows:</p>
                   5810: 
                   5811:   <dl class="switch"><dt>A character token</dt>
                   5812:    <dd>
                   5813: 
                   5814:     <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
                   5815:     tokens</a></var> list.</p>
                   5816: 
                   5817:    </dd>
                   5818: 
                   5819: 
                   5820:    <dt>Anything else</dt>
                   5821:    <dd>
                   5822: 
                   5823:     <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
                   5824:     tokens</a></var> list are character tokens that are not one of U+0009
                   5825:     CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
                   5826:     (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
                   5827:     reprocess those character tokens using the rules given in the
                   5828:     "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
                   5829:     table">in table</a>" insertion mode.</p>
                   5830: 
                   5831:     <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
                   5832:     characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
                   5833:     tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
                   5834: 
                   5835:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5836:     insertion mode</a> and reprocess the token.</p>
                   5837: 
                   5838:    </dd>
                   5839: 
                   5840:   </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>
                   5841: 
                   5842:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
                   5843:   mode: in caption">in caption</a>", tokens must be handled as follows:</p>
                   5844: 
                   5845:   <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
                   5846:    <dd>
                   5847: 
                   5848:     <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
                   5849:     scope</a> with the same tag name as the token, this is a
                   5850:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5851:     case</a>)</p>
                   5852: 
                   5853:     <p>Otherwise:</p>
                   5854: 
                   5855:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   5856: 
                   5857:     <p>Now, if the <a href="#current-node">current node</a> is not a
                   5858:     <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
                   5859:     error</a>.</p>
                   5860: 
                   5861:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
                   5862:     element has been popped from the stack.</p>
                   5863: 
                   5864:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   5865:     the last marker</a>.</p>
                   5866: 
                   5867:     <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>
                   5868: 
                   5869:    </dd>
                   5870: 
                   5871:    <dt>A start tag whose tag name is one of: "caption", "col",
                   5872:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   5873:    <dt>An end tag whose tag name is "table"</dt>
                   5874:    <dd>
                   5875: 
                   5876:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   5877:     name "caption" had been seen, then, if that token wasn't
                   5878:     ignored, reprocess the current token.</p>
                   5879: 
                   5880:     <p class="note">The fake end tag token here can only be
                   5881:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5882: 
                   5883:    </dd>
                   5884: 
                   5885:    <dt>An end tag whose tag name is one of: "body", "col",
                   5886:    "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
                   5887:    "tr"</dt>
                   5888:    <dd>
                   5889:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5890:    </dd>
                   5891: 
                   5892:    <dt>Anything else</dt>
                   5893:    <dd>
                   5894:     <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
                   5895:     mode</a>.</p>
                   5896:    </dd>
                   5897: 
                   5898:   </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>
                   5899: 
                   5900:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
                   5901:   mode: in column group">in column group</a>", tokens must be handled as follows:</p>
                   5902: 
                   5903:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   5904:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   5905:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   5906:    <dd>
                   5907:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   5908:     the <a href="#current-node">current node</a>.</p>
                   5909:    </dd>
                   5910: 
                   5911:    <dt>A comment token</dt>
                   5912:    <dd>
                   5913:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   5914:     node</a> with the <code title="">data</code> attribute set to
                   5915:     the data given in the comment token.</p>
                   5916:    </dd>
                   5917: 
                   5918:    <dt>A DOCTYPE token</dt>
                   5919:    <dd>
                   5920:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5921:    </dd>
                   5922: 
                   5923:    <dt>A start tag whose tag name is "html"</dt>
                   5924:    <dd>
                   5925:     <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
                   5926:     mode</a>.</p>
                   5927:    </dd>
                   5928: 
                   5929:    <dt>A start tag whose tag name is "col"</dt>
                   5930:    <dd>
                   5931: 
                   5932:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5933:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5934:     elements</a>.</p>
                   5935: 
                   5936:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5937:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5938: 
                   5939:    </dd>
                   5940: 
                   5941:    <dt>An end tag whose tag name is "colgroup"</dt>
                   5942:    <dd>
                   5943: 
                   5944:     <p>If the <a href="#current-node">current node</a> is the root
1.159     mike     5945:     <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1       mike     5946:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   5947:     case</a>)</p>
                   5948: 
                   5949:     <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
                   5950:     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
                   5951:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   5952:     "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   5953: 
                   5954:    </dd>
                   5955: 
                   5956:    <dt>An end tag whose tag name is "col"</dt>
                   5957:    <dd>
                   5958:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5959:    </dd>
                   5960: 
                   5961:    <dt>An end-of-file token</dt>
                   5962:    <dd>
                   5963: 
1.159     mike     5964:     <p>If the <a href="#current-node">current node</a> is the root <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1       mike     5965:     element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
                   5966:     case</a>)</p>
                   5967: 
                   5968:     <p>Otherwise, act as described in the "anything else" entry
                   5969:     below.</p>
                   5970: 
                   5971:    </dd>
                   5972: 
                   5973:    <dt>Anything else</dt>
                   5974:    <dd>
                   5975: 
                   5976:     <p>Act as if an end tag with the tag name "colgroup" had been
                   5977:     seen, and then, if that token wasn't ignored, reprocess the
                   5978:     current token.</p>
                   5979: 
                   5980:     <p class="note">The fake end tag token here can only be
                   5981:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5982: 
                   5983:    </dd>
                   5984: 
                   5985:   </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>
                   5986: 
                   5987:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
                   5988:   mode: in table body">in table body</a>", tokens must be handled as follows:</p>
                   5989: 
                   5990:   <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
                   5991:    <dd>
                   5992: 
                   5993:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   5994:     context</a>. (See below.)</p>
                   5995: 
                   5996:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   5997:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
                   5998:     in row">in row</a>".</p>
                   5999: 
                   6000:    </dd>
                   6001: 
                   6002:    <dt>A start tag whose tag name is one of: "th", "td"</dt>
                   6003:    <dd>
                   6004:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
                   6005:     the tag name "tr" had been seen, then reprocess the current
                   6006:     token.</p>
                   6007:    </dd>
                   6008: 
                   6009:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   6010:    "thead"</dt>
                   6011:    <dd>
                   6012: 
                   6013:     <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
                   6014:     scope</a> with the same tag name as the token, this is a
                   6015:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   6016: 
                   6017:     <p>Otherwise:</p>
                   6018: 
                   6019:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6020:     context</a>. (See below.)</p>
                   6021: 
                   6022:     <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
                   6023:     open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   6024:     to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   6025: 
                   6026:    </dd>
                   6027: 
                   6028:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6029:    "colgroup", "tbody", "tfoot", "thead"</dt>
                   6030:    <dt>An end tag whose tag name is "table"</dt>
                   6031:    <dd>
                   6032: 
                   6033:     <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
                   6034:     <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
                   6035:     element in table scope</a>, this is a <a href="#parse-error">parse
                   6036:     error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6037:     case</a>)</p>
                   6038: 
                   6039:     <p>Otherwise:</p>
                   6040: 
                   6041:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6042:     context</a>. (See below.)</p>
                   6043: 
                   6044:     <p>Act as if an end tag with the same tag name as the
                   6045:     <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
                   6046:     been seen, then reprocess the current token.</p>
                   6047: 
                   6048:    </dd>
                   6049: 
                   6050:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6051:    "col", "colgroup", "html", "td", "th", "tr"</dt>
                   6052:    <dd>
                   6053:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6054:    </dd>
                   6055: 
                   6056:    <dt>Anything else</dt>
                   6057:    <dd>
                   6058:     <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
                   6059:     mode</a>.</p>
                   6060:    </dd>
                   6061: 
                   6062:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
                   6063:   back to a table body context</dfn>, it means that the UA must,
                   6064:   while the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
1.159     mike     6065:   <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1       mike     6066:   element, pop elements from the <a href="#stack-of-open-elements">stack of open
                   6067:   elements</a>.</p>
                   6068: 
                   6069:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     6070:   <code><a href="semantics.html#the-html-element-0">html</a></code> element after this process is a <a href="#fragment-case">fragment
1.1       mike     6071:   case</a>.</p>
                   6072: 
                   6073: 
                   6074:   <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>
                   6075: 
                   6076:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   6077:   mode: in row">in row</a>", tokens must be handled as follows:</p>
                   6078: 
                   6079:   <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
                   6080:    <dd>
                   6081: 
                   6082:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   6083:     context</a>. (See below.)</p>
                   6084: 
                   6085:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   6086:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
                   6087:     in cell">in cell</a>".</p>
                   6088: 
                   6089:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   6090:     formatting elements</a>.</p>
                   6091: 
                   6092:    </dd>
                   6093: 
                   6094:    <dt>An end tag whose tag name is "tr"</dt>
                   6095:    <dd>
                   6096: 
                   6097:     <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
                   6098:     scope</a> with the same tag name as the token, this is a
                   6099:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6100:     case</a>)</p>
                   6101: 
                   6102:     <p>Otherwise:</p>
                   6103: 
                   6104:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   6105:     context</a>. (See below.)</p>
                   6106: 
                   6107:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   6108:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   6109:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   6110:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   6111:     body</a>".</p>
                   6112: 
                   6113:    </dd>
                   6114: 
                   6115:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6116:    "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
                   6117:    <dt>An end tag whose tag name is "table"</dt>
                   6118:    <dd>
                   6119: 
                   6120:     <p>Act as if an end tag with the tag name "tr" had been seen,
                   6121:     then, if that token wasn't ignored, reprocess the current
                   6122:     token.</p>
                   6123: 
                   6124:     <p class="note">The fake end tag token here can only be
                   6125:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6126: 
                   6127:    </dd>
                   6128: 
                   6129:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   6130:    "thead"</dt>
                   6131:    <dd>
                   6132: 
                   6133:     <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
                   6134:     scope</a> with the same tag name as the token, this is a
                   6135:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   6136: 
                   6137:     <p>Otherwise, act as if an end tag with the tag name "tr" had
                   6138:     been seen, then reprocess the current token.</p>
                   6139: 
                   6140:    </dd>
                   6141: 
                   6142:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6143:    "col", "colgroup", "html", "td", "th"</dt>
                   6144:    <dd>
                   6145:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6146:    </dd>
                   6147: 
                   6148:    <dt>Anything else</dt>
                   6149:    <dd>
                   6150:     <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
                   6151:     mode</a>.</p>
                   6152:    </dd>
                   6153: 
                   6154:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
                   6155:   back to a table row context</dfn>, it means that the UA must,
                   6156:   while the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tr-element">tr</a></code>
1.159     mike     6157:   element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1       mike     6158:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6159: 
                   6160:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     6161:   <code><a href="semantics.html#the-html-element-0">html</a></code> element after this process is a <a href="#fragment-case">fragment
1.1       mike     6162:   case</a>.</p>
                   6163: 
                   6164: 
                   6165:   <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>
                   6166: 
                   6167:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
                   6168:   mode: in cell">in cell</a>", tokens must be handled as follows:</p>
                   6169: 
                   6170:   <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
                   6171:    <dd>
                   6172: 
                   6173:     <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
                   6174:     scope</a> with the same tag name as that of the token, then
                   6175:     this is a <a href="#parse-error">parse error</a> and the token must be
                   6176:     ignored.</p>
                   6177: 
                   6178:     <p>Otherwise:</p>
                   6179: 
                   6180:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   6181: 
                   6182:     <p>Now, if the <a href="#current-node">current node</a> is not an element
                   6183:     with the same tag name as the token, then this is a
                   6184:     <a href="#parse-error">parse error</a>.</p>
                   6185: 
                   6186:     <p>Pop elements from this stack until an element with the same
                   6187:     tag name as the token has been popped from the stack.</p>
                   6188: 
                   6189:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   6190:     the last marker</a>.</p>
                   6191: 
                   6192:     <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
                   6193:     <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
                   6194:     this point.)</p>
                   6195: 
                   6196:    </dd>
                   6197: 
                   6198:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6199:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   6200:    <dd>
                   6201: 
                   6202:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
                   6203:     <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
                   6204:     a <code>td</code> or <code>th</code> element in table
                   6205:     scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
                   6206:     the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6207: 
                   6208:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6209:     reprocess the current token.</p>
                   6210: 
                   6211:    </dd>
                   6212: 
                   6213:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6214:    "col", "colgroup", "html"</dt>
                   6215:    <dd>
                   6216:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6217:    </dd>
                   6218: 
                   6219:    <dt>An end tag whose tag name is one of: "table", "tbody",
                   6220:    "tfoot", "thead", "tr"</dt>
                   6221:    <dd>
                   6222: 
                   6223:     <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
                   6224:     scope</a> with the same tag name as that of the token
                   6225:     (which can only happen for "tbody", "tfoot" and "thead", or,
                   6226:     in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
                   6227:     error</a> and the token must be ignored.</p>
                   6228: 
                   6229:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6230:     reprocess the current token.</p>
                   6231: 
                   6232:    </dd>
                   6233: 
                   6234:    <dt>Anything else</dt>
                   6235:    <dd>
                   6236:     <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
                   6237:     mode</a>.</p>
                   6238:    </dd>
                   6239: 
                   6240:   </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
                   6241:   mean to run the following algorithm:</p>
                   6242: 
                   6243:   <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>
                   6244:    element in table scope</a>, then act as if an end tag token
                   6245:    with the tag name "td" had been seen.</p></li>
                   6246: 
                   6247:    <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
                   6248:    <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
                   6249:    <code>th</code> element in table scope</a>; act as if an end
                   6250:    tag token with the tag name "th" had been seen.</p></li>
                   6251: 
                   6252:   </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
                   6253:   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
                   6254:   the same time, nor can it have neither when the <a href="#insertion-mode">insertion
                   6255:   mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   6256:   cell</a>".</p>
                   6257: 
                   6258: 
                   6259:   <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>
                   6260: 
                   6261:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
                   6262:   mode: in select">in select</a>", tokens must be handled as follows:</p>
                   6263: 
                   6264:   <dl class="switch"><dt>A character token</dt>
                   6265:    <dd>
                   6266:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6267:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6268:    </dd>
                   6269: 
                   6270:    <dt>A comment token</dt>
                   6271:    <dd>
                   6272:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6273:     node</a> with the <code title="">data</code> attribute set to
                   6274:     the data given in the comment token.</p>
                   6275:    </dd>
                   6276: 
                   6277:    <dt>A DOCTYPE token</dt>
                   6278:    <dd>
                   6279:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6280:    </dd>
                   6281: 
                   6282:    <dt>A start tag whose tag name is "html"</dt>
                   6283:    <dd>
                   6284:     <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
                   6285:     mode</a>.</p>
                   6286:    </dd>
                   6287: 
                   6288:    <dt>A start tag whose tag name is "option"</dt>
                   6289:    <dd>
                   6290: 
                   6291:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6292:     element, act as if an end tag with the tag name "option" had
                   6293:     been seen.</p>
                   6294: 
                   6295:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6296: 
                   6297:    </dd>
                   6298: 
                   6299:    <dt>A start tag whose tag name is "optgroup"</dt>
                   6300:    <dd>
                   6301: 
                   6302:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6303:     element, act as if an end tag with the tag name "option" had
                   6304:     been seen.</p>
                   6305: 
                   6306:     <p>If the <a href="#current-node">current node</a> is an
                   6307:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
                   6308:     tag name "optgroup" had been seen.</p>
                   6309: 
                   6310:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6311: 
                   6312:    </dd>
                   6313: 
                   6314:    <dt>An end tag whose tag name is "optgroup"</dt>
                   6315:    <dd>
                   6316: 
                   6317:     <p>First, if the <a href="#current-node">current node</a> is an
                   6318:     <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
                   6319:     it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
                   6320:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
                   6321:     the tag name "option" had been seen.</p>
                   6322: 
                   6323:     <p>If the <a href="#current-node">current node</a> is an
                   6324:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
                   6325:     <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
                   6326:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   6327: 
                   6328:    </dd>
                   6329: 
                   6330:    <dt>An end tag whose tag name is "option"</dt>
                   6331:    <dd>
                   6332: 
                   6333:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6334:     element, then pop that node from the <a href="#stack-of-open-elements">stack of open
                   6335:     elements</a>. Otherwise, this is a <a href="#parse-error">parse
                   6336:     error</a>; ignore the token.</p>
                   6337: 
                   6338:    </dd>
                   6339: 
                   6340:    <dt>An end tag whose tag name is "select"</dt>
                   6341:    <dd>
                   6342: 
                   6343:     <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
                   6344:     scope</a> with the same tag name as the token, this is a
                   6345:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6346:     case</a>)</p>
                   6347: 
                   6348:     <p>Otherwise:</p>
                   6349: 
                   6350:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   6351:     until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
                   6352:     stack.</p>
                   6353: 
                   6354:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   6355: 
                   6356:    </dd>
                   6357: 
                   6358:    <dt>A start tag whose tag name is "select"</dt>
                   6359:    <dd>
                   6360: 
                   6361:     <p><a href="#parse-error">Parse error</a>. Act as if the token had been
                   6362:     an end tag with the tag name "select" instead.</p>
                   6363: 
                   6364:    </dd>
                   6365: 
                   6366:    <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
                   6367:    <dd>
1.73      mike     6368: 
                   6369:     <p><a href="#parse-error">Parse error</a>.</p>
                   6370: 
1.124     mike     6371:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a <code>select</code>
                   6372:     element in table scope</a>, ignore the token. (<a href="#fragment-case">fragment
                   6373:     case</a>)</p>
1.73      mike     6374: 
                   6375:     <p>Otherwise, act as if an end tag with the tag name "select" had
                   6376:     been seen, and reprocess the token.</p>
                   6377: 
1.1       mike     6378:    </dd>
                   6379: 
                   6380:    <dt>A start tag token whose tag name is "script"</dt>
                   6381:    <dd>
                   6382:     <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
                   6383:     mode</a>.</p>
                   6384:    </dd>
                   6385: 
                   6386:    <dt>An end-of-file token</dt>
                   6387:    <dd>
                   6388: 
                   6389:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     6390:     <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1       mike     6391:     error</a>.</p>
                   6392: 
                   6393:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6394:     the <a href="#fragment-case">fragment case</a>.</p>
                   6395: 
                   6396:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6397: 
                   6398:    </dd>
                   6399: 
                   6400:    <dt>Anything else</dt>
                   6401:    <dd>
                   6402:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6403:    </dd>
                   6404: 
                   6405:   </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>
                   6406: 
                   6407:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
                   6408:   mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
                   6409: 
                   6410:   <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
                   6411:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6412:    <dd>
                   6413:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   6414:     name "select" had been seen, and reprocess the token.</p>
                   6415:    </dd>
                   6416: 
                   6417:    <dt>An end tag whose tag name is one of: "caption", "table",
                   6418:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6419:    <dd>
                   6420: 
                   6421:     <p><a href="#parse-error">Parse error</a>.</p>
                   6422: 
                   6423:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
                   6424:     element in table scope</a> with the same tag name as that
                   6425:     of the token, then act as if an end tag with the tag name
                   6426:     "select" had been seen, and reprocess the token. Otherwise,
                   6427:     ignore the token.</p>
                   6428: 
                   6429:    </dd>
                   6430: 
                   6431:    <dt>Anything else</dt>
                   6432:    <dd>
                   6433:     <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
                   6434:     mode</a>.</p>
                   6435:    </dd>
                   6436: 
1.168     mike     6437:   </dl><h5 id="parsing-main-inforeign"><span class="secno">9.2.5.21 </span>The "<dfn title="insertion mode: in foreign content">in foreign content</dfn>" insertion mode</h5>
1.1       mike     6438: 
                   6439:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
                   6440:   mode: in foreign content">in foreign content</a>", tokens must be
                   6441:   handled as follows:</p>
                   6442: 
                   6443:   <dl class="switch"><dt>A character token</dt>
                   6444:    <dd>
                   6445: 
                   6446:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6447:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6448: 
                   6449:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   6450:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   6451:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   6452:     flag</a> to "not ok".</p>
                   6453: 
                   6454:    </dd>
                   6455: 
                   6456:    <dt>A comment token</dt>
                   6457:    <dd>
                   6458:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6459:     node</a> with the <code title="">data</code> attribute set to
                   6460:     the data given in the comment token.</p>
                   6461:    </dd>
                   6462: 
                   6463:    <dt>A DOCTYPE token</dt>
                   6464:    <dd>
                   6465:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6466:    </dd>
                   6467: 
                   6468:    <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>
                   6469:    <dd>
                   6470: 
                   6471:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6472:     elements</a>.</p>
                   6473: 
                   6474:     <p>Let the <var title="">old insertion point</var> have the
                   6475:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   6476:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   6477:     input character</a>.</p>
                   6478: 
                   6479:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6480:     one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
                   6481: 
                   6482:     <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
                   6483:     the <code title="">script</code> element</a> according to the SVG
1.187     mike     6484:     rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
1.1       mike     6485: 
1.159     mike     6486:     <p class="note">Even if this causes <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters to be inserted into the
1.1       mike     6487:     tokenizer</a>, the parser will not be executed reentrantly,
                   6488:     since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
                   6489: 
                   6490:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6491:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   6492:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   6493: 
                   6494:     <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
                   6495:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   6496:     might be the "undefined" value.)</p>
                   6497: 
                   6498:    </dd>
                   6499: 
                   6500:    <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>
                   6501:    <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>
                   6502:    <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>
                   6503:    <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>
                   6504:    <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>
                   6505:    <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>
                   6506:    <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>
                   6507:    <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>
                   6508:    <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>
                   6509:    <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>
                   6510:    <dt>An end tag</dt>
                   6511:    <dd>
                   6512: 
                   6513:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
                   6514:     <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6515: 
                   6516:     <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
                   6517:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   6518:     content</a>", but there is no element in scope that has a
                   6519:     namespace other than the <a href="#html-namespace-0">HTML namespace</a><!-- XXX this
                   6520:     isn't well-defined; it means check to see if the bottom-most HTML
                   6521:     element on the stack is in scope -->, switch the <a href="#insertion-mode">insertion
                   6522:     mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6523: 
                   6524:    </dd>
                   6525: 
                   6526:    <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
                   6527:    "blockquote", "body"<!--by inspection-->, "br", "center", "code",
                   6528:    "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
                   6529:    uniformly throughout the parser -->, "em", "embed", "h1", "h2",
                   6530:    "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
                   6531:    completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
                   6532:    "li", "listing"<!-- so that pre and listing can be handled
                   6533:    uniformly throughout the parser -->, "menu", "meta", "nobr",
                   6534:    "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
                   6535:    the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
                   6536:    "span", "strong", "strike"<!-- so that s and strike can be handled
                   6537:    uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
                   6538:    "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt>
                   6539:    <!-- this list was determined empirically by studying over
                   6540:    6,000,000,000 pages that were specifically not XML pages -->
                   6541:    <dt>A start tag whose tag name is "font", if the token has
                   6542:    any attributes named "color", "face", or "size"</dt>
                   6543:    <!-- the attributes here are required so that SVG <font> will go
                   6544:    through as SVG but legacy <font>s won't -->
                   6545:    <dt>An end-of-file token</dt>
                   6546:    <dd>
                   6547: 
                   6548:     <p><a href="#parse-error">Parse error</a>.</p>
                   6549: 
                   6550:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
                   6551:     the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
                   6552:     namespace</a>.</p>
                   6553: 
                   6554:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
                   6555:     insertion mode</a>, and reprocess the token.</p>
                   6556: 
                   6557:    </dd>
                   6558: 
                   6559:    <dt>Any other start tag</dt>
                   6560:    <dd>
                   6561: 
                   6562:     <p>If the <a href="#current-node">current node</a> is an element in the
                   6563:     <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
                   6564:     attributes</a> for the token. (This fixes the case of MathML
                   6565:     attributes that are not all lowercase.)</p>
                   6566: 
                   6567:     <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6568:     namespace</a>, and the token's tag name is one of the ones in
                   6569:     the first column of the following table, change the tag name to
                   6570:     the name given in the corresponding cell in the second
                   6571:     column. (This fixes the case of SVG elements that are not all
                   6572:     lowercase.)</p>
                   6573: 
                   6574:     <table><thead><tr><th> Tag name </th><th> Element name
                   6575:      </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
                   6576:       </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
                   6577:       </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
                   6578:       </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
                   6579:       </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
                   6580:       </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
                   6581:       </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
                   6582:       </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
                   6583:       </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
                   6584:       </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
                   6585:       </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
                   6586:       </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
                   6587:       </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
                   6588:       </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
                   6589:       </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
                   6590:       </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
                   6591:       </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
                   6592:       </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
                   6593:       </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
                   6594:       </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
                   6595:       </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
                   6596:       </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
                   6597:       </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
                   6598:       </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
                   6599:       </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
                   6600:       </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
                   6601:       </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
                   6602:       </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
                   6603:       </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
                   6604:       </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
                   6605:       </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
                   6606:       </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
                   6607:       </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   6608:       </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
                   6609:       </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
                   6610:       <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
                   6611:       </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
                   6612:     </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6613:     namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
                   6614:     token. (This fixes the case of SVG attributes that are not all
                   6615:     lowercase.)</p>
                   6616: 
                   6617:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   6618:     fixes the use of namespaced attributes, in particular XLink in
                   6619:     SVG.)</p>
                   6620: 
                   6621:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   6622:     same namespace as the <a href="#current-node">current node</a>.</p>
                   6623: 
                   6624:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   6625:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6626:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   6627:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   6628: 
                   6629:    </dd>
                   6630: 
                   6631:   </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>
                   6632: 
                   6633:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
                   6634:   mode: after body">after body</a>", tokens must be handled as follows:</p>
                   6635: 
                   6636:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6637:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6638:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6639:    <dd>
                   6640:     <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
                   6641:     mode</a>.</p>
                   6642:    </dd>
                   6643: 
                   6644:    <dt>A comment token</dt>
                   6645:    <dd>
                   6646:     <p>Append a <code>Comment</code> node to the first element in
1.159     mike     6647:     the <a href="#stack-of-open-elements">stack of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1       mike     6648:     element), with the <code title="">data</code> attribute set to
                   6649:     the data given in the comment token.</p>
                   6650:    </dd>
                   6651: 
                   6652:    <dt>A DOCTYPE token</dt>
                   6653:    <dd>
                   6654:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6655:    </dd>
                   6656: 
                   6657:    <dt>A start tag whose tag name is "html"</dt>
                   6658:    <dd>
                   6659:     <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
                   6660:     mode</a>.</p>
                   6661:    </dd>
                   6662: 
                   6663:    <dt>An end tag whose tag name is "html"</dt>
                   6664:    <dd>
                   6665: 
                   6666:     <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
                   6667:     fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
                   6668:     error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6669: 
                   6670:     <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
                   6671:     body</a>".</p>
                   6672: 
                   6673:    </dd>
                   6674: 
                   6675:    <dt>An end-of-file token</dt>
                   6676:    <dd>
                   6677:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6678:    </dd>
                   6679: 
                   6680:    <dt>Anything else</dt>
                   6681:    <dd>
                   6682: 
                   6683:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
                   6684:     mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   6685:     body</a>" and reprocess the token.</p>
                   6686: 
                   6687:    </dd>
                   6688: 
                   6689:   </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>
                   6690: 
                   6691:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
                   6692:   mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
                   6693: 
                   6694:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6695:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6696:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6697:    <dd>
                   6698:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6699:     the <a href="#current-node">current node</a>.</p>
                   6700:    </dd>
                   6701: 
                   6702:    <dt>A comment token</dt>
                   6703:    <dd>
                   6704:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6705:     node</a> with the <code title="">data</code> attribute set to
                   6706:     the data given in the comment token.</p>
                   6707:    </dd>
                   6708: 
                   6709:    <dt>A DOCTYPE token</dt>
                   6710:    <dd>
                   6711:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6712:    </dd>
                   6713: 
                   6714:    <dt>A start tag whose tag name is "html"</dt>
                   6715:    <dd>
                   6716:     <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
                   6717:     mode</a>.</p>
                   6718:    </dd>
                   6719: 
                   6720:    <dt>A start tag whose tag name is "frameset"</dt>
                   6721:    <dd>
                   6722:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6723:    </dd>
                   6724: 
                   6725:    <dt>An end tag whose tag name is "frameset"</dt>
                   6726:    <dd>
                   6727: 
                   6728:     <p>If the <a href="#current-node">current node</a> is the root
1.159     mike     6729:     <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1       mike     6730:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   6731:     case</a>)</p>
                   6732: 
                   6733:     <p>Otherwise, pop the <a href="#current-node">current node</a> from the
                   6734:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6735: 
                   6736:     <p>If the parser was <em>not</em> originally created as part
                   6737:     of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
                   6738:     (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5       mike     6739:     node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1       mike     6740:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
                   6741:     frameset</a>".</p>
                   6742: 
                   6743:    </dd>
                   6744: 
                   6745:    <dt>A start tag whose tag name is "frame"</dt>
                   6746:    <dd>
                   6747: 
                   6748:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
                   6749:     Immediately pop the <a href="#current-node">current node</a> off the
                   6750:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6751: 
                   6752:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   6753:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   6754: 
                   6755:    </dd>
                   6756: 
                   6757:    <dt>A start tag whose tag name is "noframes"</dt>
                   6758:    <dd>
                   6759:     <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
                   6760:     mode</a>.</p>
                   6761:    </dd>
                   6762: 
                   6763:    <dt>An end-of-file token</dt>
                   6764:    <dd>
                   6765: 
                   6766:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     6767:     <code><a href="semantics.html#the-html-element-0">html</a></code> element, then this is a <a href="#parse-error">parse
1.1       mike     6768:     error</a>.</p>
                   6769: 
                   6770:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6771:     the <a href="#fragment-case">fragment case</a>.</p>
                   6772: 
                   6773:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6774: 
                   6775:    </dd>
                   6776: 
                   6777:    <dt>Anything else</dt>
                   6778:    <dd>
                   6779:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6780:    </dd>
                   6781: 
                   6782:   </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>
                   6783: 
                   6784:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
                   6785:   mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
                   6786: 
                   6787:   <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
                   6788:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6789:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6790:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6791:    <dd>
                   6792:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6793:     the <a href="#current-node">current node</a>.</p>
                   6794:    </dd>
                   6795: 
                   6796:    <dt>A comment token</dt>
                   6797:    <dd>
                   6798:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6799:     node</a> with the <code title="">data</code> attribute set to
                   6800:     the data given in the comment token.</p>
                   6801:    </dd>
                   6802: 
                   6803:    <dt>A DOCTYPE token</dt>
                   6804:    <dd>
                   6805:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6806:    </dd>
                   6807: 
                   6808:    <dt>A start tag whose tag name is "html"</dt>
                   6809:    <dd>
                   6810:     <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
                   6811:     mode</a>.</p>
                   6812:    </dd>
                   6813: 
                   6814:    <dt>An end tag whose tag name is "html"</dt>
                   6815:    <dd>
                   6816:     <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
                   6817:     frameset</a>".</p>
                   6818:    </dd>
                   6819: 
                   6820:    <dt>A start tag whose tag name is "noframes"</dt>
                   6821:    <dd>
                   6822:     <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
                   6823:     mode</a>.</p>
                   6824:    </dd>
                   6825: 
                   6826:    <dt>An end-of-file token</dt>
                   6827:    <dd>
                   6828:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6829:    </dd>
                   6830: 
                   6831:    <dt>Anything else</dt>
                   6832:    <dd>
                   6833:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6834:    </dd>
                   6835: 
                   6836:   </dl><p class="XXX">This doesn't handle UAs that don't support
                   6837:   frames, or that do support frames but want to show the NOFRAMES
                   6838:   content. Supporting the former is easy; supporting the latter is
                   6839:   harder.</p>
                   6840: 
                   6841: 
                   6842:   <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>
                   6843: 
                   6844:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
                   6845:   mode: after after body">after after body</a>", tokens must be handled as follows:</p>
                   6846: 
                   6847:   <dl class="switch"><dt>A comment token</dt>
                   6848:    <dd>
                   6849:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   6850:     object with the <code title="">data</code> attribute set to the
                   6851:     data given in the comment token.</p>
                   6852:    </dd>
                   6853: 
                   6854:    <dt>A DOCTYPE token</dt>
                   6855:    <dt>A character token that is one of U+0009 CHARACTER
                   6856:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6857:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6858:    <dt>A start tag whose tag name is "html"</dt>
                   6859:    <dd>
                   6860:     <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
                   6861:     mode</a>.</p>
                   6862:    </dd>
                   6863: 
                   6864:    <dt>An end-of-file token</dt>
                   6865:    <dd>
                   6866:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6867:    </dd>
                   6868: 
                   6869:    <dt>Anything else</dt>
                   6870:    <dd>
                   6871:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   6872:     to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
                   6873:     reprocess the token.</p>
                   6874:    </dd>
                   6875: 
                   6876:   </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>
                   6877: 
                   6878:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
                   6879:   mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
                   6880: 
                   6881:   <dl class="switch"><dt>A comment token</dt>
                   6882:    <dd>
                   6883:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   6884:     object with the <code title="">data</code> attribute set to the
                   6885:     data given in the comment token.</p>
                   6886:    </dd>
                   6887: 
                   6888:    <dt>A DOCTYPE token</dt>
                   6889:    <dt>A character token that is one of U+0009 CHARACTER
                   6890:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6891:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6892:    <dt>A start tag whose tag name is "html"</dt>
                   6893:    <dd>
                   6894:     <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
                   6895:     mode</a>.</p>
                   6896:    </dd>
                   6897: 
                   6898:    <dt>An end-of-file token</dt>
                   6899:    <dd>
                   6900:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6901:    </dd>
                   6902: 
                   6903:    <dt>A start tag whose tag name is "noframes"</dt>
                   6904:    <dd>
                   6905:     <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
                   6906:     mode</a>.</p>
                   6907:    </dd>
                   6908: 
                   6909:    <dt>Anything else</dt>
                   6910:    <dd>
                   6911:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6912:    </dd>
                   6913: 
1.266     mike     6914:   </dl></div><div class="impl">
                   6915: 
                   6916:   <h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4>
1.1       mike     6917: 
                   6918:   <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
                   6919:   the document, the user agent must follow the steps in this
                   6920:   section.</p>
                   6921: 
1.10      mike     6922:   <!-- this happens as part of one of the tasks that runs the parser -->
1.1       mike     6923: 
1.10      mike     6924:   <p>First, the user agent must set the <a href="dom.html#current-document-readiness">current document
                   6925:   readiness</a> to "interactive" and the <a href="#insertion-point">insertion
                   6926:   point</a> to undefined.</p>
                   6927: 
                   6928:   <p>Then, the user agent must then make a list of all the scripts
                   6929:   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
                   6930:   document has finished parsing</a>, the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that
                   6931:   will execute asynchronously</a>, and the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts
                   6932:   that will execute as soon as possible</a>. This is the <dfn id="list-of-scripts-pending-after-the-parser-stopped">list
                   6933:   of scripts pending after the parser stopped</dfn>.</p>
                   6934: 
                   6935:   <p>The rules for <a href="semantics.html#when-a-script-completes-loading">when a script completes loading</a> start
                   6936:   applying (script execution is no longer managed by the parser).</p>
1.1       mike     6937: 
                   6938:   <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
                   6939:   execute as soon as possible</a> have <a href="semantics.html#completed-loading">completed
                   6940:   loading</a>, or if the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that will execute
                   6941:   asynchronously</a> is not empty and the first script in that list
                   6942:   has <a href="semantics.html#completed-loading">completed loading</a>, then the user agent must act as
                   6943:   if those scripts just completed loading, following the rules given
                   6944:   for that in the <code><a href="semantics.html#script">script</a></code> element definition.</p>
                   6945: 
1.10      mike     6946:   <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
                   6947:   has finished parsing</a> is not empty, and the first item in this
                   6948:   list has already <a href="semantics.html#completed-loading">completed loading</a>, then the user agent
                   6949:   must act as if that script just finished loading.</p>
                   6950: 
                   6951:   <p class="note">By this point, there will be no scripts that have
                   6952:   loaded but have not yet been executed.</p>
                   6953: 
                   6954:   <hr><!-- async --><p>Once all the scripts on the <a href="#list-of-scripts-pending-after-the-parser-stopped">list of scripts pending after
                   6955:   the parser stopped</a> have <a href="semantics.html#completed-loading">completed loading</a> and
                   6956:   been <a href="semantics.html#executing-a-script-block" title="executing a script block">executed</a>, the
                   6957:   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
                   6958:   event</a> called <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
                   6959:   <code>Document</code>. (If the list is empty, this happens
                   6960:   immediately.)</p>
1.1       mike     6961: 
1.10      mike     6962:   <hr><!-- async --><p>Once everything that <dfn id="delay-the-load-event" title="delay the load event">delays the
1.1       mike     6963:   load event</dfn> of the document has completed, the user agent must
                   6964:   run the following steps:</p>
                   6965: 
                   6966:   <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
                   6967:    readiness</a> to "complete".</li>
                   6968: 
                   6969:    <li>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
                   6970:    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
                   6971:    simple event</a> called <code title="event-load"><a href="video.html#event-load">load</a></code> at
                   6972:    the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
                   6973:    its <code title="dom-event-target">target</code> set to the
                   6974:    <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
                   6975:    <code><a href="browsers.html#window">Window</a></code> object).</li>
                   6976: 
                   6977:    <li>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
                   6978:    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
                   6979:    <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
                   6980:    <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
                   6981:    current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
                   6982:    must bubble but not be cancelable and has no default action.</li>
                   6983: 
1.228     mike     6984:   </ol><p>The <a href="browsers.html#task-source">task source</a> for these <span title="concept-tasks">tasks</span> is the <a href="browsers.html#dom-manipulation-task-source">DOM manipulation
                   6985:   task source</a>.</p>
1.1       mike     6986: 
                   6987:   <!-- XXX make sure things "delay the load event", e.g. applet and
                   6988:   object element's frame contents -->
                   6989: 
                   6990:   <p class="XXX">delaying the load event for things like image
                   6991:   loads allows for intranet port scans (even without
                   6992:   javascript!). Should we really encode that into the spec?</p>
                   6993: 
                   6994: 
                   6995: <!--XXX need to handle
                   6996: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#2354
                   6997: 2354           // Don't open transient styles if it makes the stack deep, bug 58917.
                   6998: -->
                   6999: 
                   7000: <!--XXX
                   7001: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/nsHTMLTokenizer.cpp#749
                   7002: -->
                   7003: 
                   7004: <!--
                   7005: see also  CTextToken::ConsumeCharacterData()  for CDATA parsing?
                   7006: 
                   7007: 1212                      1  Here's a tricky case from bug 22596:  <h5><li><h5>
                   7008: 1213                         How do we know that the 2nd <h5> should close the <LI> rather than nest inside the <LI>?
                   7009: 1214                         (Afterall, the <h5> is a legal child of the <LI>).
                   7010: 1215
                   7011: 1216                         The way you know is that there is no root between the two, so the <h5> binds more
                   7012: 1217                         tightly to the 1st <h5> than to the <LI>.
                   7013: 1218                      2. Also, bug 6148 shows this case: <SPAN><DIV><SPAN>
                   7014: 1219                         From this case we learned not to execute this logic if the parent is a block.
                   7015: 1220
                   7016: 1221                      3. Fix for 26583
                   7017: 1222                         Ex. <A href=foo.html><B>foo<A href-bar.html>bar</A></B></A>  <- A legal HTML
                   7018: 1223                         In the above example clicking on "foo" or "bar" should link to
                   7019: 1224                         foo.html or bar.html respectively. That is, the inner <A> should be informed
                   7020: 1225                         about the presence of an open <A> above <B>..so that the inner <A> can close out
                   7021: 1226                         the outer <A>. The following code does it for us.
                   7022: 1227
                   7023: 1228                      4. Fix for 27865 [ similer to 22596 ]. Ex: <DL><DD><LI>one<DD><LI>two
                   7024:  - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1211
                   7025: 
                   7026: 815             // Here's a problem.  If theTag is legal in here, we don't move it
                   7027: 816             // out.  So if we're moving stuff out of here, the parent of theTag
                   7028: 817             // gets closed at this point.  But some things are legal
                   7029: 818             // _everywhere_ and hence would effectively close out misplaced
                   7030: 819             // content in tables.  This is undesirable, so treat them as
                   7031: 820             // illegal here so they'll be shipped out with their parents and
                   7032: 821             // siblings.  See bug 40855 for an explanation (that bug was for
                   7033: 822             // comments, but the same issues arise with whitespace, newlines,
                   7034: 823             // noscript, etc).  Script is special, though.  Shipping it out
                   7035: 824             // breaks document.write stuff.  See bug 243064.
                   7036:  - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#825
                   7037: 
                   7038: 
                   7039: 1326     /**************************************************************************************
                   7040: 1327      *
                   7041: 1328      * Now a little code to deal with bug #49687 (crash when layout stack gets too deep)
                   7042: 1329      * I've also opened this up to any container (not just inlines): re bug 55095
                   7043: 1330      * Improved to handle bug 55980 (infinite loop caused when DEPTH is exceeded and
                   7044: 1331      * </P> is encountered by itself (<P>) is continuously produced.
                   7045: 1332      *
                   7046: 1333      **************************************************************************************/
                   7047: 
                   7048: 1912               // Oh boy!! we found a "stray" tag. Nav4.x and IE introduce line break in
                   7049: 1913               // such cases. So, let's simulate that effect for compatibility.
                   7050: 1914               // Ex. <html><body>Hello</P>There</body></html>
                   7051: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1912
                   7052: 
                   7053: http://lxr.mozilla.org/seamonkey/search?string=nested
                   7054: /parser/htmlparser/src/CNavDTD.cpp, line 791 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
                   7055: /parser/htmlparser/src/CNavDTD.cpp, line 792 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
                   7056: /parser/htmlparser/src/CNavDTD.cpp, line 2562 - // Discard nested forms - bug 72639
                   7057: /parser/htmlparser/src/nsElementTable.cpp, line 1453 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
                   7058: /parser/htmlparser/src/nsElementTable.cpp, line 1454 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
                   7059: /parser/htmlparser/src/nsElementTable.cpp, line 1901 - // Ex: <H1><LI><H1><LI>. Inner LI has the potential of getting nested
                   7060: -->
                   7061: 
1.266     mike     7062:   </div><div class="impl">
1.1       mike     7063: 
                   7064:   <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4>
                   7065: 
                   7066:   <p>When an application uses an <a href="#html-parser">HTML parser</a> in
                   7067:   conjunction with an XML pipeline, it is possible that the
                   7068:   constructed DOM is not compatible with the XML tool chain in certain
                   7069:   subtle ways. For example, an XML toolchain might not be able to
                   7070:   represent attributes with the name <code title="">xmlns</code>,
                   7071:   since they conflict with the Namespaces in XML syntax. There is also
                   7072:   some data that the <a href="#html-parser">HTML parser</a> generates that isn't
                   7073:   included in the DOM itself. This section specifies some rules for
                   7074:   handling these issues.</p>
                   7075: 
                   7076:   <p>If the XML API being used doesn't support DOCTYPEs, the tool may
                   7077:   drop DOCTYPEs altogether.</p>
                   7078: 
                   7079:   <p>If the XML API doesn't support attributes in no namespace that
                   7080:   are named "<code title="">xmlns</code>", attributes whose names
                   7081:   start with "<code title="">xmlns:</code>", or attributes in the
                   7082:   <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
                   7083:   attributes.</p>
                   7084: 
                   7085:   <p>The tool may annotate the output with any namespace declarations
                   7086:   required for proper operation.</p>
                   7087: 
                   7088:   <p>If the XML API being used restricts the allowable characters in
                   7089:   the local names of elements and attributes, then the tool may map
                   7090:   all element and attribute local names that the API wouldn't support
                   7091:   to a set of names that <em>are</em> allowed, by replacing any
                   7092:   character that isn't supported with the uppercase letter U and the
                   7093:   six digits of the character's Unicode code point when expressed in
                   7094:   hexadecimal, using digits 0-9 and capital letters A-F as the
                   7095:   symbols, in increasing numeric order.</p>
                   7096: 
                   7097:   <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
                   7098:   parser</a>, though it is neither a legal HTML element name nor a
                   7099:   well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
                   7100:   element name (though it's still not legal in HTML by any means).</p>
                   7101: 
                   7102:   <p class="example">As another example, consider the attribute
                   7103:   <code>xlink:href</code>. Used on a MathML element, it becomes, after
                   7104:   being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
                   7105:   attribute with a prefix "<code title="">xlink</code>" and a local
                   7106:   name "<code title="">href</code>". However, used on an HTML element,
                   7107:   it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
                   7108:   might not be accepted by an XML API. It could thus get converted,
                   7109:   becoming "<code title="">xlinkU00003Ahref</code>".</p>
                   7110: 
                   7111:   <p class="note">The resulting names from this conversion
                   7112:   conveniently can't clash with any attribute generated by the
                   7113:   <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
                   7114:   those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
                   7115:   algorithm's table.</p>
                   7116: 
                   7117:   <p>If the XML API restricts comments from having two consecutive
                   7118:   U+002D HYPHEN-MINUS characters (--), the tool may insert a single
                   7119:   U+0020 SPACE character between any such offending characters.</p>
                   7120: 
                   7121:   <p>If the XML API restricts comments from ending in a
                   7122:   U+002D HYPHEN-MINUS character (-), the tool may insert a single
                   7123:   U+0020 SPACE character at the end of such comments.</p>
                   7124: 
                   7125:   <p>If the XML API restricts allowed characters in character data,
                   7126:   the tool may replace any U+000C FORM FEED (FF) character with a
                   7127:   U+0020 SPACE character, and any other literal non-XML character with
                   7128:   a U+FFFD REPLACEMENT CHARACTER.</p>
                   7129: 
                   7130:   <p>If the tool has no way to convey out-of-band information, then
                   7131:   the tool may drop the following information:</p>
                   7132: 
                   7133:   <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
                   7134:    <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>
                   7135: 
                   7136:    <li>The association between form controls and forms that aren't
                   7137:    their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
                   7138:    <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
                   7139: 
                   7140:   </ul><p class="note">The mutations allowed by this section apply
                   7141:   <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
                   7142:   applied. For example, a <code title="">&lt;a::&gt;</code> start tag
                   7143:   will be closed by a <code title="">&lt;/a::&gt;</code> end tag, and
                   7144:   never by a <code title="">&lt;/aU00003AU00003A&gt;</code> end tag, even
                   7145:   if the user agent is using the rules above to then generate an
                   7146:   actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
                   7147: 
1.266     mike     7148:   </div><div class="impl">
1.1       mike     7149: 
1.35      mike     7150:   <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     7151: 
                   7152:   <p><i>This section is non-normative.</i></p>
                   7153: 
                   7154:   <p>This section examines some erroneous markup and discusses how
                   7155:   the <a href="#html-parser">HTML parser</a> handles these cases.</p>
                   7156: 
                   7157: 
                   7158:   <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>
                   7159: 
                   7160:   <p><i>This section is non-normative.</i></p>
                   7161: 
                   7162:   <p>The most-often discussed example of erroneous markup is as
                   7163:   follows:</p>
                   7164: 
                   7165:   <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>
                   7166: 
                   7167:   <p>The parsing of this markup is straightforward up to the "3". At
                   7168:   this point, the DOM looks like this:</p>
                   7169: 
1.159     mike     7170:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>Here, the <a href="#stack-of-open-elements">stack of open elements</a> has five elements
                   7171:   on it: <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>,
1.1       mike     7172:   <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
                   7173:   formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
                   7174:   <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>
                   7175: 
                   7176:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
                   7177:   invoked. This is a simple case, in that the <var title="">formatting
                   7178:   element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
                   7179:   <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
1.159     mike     7180:   elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element-0">html</a></code>,
                   7181:   <code><a href="semantics.html#the-body-element-0">body</a></code>, and <code><a href="semantics.html#the-p-element">p</a></code>, while the <a href="#list-of-active-formatting-elements">list of
1.1       mike     7182:   active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
                   7183:   DOM tree is unmodified at this point.</p>
                   7184: 
                   7185:   <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
                   7186:   the active formatting elements</a>, in this case just the
                   7187:   <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
                   7188:   for the "4" text node. After the end tag token for the "i" is also
                   7189:   received, and the "5" text node is inserted, the DOM looks as
                   7190:   follows:</p>
                   7191: 
1.159     mike     7192:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">4</span></li></ul></li><li class="t3"><code>#text</code>: <span title="">5</span></li></ul></li></ul></li></ul></li></ul><h5 id="misnested-tags:-b-p-b-p"><span class="secno">9.2.8.2 </span>Misnested tags: &lt;b&gt;&lt;p&gt;&lt;/b&gt;&lt;/p&gt;</h5>
1.1       mike     7193: 
                   7194:   <p><i>This section is non-normative.</i></p>
                   7195: 
                   7196:   <p>A case similar to the previous one is the following:</p>
                   7197: 
                   7198:   <pre>&lt;b&gt;1&lt;p&gt;2&lt;/b&gt;3&lt;/p&gt;</pre>
                   7199: 
                   7200:   <p>Up to the "2" the parsing here is straightforward:</p>
                   7201: 
1.159     mike     7202:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>The interesting part is when the end tag token with the tag name
1.1       mike     7203:   "b" is parsed.</p>
                   7204: 
                   7205:   <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
1.159     mike     7206:   elements</a> has four elements on it: <code><a href="semantics.html#the-html-element-0">html</a></code>,
                   7207:   <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="text-level-semantics.html#the-b-element">b</a></code>, and <code><a href="semantics.html#the-p-element">p</a></code>. The
1.1       mike     7208:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
                   7209:   <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>
                   7210: 
                   7211:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
                   7212:   in the previous example. However, in this case, there <em>is</em> a
                   7213:   <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
                   7214:   this time the adoption agency algorithm isn't skipped over.</p>
                   7215: 
1.159     mike     7216:   <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1       mike     7217:   element. A conceptual "bookmark" marks the position of the
                   7218:   <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
                   7219:   elements</a>, but since that list has only one element in it,
                   7220:   it won't have much effect.</p>
                   7221: 
                   7222:   <p>As the algorithm progresses, <var title="">node</var> ends up set
                   7223:   to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
                   7224:   node</var> ends up set to the <var title="">furthest block</var>
                   7225:   (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7226: 
                   7227:   <p>The <var title="">last node</var> gets appended (moved) to the
                   7228:   <var title="">common ancestor</var>, so that the DOM looks like:</p>
                   7229: 
1.159     mike     7230:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul><p>A new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created, and the children of the
1.1       mike     7231:   <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
                   7232: 
1.159     mike     7233:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code></li></ul></li></ul></li></ul><ul class="domTree"><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul><p>Finally, the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is appended to the
1.1       mike     7234:   <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
                   7235: 
1.159     mike     7236:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>The <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is removed from the <a href="#list-of-active-formatting-elements">list of
1.1       mike     7237:   active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
                   7238:   elements</a>, so that when the "3" is parsed, it is appended to
                   7239:   the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
                   7240: 
1.159     mike     7241:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li></ul></li></ul><h5 id="unexpected-markup-in-tables"><span class="secno">9.2.8.3 </span>Unexpected markup in tables</h5>
1.1       mike     7242: 
                   7243:   <p><i>This section is non-normative.</i></p>
                   7244: 
                   7245:   <p>Error handling in tables is, for historical reasons, especially
                   7246:   strange. For example, consider the following markup:</p>
                   7247: 
                   7248:   <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>
                   7249: 
                   7250:   <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
                   7251:   directly inside a table like that, and the parser handles this case
                   7252:   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
                   7253:   examining the DOM tree as it stands just after the
                   7254:   <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
                   7255: 
1.159     mike     7256:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code></li></ul></li></ul></li></ul><p>...and then immediately after the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start
1.1       mike     7257:   tag has been seen:</p>
                   7258: 
1.159     mike     7259:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code></li></ul></li></ul></li></ul><p>At this point, the <a href="#stack-of-open-elements">stack of open elements</a> has on it
                   7260:   the elements <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>,
1.1       mike     7261:   <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
                   7262:   resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
                   7263:   elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
                   7264:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
                   7265:   table">in table</a>".</p>
                   7266: 
                   7267:   <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
                   7268:   to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
                   7269:   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
                   7270:   then handled in a rather straight-forward manner, taking the parser
                   7271:   through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   7272:   body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   7273:   row</a>" insertion modes, after which the DOM looks as
                   7274:   follows:</p>
                   7275: 
1.159     mike     7276:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code></li></ul></li></ul></li></ul></li></ul></li></ul><p>Here, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
                   7277:   elements <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
1.1       mike     7278:   <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
                   7279:   formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
                   7280:   it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   7281:   mode: in row">in row</a>".</p>
                   7282: 
                   7283:   <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
                   7284:   <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
                   7285:   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
                   7286:   mode</a>).</p>
                   7287: 
1.159     mike     7288:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The marker means that when the "aaa" character tokens are seen,
1.1       mike     7289:   no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
                   7290:   node:</p>
                   7291: 
1.159     mike     7292:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The end tags are handled in a straight-forward manner; after
1.1       mike     7293:   handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
1.159     mike     7294:   elements <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
1.1       mike     7295:   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
                   7296:   elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
                   7297:   marker having been removed by the "td" end tag token); and the
                   7298:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
                   7299:   table body">in table body</a>".</p>
                   7300: 
                   7301:   <p>Thus it is that the "bbb" character tokens are found. These
                   7302:   trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
                   7303:   text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
                   7304:   insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
                   7305:   body">in table body</a>"). The character tokens are collected,
                   7306:   and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
                   7307:   seen, they are processed as a group. Since they are not all spaces,
                   7308:   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,
                   7309:   which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   7310:   body</a>" insertion mode but with <a href="#foster-parent" title="foster
                   7311:   parent">foster parenting</a>.</p>
                   7312: 
                   7313:   <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
                   7314:   active formatting elements are reconstructed</a>, a
                   7315:   <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
                   7316:   parent">foster parented</a>, and then the "bbb" text node is
                   7317:   appended to it:</p>
                   7318: 
1.159     mike     7319:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">bbb</span></li></ul></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The <a href="#stack-of-open-elements">stack of open elements</a> has on it the elements
                   7320:   <code><a href="semantics.html#the-html-element-0">html</a></code>, <code><a href="semantics.html#the-body-element-0">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
1.1       mike     7321:   <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
                   7322:   this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
                   7323:   formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
                   7324:   and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
                   7325:   mode: in table body">in table body</a>".</p>
                   7326: 
                   7327:   <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
                   7328:   character">space characters</a> instead of "bbb", then those
                   7329:   <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
                   7330:   appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
                   7331: 
                   7332:   <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
                   7333:   tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
                   7334:   elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   7335:   but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
                   7336:   elements</a>, so the "ccc" character tokens after the table
                   7337:   result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
                   7338:   time after the table:</p>
                   7339: 
1.159     mike     7340:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">bbb</span></li></ul></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">ccc</span></li></ul></li></ul></li></ul></li></ul><h5 id="scripts-that-modify-the-page-as-it-is-being-parsed"><span class="secno">9.2.8.4 </span>Scripts that modify the page as it is being parsed</h5>
1.1       mike     7341: 
                   7342:   <p><i>This section is non-normative.</i></p>
                   7343: 
                   7344:   <p>Consider the following markup, which for this example we will
                   7345:   assume is the document with <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/inner</code>, being rendered as the
1.159     mike     7346:   content of an <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code> in another document with the
1.1       mike     7347:   <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
                   7348: 
                   7349:   <pre>&lt;div id=a&gt;
                   7350:  &lt;script&gt;
                   7351:   var div = document.getElementById('a');
                   7352:   parent.document.body.appendChild(div);
                   7353:  &lt;/script&gt;
                   7354:  &lt;script&gt;
                   7355:   alert(document.URL);
                   7356:  &lt;/script&gt;
                   7357: &lt;/div&gt;
                   7358: &lt;script&gt;
                   7359:  alert(document.URL);
                   7360: &lt;/script&gt;</pre>
                   7361: 
                   7362:   <p>Up to the first "script" end tag, before the script is parsed,
                   7363:   the result is relatively straightforward:</p>
                   7364: 
1.159     mike     7365:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="interactive-elements.html#the-div-element">div</a></code> <span class="t2" title=""><code class="attribute name">id</code>="<code class="attribute value"><a href="text-level-semantics.html#the-a-element">a</a></code>"</span><ul><li class="t3"><code>#text</code>: <span title="">
1.1       mike     7366:  </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
                   7367:   and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
                   7368: 
1.159     mike     7369:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code></li></ul></li></ul><p>They are, at this point, in the <code>Document</code> of the
1.1       mike     7370:   aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
                   7371:   <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
                   7372:   <code><a href="interactive-elements.html#the-div-element">div</a></code> element</em>.</p>
                   7373: 
                   7374:   <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
                   7375:   is inserted <em>into the outer <code>Document</code>
                   7376:   object</em>.</p>
                   7377: 
                   7378:   <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
                   7379:   the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
                   7380:   object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
1.159     mike     7381:   <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>.</p>
1.1       mike     7382: 
                   7383:   <p class="note">This isn't a security problem since the script that
                   7384:   moves the <code><a href="interactive-elements.html#the-div-element">div</a></code> into the outer <code>Document</code> can
                   7385:   only do so because they have the two <code>Document</code> object
1.159     mike     7386:   have the same <a href="browsers.html#origin">origin</a>.</p>
1.1       mike     7387: 
                   7388:   <p>Thus, the first alert says "http://example.com/outer".</p>
                   7389: 
                   7390:   <p>Once the <code><a href="interactive-elements.html#the-div-element">div</a></code> element's end tag is parsed, the
                   7391:   <code><a href="interactive-elements.html#the-div-element">div</a></code> element is popped off the stack, and so the next
                   7392:   <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
                   7393: 
1.159     mike     7394:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="semantics.html#script">script</a></code><ul><li class="t3"><code>#text</code>: <span title="">alert(document.URL);</span></li></ul></li></ul></li></ul></li></ul><p>This second alert will say "http://example.com/inner".</p>
1.1       mike     7395: 
                   7396: 
                   7397: 
1.215     mike     7398:   <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3>
1.1       mike     7399: 
                   7400:   <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
                   7401: 
                   7402:   <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
                   7403: 
                   7404:   <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
                   7405: 
                   7406:   <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
                   7407: 
                   7408:   <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
                   7409: 
                   7410:   <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
                   7411: 
                   7412:   <hr><p>Data mining tools and other user agents that perform operations
1.83      mike     7413:   on <code><a href="iana-considerations.html#text-html">text/html</a></code> content without running scripts,
1.1       mike     7414:   evaluating CSS or XPath expressions, or otherwise exposing the
                   7415:   resulting DOM to arbitrary content, may "support namespaces" by just
                   7416:   asserting that their DOM node analogues are in certain namespaces,
                   7417:   without actually exposing the above strings.</p>
                   7418: 
                   7419: 
                   7420: 
                   7421: 
                   7422:   <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3>
                   7423: 
                   7424:   <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
                   7425:   algorithm</dfn>. The algorithm takes as input a DOM
                   7426:   <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
                   7427:   exception.</p>
                   7428: 
                   7429:   <p class="note">This algorithm serializes the <em>children</em> of
                   7430:   the node being serialized, not the node itself.</p>
                   7431: 
                   7432:   <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
                   7433:    the empty string.</p></li>
                   7434: 
                   7435:    <li>
                   7436: 
                   7437:     <p>For each child node of <var title="">the node</var>, in
                   7438:     <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
                   7439: 
                   7440:     </p><ol><li><p>Let <var title="">current node</var> be the child node
                   7441:      being processed.</p></li>
                   7442: 
                   7443:      <li>
                   7444: 
                   7445:       <p>Append the appropriate string from the following list to
                   7446:       <var title="">s</var>:</p>
                   7447: 
                   7448:       <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
                   7449: 
                   7450:        <dd>
                   7451: 
                   7452:         <p>Append a U+003C LESS-THAN SIGN (<code title="">&lt;</code>)
                   7453:         character, followed by the element's tag name. (For nodes
                   7454:         created by the <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
                   7455:         lowercase.)</p>
                   7456: 
                   7457:         <p>For each attribute that the element has, append a U+0020
                   7458:         SPACE character, the attribute's name (which, for attributes
                   7459:         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
                   7460:         U+003D EQUALS SIGN (<code title="">=</code>) character, a
                   7461:         U+0022 QUOTATION MARK (<code title="">"</code>)
                   7462:         character, the attribute's value, <a href="#escapingString" title="escaping a
                   7463:         string">escaped as described below</a> in <i>attribute
                   7464:         mode</i>, and a second U+0022 QUOTATION MARK (<code title="">"</code>) character.</p>
                   7465: 
                   7466:         <p>While the exact order of attributes is UA-defined, and may
                   7467:         depend on factors such as the order that the attributes were
                   7468:         given in the original markup, the sort order must be stable,
                   7469:         such that consecutive invocations of this algorithm serialize an
                   7470:         element's attributes in the same order.</p>
                   7471: 
                   7472:         <p>Append a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>)
                   7473:         character.</p>
                   7474: 
                   7475:         <p>If <var title="">current node</var> is an
1.5       mike     7476:         <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     7477:         <code>bgsound</code>, <code><a href="semantics.html#the-br-element">br</a></code>, <code><a href="tabular-data.html#the-col-element">col</a></code>,
1.159     mike     7478:         <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>, <code><a href="obsolete.html#frame">frame</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>,
                   7479:         <code><a href="text-level-semantics.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="forms.html#the-keygen-element">keygen</a></code>,
                   7480:         <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#meta">meta</a></code>, <code><a href="text-level-semantics.html#the-param-element">param</a></code>,
1.5       mike     7481:         <code><a href="obsolete.html#spacer">spacer</a></code>, or <code>wbr</code> element, then
1.1       mike     7482:         continue on to the next child node at this point.</p> <!--
                   7483:         also, i guess: image and isindex, but we don't list those
                   7484:         because we don't consider those "elements", more "macros", and
                   7485:         thus we should never serialize them -->
                   7486: 
                   7487:         <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42      mike     7488:         <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     7489:         a U+000A LINE FEED (LF) character.</p>
                   7490: 
                   7491:         <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
                   7492:         serialization algorithm</a> on the <var title="">current
                   7493:         node</var> element (thus recursing into this algorithm for
                   7494:         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,
                   7495:         and finally a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>) character.</p>
                   7496: 
                   7497:        </dd>
                   7498: 
                   7499: 
                   7500:        <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
                   7501:        node</dt>
                   7502: 
                   7503:        <dd>
                   7504: 
1.19      mike     7505:         <p>If the parent of <var title="">current node</var> is a
1.42      mike     7506:         <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="semantics.html#script">script</a></code>, <code><a href="obsolete.html#xmp">xmp</a></code>,
1.159     mike     7507:         <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>,
1.222     mike     7508:         <code><a href="obsolete.html#noframes">noframes</a></code>, or <code><a href="obsolete.html#plaintext">plaintext</a></code> element, or
                   7509:         if the parent of <var title="">current node</var> is
                   7510:         <code><a href="semantics.html#the-noscript-element">noscript</a></code> element and <a href="browsers.html#concept-n-script" title="concept-n-script">scripting is enabled</a> for the
                   7511:         node, then append the value of <var title="">current
                   7512:         node</var>'s <code title="">data</code> IDL attribute
                   7513:         literally.</p>
1.1       mike     7514: 
                   7515:         <p>Otherwise, append the value of <var title="">current
1.192     mike     7516:         node</var>'s <code title="">data</code> IDL attribute, <a href="#escapingString" title="escaping a string">escaped as described
1.1       mike     7517:         below</a>.</p>
                   7518: 
                   7519:        </dd>
                   7520: 
                   7521: 
                   7522:        <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
                   7523: 
                   7524:        <dd>
                   7525: 
                   7526:         <p>Append the literal string <code>&lt;!--</code> (U+003C
                   7527:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
1.192     mike     7528:         U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1       mike     7529:         attribute, followed by the literal string <code>--&gt;</code>
                   7530:         (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
                   7531:         SIGN).</p>
                   7532: 
                   7533:        </dd>
                   7534: 
                   7535: 
                   7536:        <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
                   7537: 
                   7538:        <dd>
                   7539: 
                   7540:         <p>Append the literal string <code>&lt;?</code> (U+003C
                   7541:         LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
1.192     mike     7542:         of <var title="">current node</var>'s <code title="">target</code> IDL attribute, followed by a single
                   7543:         U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1       mike     7544:         attribute, followed by a single U+003E GREATER-THAN SIGN
                   7545:         character ('&gt;').</p>
                   7546: 
                   7547:        </dd>
                   7548: 
                   7549: 
                   7550:        <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
                   7551: 
                   7552:        <dd>
                   7553: 
                   7554:         <p>Append the literal string <code>&lt;!DOCTYPE</code> (U+003C
                   7555:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
                   7556:         LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
                   7557:         LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
                   7558:         LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
                   7559:         LETTER E), followed by a space (U+0020 SPACE), followed by the
1.192     mike     7560:         value of <var title="">current node</var>'s <code title="">name</code> IDL attribute, followed by the literal
1.1       mike     7561:         string <code>&gt;</code> (U+003E GREATER-THAN SIGN).</p>
                   7562: 
                   7563:        </dd>
                   7564: 
                   7565: 
                   7566:       </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
                   7567:       occur as children of elements. If, despite this, they somehow do
                   7568:       occur, this algorithm must raise an
                   7569:       <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
                   7570: 
                   7571:      </li>
                   7572: 
                   7573:     </ol></li>
                   7574: 
                   7575:    <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
                   7576: 
                   7577:   </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
                   7578:   purposes of the algorithm above) consists of replacing any
                   7579:   occurrences of the "<code title="">&amp;</code>" character by the
                   7580:   string "<code title="">&amp;amp;</code>", any occurrences of the
                   7581:   U+00A0 NO-BREAK SPACE character by the string "<code title="">&amp;nbsp;</code>", and, if the algorithm was invoked in
                   7582:   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
                   7583:   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>
                   7584: 
                   7585:   <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
                   7586:   agent, and are therefore not covered in the algorithm above.</p>
                   7587: 
                   7588:   <p class="note">It is possible that the output of this algorithm, if
                   7589:   parsed with an <a href="#html-parser">HTML parser</a>, will not return the
                   7590:   original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
                   7591:   element to which a <code title="">Comment</code> node has been
                   7592:   appended is serialized and the output is then reparsed, the comment
                   7593:   will end up being displayed in the text field. Similarly, if, as a
                   7594:   result of DOM manipulation, an element contains a comment that
                   7595:   contains the literal string "<code title="">--&gt;</code>", then
                   7596:   when the result of serializing the element is parsed, the comment
                   7597:   will be truncated at that point and the rest of the comment will be
                   7598:   interpreted as markup. More examples would be making a
                   7599:   <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
                   7600:   "<code>&lt;/script&gt;</code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
                   7601:   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
                   7602:   <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
                   7603:   tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7604: 
                   7605: 
                   7606:   <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3>
                   7607: 
                   7608:   <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
                   7609:   algorithm</dfn>. The algorithm optionally takes as input an
                   7610:   <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
                   7611:   parser, as well as <var title="">input</var>, a string to parse, and
                   7612:   returns a list of zero or more nodes.</p>
                   7613: 
                   7614:   <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
                   7615:   in the parser section are parts that only occur if the parser was
                   7616:   created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
                   7617:   with such markings for informational purposes only; such markings
                   7618:   have no normative weight. If it is possible for a condition
                   7619:   described as a <a href="#fragment-case">fragment case</a> to occur even when the
                   7620:   parser wasn't created for the purposes of handling this algorithm,
                   7621:   then that is an error in the specification.</p>
                   7622: 
                   7623:   <ol><li>
                   7624: 
                   7625:     <p>Create a new <code>Document</code> node, and mark it as being
                   7626:     an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                   7627: 
                   7628:    </li>
                   7629: 
                   7630:    <li>
                   7631: 
                   7632:     <p>If there is a <var title="">context</var> element, and the
                   7633:     <code>Document</code> of the <var title="">context</var> element
                   7634:     is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
                   7635:     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
                   7636:     the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
                   7637:     mode</a>, then let the <code>Document</code> be in
                   7638:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
                   7639:     <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
                   7640: 
                   7641:    </li>
                   7642: 
                   7643:    <li>
                   7644: 
                   7645:     <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
                   7646:     the just created <code>Document</code> node.</p>
                   7647: 
                   7648:    </li>
                   7649: 
                   7650:    <li>
                   7651: 
                   7652:     <p>If there is a <var title="">context</var> element, run these
                   7653:     substeps:</p>
                   7654: 
                   7655:     <ol><li>
                   7656: 
                   7657:       <p>Set the <a href="#html-parser">HTML parser</a>'s <a href="#tokenization">tokenization</a>
                   7658:       stage's <a href="#content-model-flag">content model flag</a> according to the <var title="">context</var> element, as follows:</p>
                   7659: 
1.159     mike     7660:       <dl class="switch"><dt>If it is a <code><a href="semantics.html#the-title-element-0">title</a></code> or <code><a href="forms.html#the-textarea-element">textarea</a></code>
1.1       mike     7661:        element</dt>
                   7662: 
                   7663:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7664:        the RCDATA state.</dd>
                   7665: 
                   7666: 
                   7667:        <dt>If it is a <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="semantics.html#script">script</a></code>,
1.159     mike     7668:        <code><a href="obsolete.html#xmp">xmp</a></code>, <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>, or
1.5       mike     7669:        <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1       mike     7670: 
                   7671:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
1.91      mike     7672:        the RAWTEXT state.</dd>
1.1       mike     7673: 
                   7674: 
                   7675:        <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
                   7676: 
                   7677:        <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, set the
1.91      mike     7678:        <a href="#content-model-flag">content model flag</a> to the RAWTEXT
1.1       mike     7679:        state. Otherwise, set the <a href="#content-model-flag">content model flag</a> to the
                   7680:        PCDATA state.</dd>
                   7681: 
                   7682: 
1.42      mike     7683:        <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1       mike     7684: 
                   7685:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7686:        PLAINTEXT.</dd>
                   7687: 
                   7688: 
                   7689:        <dt>Otherwise</dt>
                   7690: 
                   7691:        <dd>Leave the <a href="#content-model-flag">content model flag</a> in the PCDATA
                   7692:        state.</dd>
                   7693: 
                   7694:       </dl></li>
                   7695: 
                   7696:      <li>
                   7697: 
1.159     mike     7698:       <p>Let <var title="">root</var> be a new <code><a href="semantics.html#the-html-element-0">html</a></code> element
1.1       mike     7699:       with no attributes.</p>
                   7700: 
                   7701:      </li>
                   7702: 
                   7703:      <li>
                   7704: 
                   7705:       <p>Append the element <var title="">root</var> to the
                   7706:       <code>Document</code> node created above.</p>
                   7707: 
                   7708:      </li>
                   7709: 
                   7710:      <li>
                   7711: 
                   7712:       <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
                   7713:       it contains just the single element <var title="">root</var>.</p>
                   7714: 
                   7715:      </li>
                   7716: 
                   7717:      <li>
                   7718: 
                   7719:       <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
                   7720:       parser's insertion mode appropriately</a>.</p>
                   7721: 
                   7722:       <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
                   7723: 
                   7724:      </li>
                   7725: 
                   7726:      <li>
                   7727: 
                   7728:       <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
                   7729:       to the nearest node to the <var title="">context</var> element
                   7730:       that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
                   7731:       ancestor chain, and including the element itself, if it is a
                   7732:       <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
                   7733:       <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
                   7734: 
                   7735:      </li>
                   7736: 
                   7737:     </ol></li>
                   7738: 
                   7739:    <li>
                   7740: 
                   7741:     <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
                   7742:     parser</a> just created the <var title="">input</var>. The
                   7743:     encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   7744:     <i>irrelevant</i>.</p>
                   7745: 
                   7746:    </li>
                   7747: 
                   7748:    <li>
                   7749: 
                   7750:     <p>Start the parser and let it run until it has consumed all the
                   7751:     characters just inserted into the input stream.</p>
                   7752: 
                   7753:    </li>
                   7754: 
                   7755:    <li>
                   7756: 
                   7757:     <p>If there is a <var title="">context</var> element, return the
                   7758:     child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
                   7759:     order</a>.</p>
                   7760: 
                   7761:     <p>Otherwise, return the children of the <code>Document</code>
                   7762:     object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
                   7763: 
                   7764:    </li>
                   7765: 
1.123     mike     7766:   </ol></div></body></html>

Webmaster