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

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; }
1.475     mike       30:    table tbody th { text-align: left; }
1.1       mike       31:    table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
                     32:    blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
                     33: 
                     34:    .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
                     35:    .matrix, .matrix td { border: none; text-align: right; }
                     36:    .matrix { margin-left: 2em; }
                     37:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                     38:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                     39:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
                     40: 
                     41:    .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
                     42:    img.extra { float: right; }
                     43:    pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
                     44:    pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
                     45:    pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
                     46:    pre.css:first-line { color: #AAAA50; }
                     47:    dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #EEFFEE; }
                     48:    hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
                     49:    dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
                     50:    dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
                     51:    dl.domintro dd p { margin: 0.5em 0; }
                     52:    dl.switch { padding-left: 2em; }
                     53:    dl.switch > dt { text-indent: -1.5em; }
                     54:    dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
                     55:    dl.triple { padding: 0 0 0 1em; }
                     56:    dl.triple dt, dl.triple dd { margin: 0; display: inline }
                     57:    dl.triple dt:after { content: ':'; }
                     58:    dl.triple dd:after { content: '\A'; white-space: pre; }
                     59:    .diff-old { text-decoration: line-through; color: silver; background: transparent; }
                     60:    .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
                     61:    a .diff-new { border-bottom: 1px blue solid; }
                     62: 
                     63:    h2 { page-break-before: always; }
                     64:    h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
                     65:    h1 + h2, hr + h2.no-toc { page-break-before: auto; }
                     66: 
                     67:    p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
                     68: 
                     69:    div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
                     70:    div.head p { margin: 0; }
                     71:    div.head h1 { margin: 0; }
                     72:    div.head .logo { float: right; margin: 0 1em; }
                     73:    div.head .logo img { border: none } /* remove border from top image */
                     74:    div.head dl { margin: 1em 0; }
                     75:    p.copyright { font-size: x-small; font-style: oblique; margin: 0; }
                     76: 
                     77:    body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
                     78:    body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
                     79:    body > .toc > li > * { margin-bottom: 0.5em; }
                     80:    body > .toc > li > * > li > * { margin-bottom: 0.25em; }
                     81:    .toc, .toc li { list-style: none; }
                     82: 
                     83:    .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
                     84:    .brief li { margin: 0; padding: 0; }
                     85:    .brief li p { margin: 0; padding: 0; }
                     86: 
                     87:    .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
                     88:    .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
                     89:    .category-list li { display: inline; }
                     90:    .category-list li:not(:last-child)::after { content: ', '; }
                     91:    .category-list li > span, .category-list li > a { text-transform: lowercase; }
                     92:    .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
                     93: 
                     94:    .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
                     95:    .XXX > :first-child { margin-top: 0; }
                     96:    p .XXX { line-height: 3em; }
1.159     mike       97:    .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
                     98:    .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
                     99:    .annotation :link, .annotation :visited { color: inherit; }
                    100:    .annotation :link:hover, .annotation :visited:hover { background: transparent; }
                    101:    .annotation span { border: none ! important; }
1.1       mike      102:    .note { color: green; background: transparent; font-family: sans-serif; }
                    103:    .warning { color: red; background: transparent; }
                    104:    .note, .warning { font-weight: bolder; font-style: italic; }
                    105:    p.note, div.note { padding: 0.5em 2em; }
                    106:    span.note { padding: 0 2em; }
                    107:    .note p:first-child, .warning p:first-child { margin-top: 0; }
                    108:    .note p:last-child, .warning p:last-child { margin-bottom: 0; }
                    109:    .warning:before { font-style: normal; }
                    110:    p.note:before { content: 'Note: '; }
                    111:    p.warning:before { content: '\26A0 Warning! '; }
                    112: 
                    113:    .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
                    114:    .bookkeeping { font-size: 0.8em; margin: 2em 0; }
                    115:    .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
                    116: 
                    117:    h4 { position: relative; z-index: 3; }
                    118:    h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
                    119:    .element {
                    120:      background: #EEEEFF;
                    121:      color: black;
                    122:      margin: 0 0 1em 0.15em;
                    123:      padding: 0 1em 0.25em 0.75em;
                    124:      border-left: solid #9999FF 0.25em;
                    125:      position: relative;
                    126:      z-index: 1;
                    127:    }
                    128:    .element:before {
                    129:      position: absolute;
                    130:      z-index: 2;
                    131:      top: 0;
                    132:      left: -1.15em;
                    133:      height: 2em;
                    134:      width: 0.9em;
                    135:      background: #EEEEFF;
                    136:      content: ' ';
                    137:      border-style: none none solid solid;
                    138:      border-color: #9999FF;
                    139:      border-width: 0.25em;
                    140:    }
                    141: 
1.149     mike      142:    .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
                    143:    td > .example:only-child { margin: 0 0 0 0.1em; }
1.1       mike      144: 
                    145:    .tall-and-narrow {
                    146:      font-size: 0.6em;
                    147:      column-width: 25em;
                    148:      column-gap: 1em;
                    149:      -moz-column-width: 25em;
                    150:      -moz-column-gap: 1em;
                    151:      -webkit-column-width: 25em;
                    152:      -webkit-column-gap: 1em;
                    153:    }
                    154: 
                    155:    ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
                    156:    ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
                    157:    ul.domTree li li { list-style: none; }
                    158:    ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    159:    ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    160:    ul.domTree span { font-style: italic; font-family: serif; }
                    161:    ul.domTree .t1 code { color: purple; font-weight: bold; }
                    162:    ul.domTree .t2 { font-style: normal; font-family: monospace; }
                    163:    ul.domTree .t2 .name { color: black; font-weight: bold; }
                    164:    ul.domTree .t2 .value { color: blue; font-weight: normal; }
                    165:    ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
                    166:    ul.domTree .t7 code, .domTree .t8 code { color: green; }
                    167:    ul.domTree .t10 code { color: teal; }
                    168: 
1.267     mike      169:   </style><style type="text/css">
                    170: 
1.292     mike      171:    .applies thead th > * { display: block; }
                    172:    .applies thead code { display: block; }
                    173:    .applies tbody th { whitespace: nowrap; }
                    174:    .applies td { text-align: center; }
                    175:    .applies .yes { background: yellow; }
                    176: 
1.267     mike      177:    .matrix, .matrix td { border: none; text-align: right; }
                    178:    .matrix { margin-left: 2em; }
                    179: 
                    180:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                    181:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                    182:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
                    183: 
                    184:    #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
                    185:    #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
                    186:    #table-example-1 caption { padding-bottom: 0.5em; }
                    187:    #table-example-1 thead, #table-example-1 tbody { border: none; }
                    188:    #table-example-1 th, #table-example-1 td { border: solid thin; }
                    189:    #table-example-1 th { font-weight: normal; }
                    190:    #table-example-1 td { border-style: none solid; vertical-align: top; }
                    191:    #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
                    192:    #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
                    193:    #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
                    194:    #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
                    195:    #table-example-1 tbody td:first-child::after { content: leader(". "); }
                    196:    #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
                    197:    #table-example-1 tbody td:first-child + td { width: 10em; }
                    198:    #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
                    199:    #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
                    200: 
                    201:    .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
                    202:    .apple-table-examples * { font-family: "Times", serif; }
                    203:    .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
                    204:    .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
                    205:    .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
                    206:    .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
                    207:    .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
                    208:    .apple-table-examples td { text-align: right; vertical-align: top; }
                    209:    .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
                    210:    .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
                    211:    .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
                    212:    .apple-table-examples sup { line-height: 0; }
                    213: 
1.235     mike      214:   </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      215:   <script src="link-fixup.js"></script>
                    216:   <link href="comms.html" title="8 Communication" rel="prev">
                    217:   <link href="spec.html#contents" title="Table of contents" rel="index">
1.1       mike      218:   <link href="named-character-references.html" title="9.6 Named character references" rel="next">
1.16      mike      219:   </head><body onload="fixBrokenLink(); fixBrokenLink()"><div class="head">
1.1       mike      220:    <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      221:    <h1>HTML5</h1>
1.1       mike      222:    <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      223:    </div><nav>
1.1       mike      224:    <a href="comms.html">&#8592; 8 Communication</a> &#8211;
1.2       mike      225:    <a href="spec.html#contents">Table of contents</a> &#8211;
1.1       mike      226:    <a href="named-character-references.html">9.6 Named character references &#8594;</a>
1.501   ! mike      227:   </nav><p>This is revision 1.3281.</p>
1.11      mike      228: 
1.1       mike      229: 
1.123     mike      230:   <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      231:   <code><a href="iana-considerations.html#text-html">text/html</a></code> resources. Rules for XML resources are
1.1       mike      232:   discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.159     mike      233:   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      234: 
                    235:   <p><i>This section only applies to documents, authoring tools, and
                    236:   markup generators. In particular, it does not apply to conformance
                    237:   checkers; conformance checkers must use the requirements given in
                    238:   the next section ("parsing HTML documents").</i></p>
                    239: 
1.123     mike      240:   </div><p>Documents must consist of the following parts, in the given
                    241:   order:</p><ol><li>Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.</li>
1.1       mike      242: 
                    243:    <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    244:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    245: 
                    246:    <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
                    247: 
                    248:    </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    249:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    250: 
1.159     mike      251:    <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      252: 
                    253:    <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    254:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    255: 
                    256:   </ol><p>The various types of content mentioned above are described in the
1.123     mike      257:   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      258:   declarations</a> are to be serialized, as discussed in the
1.123     mike      259:   section on that topic.</p><div class="note">
1.1       mike      260: 
1.159     mike      261:    <p>Space characters before the root <code><a href="semantics.html#the-html-element-0">html</a></code> element, and
                    262:    space characters at the start of the <code><a href="semantics.html#the-html-element-0">html</a></code> element and
                    263:    before the <code><a href="semantics.html#the-head-element-0">head</a></code> element, will be dropped when the
1.1       mike      264:    document is parsed; space characters <em>after</em> the root
1.159     mike      265:    <code><a href="semantics.html#the-html-element-0">html</a></code> element will be parsed as if they were at the end
                    266:    of the <code><a href="semantics.html#the-body-element-0">body</a></code> element. Thus, space characters around the
1.1       mike      267:    root element do not round-trip.</p>
                    268: 
                    269:    <p>It is suggested that newlines be inserted after the DOCTYPE,
                    270:    after any comments that are before the root element, after the
1.159     mike      271:    <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
                    272:    that are inside the <code><a href="semantics.html#the-html-element-0">html</a></code> element but before the
                    273:    <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike      274: 
1.123     mike      275:   </div><p>Many strings in the HTML syntax (e.g. the names of elements and
1.1       mike      276:   their attributes) are case-insensitive, but only for characters in
                    277:   the ranges U+0041 .. U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
                    278:   LETTER Z) and U+0061 .. U+007A (LATIN SMALL LETTER A to LATIN SMALL
                    279:   LETTER Z). For convenience, in this section this is just referred to
1.168     mike      280:   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      281:   but required, header.</p><p class="note">DOCTYPEs are required for legacy reasons. When
1.1       mike      282:   omitted, browsers tend to use a different rendering mode that is
                    283:   incompatible with some specifications. Including the DOCTYPE in a
                    284:   document ensures that the browser makes a best-effort attempt at
1.123     mike      285:   following the relevant specifications.</p><p>A DOCTYPE must consist of the following characters, in this
                    286:   order:</p><ol class="brief"><li>A U+003C LESS-THAN SIGN (<code>&lt;</code>) character.</li>
1.1       mike      287:    <li>A U+0021 EXCLAMATION MARK (<code>!</code>) character.</li>
                    288:    <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>
                    289:    <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    290:    <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>
                    291:    <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> (defined below).</li>
                    292:    <li>Zero or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    293:    <li>A U+003E GREATER-THAN SIGN (<code>&gt;</code>) character.</li>
                    294:   </ol><p class="note">In other words, <code>&lt;!DOCTYPE HTML&gt;</code>,
1.123     mike      295:   case-insensitively.</p><p>For the purposes of HTML generators that cannot output HTML
1.1       mike      296:   markup with the short DOCTYPE "<code title="">&lt;!DOCTYPE
                    297:   HTML&gt;</code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
                    298:   into the DOCTYPE (in the position defined above). This string must
1.123     mike      299:   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      300:    <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">SYSTEM</code>".</li>
1.444     mike      301:    <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.1       mike      302:    <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
1.465     mike      303:    <li>The literal string "<code><a href="infrastructure.html#about:legacy-compat">about:legacy-compat</a></code>".</li>
1.1       mike      304:    <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>
                    305:   </ol><p class="note">In other words, <code>&lt;!DOCTYPE HTML SYSTEM
                    306:   "about:legacy-compat"&gt;</code> or <code>&lt;!DOCTYPE HTML SYSTEM
                    307:   'about:legacy-compat'&gt;</code>, case-insensitively except for the bit
1.123     mike      308:   in quotes.</p><p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1       mike      309:   the document is generated from a system that cannot output the
1.373     mike      310:   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>: <a href="#void-elements">void elements</a>,
                    311:   <a href="#raw-text-elements">raw text elements</a>, <a href="#rcdata-elements">RCDATA elements</a>,
                    312:   <a href="#foreign-elements">foreign elements</a>, and <a href="#normal-elements">normal elements</a>.</p><dl><dt><dfn id="void-elements">Void elements</dfn></dt>
1.1       mike      313: 
                    314:    <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      315:    <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>,
                    316:    <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      317:    <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      318:    <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      319: 
1.373     mike      320:    <dt><dfn id="raw-text-elements">Raw text elements</dfn></dt>
1.1       mike      321: 
                    322:    <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      323:    noscript don't count as raw text for syntax purposes -->
1.1       mike      324: 
1.373     mike      325:    <dt><dfn id="rcdata-elements">RCDATA elements</dfn></dt>
1.1       mike      326: 
1.159     mike      327:    <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      328: 
1.373     mike      329:    <dt><dfn id="foreign-elements">Foreign elements</dfn></dt>
1.1       mike      330: 
                    331:    <dd>Elements from the <a href="#mathml-namespace">MathML namespace</a>
                    332:    and the <a href="#svg-namespace">SVG namespace</a>.</dd>
                    333: 
1.373     mike      334:    <dt><dfn id="normal-elements">Normal elements</dfn></dt>
1.1       mike      335: 
                    336:    <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
                    337:    elements.</dd>
                    338: 
                    339:   </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.373     mike      340:   and end of elements in the markup. <a href="#raw-text-elements" title="raw text
                    341:   elements">Raw text</a>, <a href="#rcdata-elements" title="RCDATA
                    342:   elements">RCDATA</a>, and <a href="#normal-elements" title="normal
                    343:   elements">normal</a> elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to indicate where they
                    344:   begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> to
                    345:   indicate where they end. The start and end tags of certain
                    346:   <a href="#normal-elements">normal elements</a> can be <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>, as described
1.1       mike      347:   later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
                    348:   elements</a> only have a start tag; end tags must not be
1.373     mike      349:   specified for <a href="#void-elements">void elements</a>. <a href="#foreign-elements">Foreign
                    350:   elements</a> must either have a start tag and an end tag, or a
                    351:   start tag that is marked as self-closing, in which case they must
                    352:   not have an end tag.</p><p>The contents of the element must be placed between just after the
1.1       mike      353:   start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
                    354:   in certain cases</a>) and just before the end tag (which again,
                    355:   <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
                    356:   cases</a>). The exact allowed contents of each individual element
                    357:   depends on the content model of that element, as described earlier
                    358:   in this specification. Elements must not contain content that their
                    359:   content model disallows. In addition to the restrictions placed on
                    360:   the contents by those content models, however, the five types of
1.123     mike      361:   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      362:   no end tag, no content can be put between the start tag and the end
1.373     mike      363:   tag).</p><p><a href="#raw-text-elements">Raw text elements</a> can have <a href="#syntax-text" title="syntax-text">text</a>, though it has <a href="#cdata-rcdata-restrictions">restrictions</a> described
                    364:   below.</p><p><a href="#rcdata-elements">RCDATA elements</a> can have <a href="#syntax-text" title="syntax-text">text</a> and <a href="#syntax-charref" title="syntax-charref">character references</a>, but the text
                    365:   must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
1.1       mike      366:   There are also <a href="#cdata-rcdata-restrictions">further
1.373     mike      367:   restrictions</a> described below.</p><p><a href="#foreign-elements">Foreign elements</a> whose start tag is marked as
                    368:   self-closing can't have any contents (since, again, as there's no
                    369:   end tag, no content can be put between the start tag and the end
                    370:   tag). <a href="#foreign-elements">Foreign elements</a> whose start tag is <em>not</em>
                    371:   marked as self-closing can have <a href="#syntax-text" title="syntax-text">text</a>, <a href="#syntax-charref" title="syntax-charref">character references</a>, <a href="#syntax-cdata" title="syntax-cdata">CDATA sections</a>, other <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
1.1       mike      372:   contain the character U+003C LESS-THAN SIGN (<code>&lt;</code>) or
                    373:   an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.374     mike      374:   ampersand</a>.</p><div class="note">
                    375: 
                    376:    <p>The HTML syntax does not support namespace
                    377:    declarations, even in <a href="#foreign-elements">foreign elements</a>.</p>
                    378: 
                    379:    <p>For instance, consider the following HTML fragment:</p>
                    380: 
                    381:    <pre>&lt;p&gt;
                    382:  &lt;svg&gt;
                    383:   &lt;metadata&gt;
                    384:    &lt;!-- this is invalid --&gt;
                    385:    &lt;cdr:license xmlns:cdr="http://www.example.com/cdr/metadata" name="MIT"/&gt;
                    386:   &lt;/metadata&gt;
                    387:  &lt;/svg&gt;
                    388: &lt;/p&gt;</pre>
                    389: 
                    390:    <p>The innermost element, <code title="">cdr:license</code>, is
                    391:    actually in the SVG namespace, as the "<code title="">xmlns:cdr</code>" attribute has no effect (unlike in
                    392:    XML). In fact, as the comment in the fragment above says, the
                    393:    fragment is actually non-conforming. This is because the SVG
                    394:    specification does not define any elements called "<code title="">cdr:license</code>" in the SVG namespace.</p>
                    395: 
                    396:   </div><p><a href="#normal-elements">Normal elements</a> can have <a href="#syntax-text" title="syntax-text">text</a>, <a href="#syntax-charref" title="syntax-charref">character references</a>, other <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
1.1       mike      397:   contain the character U+003C LESS-THAN SIGN (<code>&lt;</code>) or
                    398:   an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.373     mike      399:   ampersand</a>. Some <a href="#normal-elements">normal elements</a> also have <a href="#element-restrictions">yet more restrictions</a> on what
1.1       mike      400:   content they are allowed to hold, beyond the restrictions imposed by
                    401:   the content model and those described in this paragraph. Those
1.123     mike      402:   restrictions are described below.</p><p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1       mike      403:   giving the element's name. HTML elements all have names that only
1.464     mike      404:   use characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT
                    405:   NINE (9), U+0061 LATIN SMALL LETTER A to U+007A LATIN SMALL LETTER
                    406:   Z, and U+0041 LATIN CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER
                    407:   Z. In the HTML syntax, tag names, even those for <a href="#foreign-elements">foreign
1.462     mike      408:   elements</a>, may be written with any mix of lower- and uppercase
                    409:   letters that, when converted to all-lowercase, matches the element's
                    410:   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      411:   following format:</p><ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.1       mike      412:    SIGN (<code>&lt;</code>).</li>
                    413: 
                    414:    <li>The next few characters of a start tag must be the element's
                    415:    <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
                    416: 
                    417:    <li>If there are to be any attributes in the next step, there must
                    418:    first be one or more <a href="infrastructure.html#space-character" title="space character">space
                    419:    characters</a>.</li>
                    420: 
                    421:    <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
                    422:    below. Attributes may be separated from each other by one or more
                    423:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    424: 
                    425:    <li>After the attributes, there may be one or more <a href="infrastructure.html#space-character" title="space character">space characters</a>. (Some attributes
                    426:    are required to be followed by a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes section</a> below.)</li>
                    427: 
                    428:    <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
1.373     mike      429:    or if the element is a <a href="#foreign-elements" title="foreign elements">foreign
                    430:    element</a>, then there may be a single U+002F SOLIDUS
                    431:    (<code>/</code>) character. This character has no effect on
                    432:    <a href="#void-elements">void elements</a>, but on <a href="#foreign-elements">foreign elements</a> it
                    433:    marks the start tag as self-closing.</li>
1.1       mike      434: 
                    435:    <li>Finally, start tags must be closed by a U+003E GREATER-THAN
                    436:    SIGN (<code>&gt;</code>) character.</li>
                    437: 
1.123     mike      438:   </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
                    439:   following format:</p><ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.1       mike      440:    SIGN (<code>&lt;</code>).</li>
                    441: 
                    442:    <li>The second character of an end tag must be a U+002F SOLIDUS
                    443:    (<code>/</code>).</li>
                    444: 
                    445:    <li>The next few characters of an end tag must be the element's
                    446:    <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
                    447: 
                    448:    <li>After the tag name, there may be one or more <a href="infrastructure.html#space-character" title="space
                    449:    character">space characters</a>.</li>
                    450: 
                    451:    <li>Finally, end tags must be closed by a U+003E GREATER-THAN
                    452:    SIGN (<code>&gt;</code>) character.</li>
                    453: 
1.123     mike      454:   </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
                    455:   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      456:   one or more characters other than the <a href="infrastructure.html#space-character" title="space
                    457:   character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
                    458:   MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
                    459:   (&gt;), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters,
                    460:   the control characters, and any characters that are not defined by
1.462     mike      461:   Unicode. In the HTML syntax, attribute names, even those for
                    462:   <a href="#foreign-elements">foreign elements</a>, may be written with any mix of lower-
                    463:   and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.123     mike      464:   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      465:   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      466:   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      467: 
                    468:    <dd>
                    469: 
                    470:     <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
                    471:     name</a>.</p>
                    472: 
                    473:     <div class="example">
                    474: 
                    475:      <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
                    476:      the empty attribute syntax:</p>
                    477: 
                    478:      <pre>&lt;input <em>disabled</em>&gt;</pre>
                    479: 
                    480:     </div>
                    481: 
                    482:     <p>If an attribute using the empty attribute syntax is to be
                    483:     followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    484:     character</a> separating the two.</p>
                    485: 
                    486:    </dd>
                    487: 
1.2       mike      488:    <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1       mike      489: 
                    490:    <dd>
                    491: 
                    492:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    493:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    494:     characters</a>, followed by a single U+003D EQUALS SIGN
                    495:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    496:     character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    497:     addition to the requirements given above for attribute values,
                    498:     must not contain any literal <a href="infrastructure.html#space-character" title="space character">space
                    499:     characters</a>, any U+0022 QUOTATION MARK (<code>"</code>)
                    500:     characters, U+0027 APOSTROPHE (<code>'</code>) characters,
                    501:     U+003D EQUALS SIGN (<code>=</code>) characters, U+003C LESS-THAN
1.463     mike      502:     SIGN (<code>&lt;</code>) characters, U+003E GREATER-THAN SIGN
                    503:     (<code>&gt;</code>) characters, or U+0060 GRAVE ACCENT (`)
                    504:     characters, and must not be the empty string.</p>
                    505: 
                    506:     <!-- The ` character is in this list on a temporary basis, waiting
                    507:          for IE to fix it's parsing bug whereby it treats ` as an
                    508:          attribute value delimiter. Otherwise, escaping software that
                    509:          tries to be clever and not use quotes when it doesn't need to
                    510:          could be tricked by an attacker.
                    511: 
                    512:          Posit a site that allows the user to input text that is used
                    513:          verbatim in two attributes, such that the user can set the
                    514:          first attribute's value to:
                    515: 
                    516:             `
                    517: 
                    518:          ...and the second to:
                    519: 
                    520:             ` onload='...payload...' end=x
                    521: 
                    522:          ...with the assumption that the site is going to not quote
                    523:          the first one, and quote the second one with double quotes:
                    524: 
                    525:             <body title=` class="` onload='...payload...' end=x">
                    526: 
                    527:          In IE, this is treated as:
                    528: 
                    529:             <body title=' class="'
                    530:                   onload='...payload...'
                    531:                   end='x"'>
                    532: 
                    533:     -->
                    534: 
1.1       mike      535: 
                    536:     <div class="example">
                    537: 
                    538:      <p>In the following example, the <code title="attr-input-value"><a href="forms.html#attr-input-value">value</a></code> attribute is given
                    539:      with the unquoted attribute value syntax:</p>
                    540: 
                    541:      <pre>&lt;input <em>value=yes</em>&gt;</pre>
                    542: 
                    543:     </div>
                    544: 
                    545:     <p>If an attribute using the unquoted attribute syntax is to be
1.101     mike      546:     followed by another attribute or by the optional U+002F SOLIDUS
1.464     mike      547:     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      548:     must be a <a href="infrastructure.html#space-character">space character</a> separating the two.</p>
                    549: 
                    550:    </dd>
                    551: 
                    552:    <dt>Single-quoted attribute value syntax</dt>
                    553: 
                    554:    <dd>
                    555: 
                    556:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    557:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    558:     characters</a>, followed by a single U+003D EQUALS SIGN
                    559:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    560:     character">space characters</a>, followed by a single U+0027
                    561:     APOSTROPHE (<code>'</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    562:     addition to the requirements given above for attribute values,
                    563:     must not contain any literal U+0027 APOSTROPHE (<code>'</code>)
                    564:     characters, and finally followed by a second single U+0027
                    565:     APOSTROPHE (<code>'</code>) character.</p>
                    566: 
                    567:     <div class="example">
                    568: 
                    569:      <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
                    570:      single-quoted attribute value syntax:</p>
                    571: 
                    572:      <pre>&lt;input <em>type='checkbox'</em>&gt;</pre>
                    573: 
                    574:     </div>
                    575: 
                    576:     <p>If an attribute using the single-quoted attribute syntax is to
                    577:     be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    578:     character</a> separating the two.</p>
                    579: 
                    580:    </dd>
                    581: 
                    582:    <dt>Double-quoted attribute value syntax</dt>
                    583: 
                    584:    <dd>
                    585: 
                    586:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    587:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    588:     characters</a>, followed by a single U+003D EQUALS SIGN
                    589:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    590:     character">space characters</a>, followed by a single U+0022
                    591:     QUOTATION MARK (<code>"</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    592:     addition to the requirements given above for attribute values,
                    593:     must not contain any literal U+0022 QUOTATION MARK
                    594:     (<code>"</code>) characters, and finally followed by a second
                    595:     single U+0022 QUOTATION MARK (<code>"</code>) character.</p>
                    596: 
                    597:     <div class="example">
                    598: 
                    599:      <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
                    600:      double-quoted attribute value syntax:</p>
                    601: 
                    602:      <pre>&lt;input <em>name="be evil"</em>&gt;</pre>
                    603: 
                    604:     </div>
                    605: 
                    606:     <p>If an attribute using the double-quoted attribute syntax is to
                    607:     be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    608:     character</a> separating the two.</p>
                    609: 
                    610:    </dd>
                    611: 
                    612:   </dl><p>There must never be two or more attributes on the same start tag
                    613:   whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.462     mike      614:   each other.</p><hr><p>When a <a href="#foreign-elements" title="foreign elements">foreign element</a> has
                    615:   one of the namespaced attributes given by the local name and
                    616:   namespace of the first and second cells of a row from the following
                    617:   table, it must be written using the name given by the third cell
                    618:   from the same row.</p><table><thead><tr><th> Local name </th><th> Namespace </th><th> Attribute name
                    619:    </th></tr></thead><tbody><tr><td> <code title="">actuate</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:actuate</code>
                    620:     </td></tr><tr><td> <code title="">arcrole</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:arcrole</code>
                    621:     </td></tr><tr><td> <code title="">href</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:href</code>
                    622:     </td></tr><tr><td> <code title="">role</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:role</code>
                    623:     </td></tr><tr><td> <code title="">show</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:show</code>
                    624:     </td></tr><tr><td> <code title="">title</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:title</code>
                    625:     </td></tr><tr><td> <code title="">type</code> </td><td> <a href="#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:type</code>
                    626:     </td></tr><tr><td> <code title="">base</code> </td><td> <a href="#xml-namespace">XML namespace</a> <!-- attr-xml-base --> </td><td> <code title="">xml:base</code>
                    627:     </td></tr><tr><td> <code title="">lang</code> </td><td> <a href="#xml-namespace">XML namespace</a> </td><td> <code title="">xml:lang</code>
                    628:     </td></tr><tr><td> <code title="">space</code> </td><td> <a href="#xml-namespace">XML namespace</a> </td><td> <code title="">xml:space</code>
                    629:     </td></tr><tr><td> <code title="">xmlns</code> </td><td> <a href="#xmlns-namespace">XMLNS namespace</a> </td><td> <code title="">xmlns</code>
                    630:     </td></tr><tr><td> <code title="">xlink</code> </td><td> <a href="#xmlns-namespace">XMLNS namespace</a> </td><td> <code title="">xmlns:xlink</code>
                    631:   </td></tr></tbody></table><p>No other namespaced attribute can be expressed in the <a href="#syntax">the
                    632:   HTML syntax</a>.</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      633:   is not present; it is implied, but it is still there. An HTML
1.159     mike      634:   document always has a root <code><a href="semantics.html#the-html-element-0">html</a></code> element, even if the
1.1       mike      635:   string <code title="">&lt;html&gt;</code> doesn't appear anywhere in
1.159     mike      636:   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
                    637:   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
                    638:   tag</a> may be omitted if the <code><a href="semantics.html#the-html-element-0">html</a></code> element is not
                    639:   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      640:   element is empty, or--> if the first thing inside the
1.159     mike      641:   <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
                    642:   tag</a> may be omitted if the <code><a href="semantics.html#the-head-element-0">head</a></code> element is not
                    643:   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
                    644:   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      645:   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      646:   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      647:   <code><a href="semantics.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
                    648:   tag is present, the parser makes <style> and <script> elements
                    649:   between </head> and <body> end up in the <head> instead of implying
1.159     mike      650:   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
                    651:   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      652:   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      653:   tag</a> may be omitted if the <code><a href="semantics.html#the-li-element">li</a></code> element is
                    654:   immediately followed by another <code><a href="semantics.html#the-li-element">li</a></code> element or if there
1.422     mike      655:   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      656:   tag</a> may be omitted if the <code><a href="semantics.html#the-dt-element">dt</a></code> element is
                    657:   immediately followed by another <code><a href="semantics.html#the-dt-element">dt</a></code> element or a
1.123     mike      658:   <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      659:   tag</a> may be omitted if the <code><a href="semantics.html#the-dd-element">dd</a></code> element is
                    660:   immediately followed by another <code><a href="semantics.html#the-dd-element">dd</a></code> element or a
                    661:   <code><a href="semantics.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.123     mike      662:   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      663:   tag</a> may be omitted if the <code><a href="semantics.html#the-p-element">p</a></code> element is
                    664:   immediately followed by an <code><a href="semantics.html#the-address-element">address</a></code>,
                    665:   <code><a href="semantics.html#the-article-element">article</a></code>, <code><a href="semantics.html#the-aside-element">aside</a></code>, <code><a href="semantics.html#the-blockquote-element">blockquote</a></code>,
1.305     mike      666:   <!--v2DATAGRID <code>datagrid</code>,--> <code><a href="obsolete.html#dir">dir</a></code>,
1.306     mike      667:   <code><a href="semantics.html#the-div-element">div</a></code>, <code><a href="semantics.html#the-dl-element">dl</a></code>, <code><a href="forms.html#the-fieldset-element">fieldset</a></code>,
1.305     mike      668:   <code><a href="semantics.html#the-footer-element">footer</a></code>, <code><a href="forms.html#the-form-element">form</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h1</a></code>,
                    669:   <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>,
                    670:   <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h6</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>, <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>,
                    671:   <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="interactive-elements.html#menus">menu</a></code>, <code><a href="semantics.html#the-nav-element">nav</a></code>,
                    672:   <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      673:   <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>,
                    674:   element, or if there is no more content in the parent element and
1.123     mike      675:   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      676:   tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element is
                    677:   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      678:   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      679:   tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element is
                    680:   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      681:   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      682:   <select>; commented out text below can handle the non-<select> case
1.123     mike      683:   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      684:   <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
                    685:   <code>select</code> element and--> is immediately followed by
                    686:   another <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
                    687:   that are ancestors of the <code>optgroup</code> element, up to and
                    688:   including the first ancestor element that is not an
                    689:   <code>optgroup</code> element, have no more content--> there is no
1.123     mike      690:   more content in the parent element.</p><!-- so e.g. the max number of </optgroup>s are omitted here:
1.1       mike      691:    <select><optgroup></select>
                    692:    <p id=x><optgroup></optgroup>x</p>
                    693:    <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
                    694:    <p><optgroup id=x><optgroup></optgroup>x</p>
                    695:    <p><optgroup><optgroup id=x>x</p>
1.123     mike      696:   --><!-- </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      697:   tag</a> may be omitted if the <code><a href="forms.html#the-option-element">option</a></code> element is
                    698:   immediately followed by another <code><a href="forms.html#the-option-element">option</a></code> element, or if
                    699:   it is immediately followed by an <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or
1.123     mike      700:   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      701:   first thing inside the <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is a
                    702:   <code><a href="tabular-data.html#the-col-element">col</a></code> element, and if the element is not immediately
                    703:   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      704:   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      705:   <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.123     mike      706:   <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      707:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-thead-element">thead</a></code> element is
                    708:   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      709:   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      710:   first thing inside the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is a
                    711:   <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, and if the element is not immediately
                    712:   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
                    713:   <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
                    714:   tag</a> has been omitted. (It can't be omitted if the element is
1.123     mike      715:   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      716:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is
                    717:   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      718:   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      719:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element is
                    720:   immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, or if there is
1.123     mike      721:   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      722:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
                    723:   immediately followed by another <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, or if there
1.123     mike      724:   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      725:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-td-element">td</a></code> element is
                    726:   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      727:   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      728:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-th-element">th</a></code> element is
                    729:   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      730:   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
                    731:   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
                    732:   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      733:   elements, even though these elements are technically allowed inside
                    734:   <code><a href="tabular-data.html#the-table-element">table</a></code> elements according to the content models
                    735:   described in this specification. (If a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
                    736:   put inside a <code><a href="tabular-data.html#the-table-element">table</a></code> in the markup, it will in fact imply
1.304     mike      737:   a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag before it.)</p><p>A single <a href="#syntax-newlines" title="syntax-newlines">newline</a> may be
                    738:   placed immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
1.1       mike      739:   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>
                    740:   elements. This does not affect the processing of the element. The
1.304     mike      741:   otherwise optional <a href="#syntax-newlines" title="syntax-newlines">newline</a>
1.381     mike      742:   <em>must</em> be included if the element's contents themselves start
                    743:   with a <a href="#syntax-newlines" title="syntax-newlines">newline</a> (because
                    744:   otherwise the leading newline in the contents would be treated like
                    745:   the optional newline, and ignored).</p><div class="example">
1.1       mike      746:    <p>The following two <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
                    747:    <pre>&lt;pre&gt;Hello&lt;/pre&gt;</pre>
                    748:    <pre>&lt;pre&gt;<br>Hello&lt;/pre&gt;</pre>
1.373     mike      749:   </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 <a href="#raw-text-elements" title="raw text elements">raw text</a> and
                    750:   <a href="#rcdata-elements" title="RCDATA elements">RCDATAs</a> element must not
                    751:   contain any occurrences of the string "<code title="">&lt;/</code>"
                    752:   (U+003C LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that
1.1       mike      753:   case-insensitively match the tag name of the element followed by one
                    754:   of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM
1.304     mike      755:   FEED (FF), U+000D CARRIAGE RETURN (CR), U+0020 SPACE, U+003E
                    756:   GREATER-THAN SIGN (&gt;), or U+002F SOLIDUS (/), unless that string is
                    757:   part of an <a href="#syntax-escape" title="syntax-escape">escaping text
                    758:   span</a>.</p><p>An <dfn id="syntax-escape" title="syntax-escape">escaping text span</dfn> is a span
1.1       mike      759:   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
                    760:   not itself in an <a href="#syntax-escape" title="syntax-escape">escaping text
                    761:   span</a>, and ends at the next <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span end</a>. There
                    762:   cannot be any <a href="#syntax-charref" title="syntax-charref">character
                    763:   references</a> inside an <a href="#syntax-escape" title="syntax-escape">escaping
                    764:   text span</a> &#8212; sequences of characters that would look
                    765:   like <a href="#syntax-charref" title="syntax-charref">character references</a> do not
1.123     mike      766:   have special meaning.</p><p>An <dfn id="syntax-escape-start" title="syntax-escape-start">escaping text span
1.1       mike      767:   start</dfn> is a part of <a href="#syntax-text" title="syntax-text">text</a> that
                    768:   consists of the four character sequence "<code title="">&lt;!--</code>" (U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
1.123     mike      769:   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      770:   a part of <a href="#syntax-text" title="syntax-text">text</a> that consists of the
                    771:   three character sequence "<code title="">--&gt;</code>" (U+002D
1.134     mike      772:   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      773:   start</a> may share its U+002D HYPHEN-MINUS characters with its
                    774:   corresponding <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span
1.373     mike      775:   end</a>.</p><p>The text in <a href="#raw-text-elements">raw text elements</a> and <a href="#rcdata-elements">RCDATA
                    776:   elements</a> must not have an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a> that is
                    777:   not followed by an <a href="#syntax-escape-end" title="syntax-escape-end">escaping text
                    778:   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      779:   attributes, and comments. Text must consist of Unicode characters.
                    780:   Text must not contain U+0000 characters. Text must not contain
1.316     mike      781:   permanently undefined Unicode characters (noncharacters). Text must
                    782:   not contain control characters other than <a href="infrastructure.html#space-character" title="space
                    783:   character">space characters</a>. Extra constraints are placed on
                    784:   what is and what is not allowed in text based on where the text is
                    785:   to be put, as 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      786:   represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A
                    787:   LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR),
1.123     mike      788:   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      789:   to escape characters that couldn't otherwise legally be included in
1.123     mike      790:   <a href="#syntax-text" title="syntax-text">text</a>.</p><p>Character references must start with a U+0026 AMPERSAND
1.1       mike      791:   (<code>&amp;</code>). Following this, there are three possible kinds
1.123     mike      792:   of character references:</p><dl><dt>Named character references</dt>
1.1       mike      793: 
                    794:    <dd>The ampersand must be followed by one of the names given in the
                    795:    <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
                    796:    case. The name must be one that is terminated by a U+003B SEMICOLON
1.464     mike      797:    character (;).</dd>
1.1       mike      798: 
                    799: 
                    800:    <dt>Decimal numeric character reference</dt>
                    801: 
                    802:    <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
                    803:    (<code>#</code>) character, followed by one or more digits in the
1.464     mike      804:    range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), representing
                    805:    a base-ten integer that corresponds to a Unicode code point that is
1.378     mike      806:    allowed according to the definition below. The digits must then be
1.464     mike      807:    followed by a U+003B SEMICOLON character (;).</dd>
1.1       mike      808: 
                    809: 
                    810:    <dt>Hexadecimal numeric character reference</dt>
                    811: 
                    812:    <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
                    813:    (<code>#</code>) character, which must be followed by either a
1.464     mike      814:    U+0078 LATIN SMALL LETTER X character (x) or a U+0058 LATIN CAPITAL
                    815:    LETTER X character (X), which must then be followed by one or more
                    816:    digits in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9),
                    817:    U+0061 LATIN SMALL LETTER A to U+0066 LATIN SMALL LETTER F, and
                    818:    U+0041 LATIN CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F,
                    819:    representing a base-sixteen integer that corresponds to a Unicode
                    820:    code point that is allowed according to the definition below. The
                    821:    digits must then be followed by a U+003B SEMICOLON character
                    822:    (;).</dd>
1.378     mike      823: 
                    824:   </dl><p>The numeric character reference forms described above are allowed
                    825:   to reference any Unicode code point other than U+0000, permanently
                    826:   undefined Unicode characters (noncharacters), and control characters
                    827:   other than <a href="infrastructure.html#space-character" title="space character">space
                    828:   characters</a>.</p><p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.464     mike      829:   ampersand</dfn> is a U+0026 AMPERSAND character (&amp;) that is
                    830:   followed by some <a href="#syntax-text" title="syntax-text">text</a> other than a
                    831:   <a href="infrastructure.html#space-character">space character</a>, a U+003C LESS-THAN SIGN character
                    832:   (&lt;), or another U+0026 AMPERSAND character
                    833:   (<code>&amp;</code>).</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      834:   the character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
                    835:   MARK, U+005B LEFT SQUARE BRACKET, U+0043 LATIN CAPITAL LETTER C,
                    836:   U+0044 LATIN CAPITAL LETTER D, U+0041 LATIN CAPITAL LETTER A, U+0054
                    837:   LATIN CAPITAL LETTER T, U+0041 LATIN CAPITAL LETTER A, U+005B LEFT
                    838:   SQUARE BRACKET (<code title="">&lt;![CDATA[</code>). Following this
                    839:   sequence, the CDATA section may have <a href="#syntax-text" title="syntax-text">text</a>, with the additional restriction
                    840:   that the text must not contain the three character sequence U+005D
                    841:   RIGHT SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E
                    842:   GREATER-THAN SIGN (<code title="">]]&gt;</code>). Finally, the CDATA
                    843:   section must be ended by the three character sequence U+005D RIGHT
                    844:   SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E GREATER-THAN
1.159     mike      845:   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      846:   four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
                    847:   MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title="">&lt;!--</code>). Following this sequence, the comment may
                    848:   have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
                    849:   restriction that the text must not start with a single U+003E
1.464     mike      850:   GREATER-THAN SIGN (&gt;) character, nor start with a U+002D
                    851:   HYPHEN-MINUS character (-) followed by a
                    852:   U+003E GREATER-THAN SIGN (&gt;) character, nor contain two
1.1       mike      853:   consecutive U+002D HYPHEN-MINUS (<code title="">-</code>)
                    854:   characters, nor end with a U+002D HYPHEN-MINUS (<code title="">-</code>) character. Finally, the comment must be ended by
                    855:   the three character sequence U+002D HYPHEN-MINUS, U+002D
1.123     mike      856:   HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--&gt;</code>).</p><div class="impl">
1.1       mike      857: 
1.159     mike      858:   <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      859: 
                    860:   <p><i>This section only applies to user agents, data mining tools,
                    861:   and conformance checkers.</i></p>
                    862: 
                    863:   <p class="note">The rules for parsing XML documents into DOM trees
                    864:   are covered by the next section, entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
                    865:   syntax</a>".</p>
                    866: 
                    867:   <p>For <a href="dom.html#html-documents">HTML documents</a>, user agents must use the parsing
                    868:   rules described in this section to generate the DOM trees. Together,
                    869:   these rules define what is referred to as the <dfn id="html-parser">HTML
                    870:   parser</dfn>.</p>
                    871: 
                    872:   <div class="note">
                    873: 
                    874:    <p>While the HTML syntax described in this specification bears a
                    875:    close resemblance to SGML and XML, it is a separate language with
                    876:    its own parsing rules.</p>
                    877: 
1.183     mike      878:    <p>Some earlier versions of HTML (in particular from HTML2 to
                    879:    HTML4) were based on SGML and used SGML parsing rules. However, few
1.1       mike      880:    (if any) web browsers ever implemented true SGML parsing for HTML
                    881:    documents; the only user agents to strictly handle HTML as an SGML
                    882:    application have historically been validators. The resulting
                    883:    confusion &#8212; with validators claiming documents to have one
                    884:    representation while widely deployed Web browsers interoperably
                    885:    implemented a different representation &#8212; has wasted decades
                    886:    of productivity. This version of HTML thus returns to a non-SGML
                    887:    basis.</p>
                    888: 
                    889:    <p>Authors interested in using SGML tools in their authoring
                    890:    pipeline are encouraged to use XML tools and the XML serialization
                    891:    of HTML.</p>
                    892: 
                    893:   </div>
                    894: 
                    895:   <p>This specification defines the parsing rules for HTML documents,
                    896:   whether they are syntactically correct or not. Certain points in the
                    897:   parsing algorithm are said to be <dfn id="parse-error" title="parse error">parse
                    898:   errors</dfn>. The error handling for parse errors is well-defined:
                    899:   user agents must either act as described below when encountering
                    900:   such problems, or must abort processing at the first error that they
                    901:   encounter for which they do not wish to apply the rules described
                    902:   below.</p>
                    903: 
                    904:   <p>Conformance checkers must report at least one parse error
                    905:   condition to the user if one or more parse error conditions exist in
                    906:   the document and must not report parse error conditions if none
                    907:   exist in the document. Conformance checkers may report more than one
1.174     mike      908:   parse error condition if more than one parse error condition exists
1.1       mike      909:   in the document. Conformance checkers are not required to recover
                    910:   from parse errors.</p>
                    911: 
                    912:   <p class="note">Parse errors are only errors with the
                    913:   <em>syntax</em> of HTML. In addition to checking for parse errors,
                    914:   conformance checkers will also verify that the document obeys all
                    915:   the other conformance requirements described in this
                    916:   specification.</p>
                    917: 
                    918:   <p>For the purposes of conformance checkers, if a resource is
                    919:   determined to be in <a href="#syntax">the HTML syntax</a>, then it is an
                    920:   <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                    921: 
1.266     mike      922:   </div><div class="impl">
1.1       mike      923: 
                    924:   <h4 id="overview-of-the-parsing-model"><span class="secno">9.2.1 </span>Overview of the parsing model</h4>
                    925: 
                    926:   <p>The input to the HTML parsing process consists of a stream of
                    927:   Unicode characters, which is passed through a
                    928:   <a href="#tokenization">tokenization</a> stage followed by a <a href="#tree-construction">tree
                    929:   construction</a> stage. The output is a <code>Document</code>
                    930:   object.</p>
                    931: 
                    932:   <p class="note">Implementations that <a href="infrastructure.html#non-scripted">do not
                    933:   support scripting</a> do not have to actually create a DOM
                    934:   <code>Document</code> object, but the DOM tree in such cases is
                    935:   still used as the model for the rest of the specification.</p>
                    936: 
                    937:   <p>In the common case, the data handled by the tokenization stage
1.159     mike      938:   comes from the network, but <a href="embedded-content-0.html#dynamic-markup-insertion" title="dynamic markup
                    939:   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      940: 
                    941:   <p><img alt="" src="images/parsing-model-overview.png"></p>
                    942: 
                    943:   <p id="nestedParsing">There is only one set of states for the
                    944:   tokenizer stage and the tree construction stage, but the tree
                    945:   construction stage is reentrant, meaning that while the tree
                    946:   construction stage is handling one token, the tokenizer might be
                    947:   resumed, causing further tokens to be emitted and processed before
                    948:   the first token's processing is complete.</p>
                    949: 
                    950:   <div class="example">
                    951: 
                    952:    <p>In the following example, the tree construction stage will be
                    953:    called upon to handle a "p" start tag token while handling the
                    954:    "script" start tag token:</p>
                    955: 
                    956:    <pre>...
                    957: &lt;script&gt;
                    958:  document.write('&lt;p&gt;');
                    959: &lt;/script&gt;
                    960: ...</pre>
                    961: 
                    962:   </div>
                    963: 
                    964:   <p>To handle these cases, parsers have a <dfn id="script-nesting-level">script nesting
                    965:   level</dfn>, which must be initially set to zero, and a <dfn id="parser-pause-flag">parser
                    966:   pause flag</dfn>, which must be initially set to false.</p>
                    967: 
1.266     mike      968:   </div><div class="impl">
1.1       mike      969: 
                    970:   <h4 id="the-input-stream"><span class="secno">9.2.2 </span>The <dfn>input stream</dfn></h4>
                    971: 
                    972:   <p>The stream of Unicode characters that comprises the input to the
                    973:   tokenization stage will be initially seen by the user agent as a
                    974:   stream of bytes (typically coming over the network or from the local
                    975:   file system). The bytes encode the actual characters according to a
                    976:   particular <em>character encoding</em>, which the user agent must
                    977:   use to decode the bytes into characters.</p>
                    978: 
                    979:   <p class="note">For XML documents, the algorithm user agents must
                    980:   use to determine the character encoding is given by the XML
1.104     mike      981:   specification. This section does not apply to XML documents. <a href="references.html#refsXML">[XML]</a></p>
1.1       mike      982: 
                    983: 
1.168     mike      984:   <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      985: 
                    986:   <p>In some cases, it might be impractical to unambiguously determine
                    987:   the encoding before parsing the document. Because of this, this
                    988:   specification provides for a two-pass mechanism with an optional
                    989:   pre-scan. Implementations are allowed, as described below, to apply
                    990:   a simplified parsing algorithm to whatever bytes they have available
                    991:   before beginning to parse the document. Then, the real parser is
                    992:   started, using a tentative encoding derived from this pre-parse and
                    993:   other out-of-band metadata. If, while the document is being loaded,
                    994:   the user agent discovers an encoding declaration that conflicts with
                    995:   this information, then the parser can get reinvoked to perform a
                    996:   parse of the document with the real encoding.</p>
                    997: 
                    998:   <p id="documentEncoding">User agents must use the following
                    999:   algorithm (the <dfn id="encoding-sniffing-algorithm">encoding sniffing algorithm</dfn>) to determine
                   1000:   the character encoding to use when decoding a document in the first
                   1001:   pass. This algorithm takes as input any out-of-band metadata
                   1002:   available to the user agent (e.g. the <a href="infrastructure.html#content-type" title="Content-Type">Content-Type metadata</a> of the document)
                   1003:   and all the bytes available so far, and returns an encoding and a
                   1004:   <dfn id="concept-encoding-confidence" title="concept-encoding-confidence">confidence</dfn>. The
                   1005:   confidence is either <i>tentative</i>, <i>certain</i>, or
                   1006:   <i>irrelevant</i>. The encoding used, and whether the confidence in
                   1007:   that encoding is <i>tentative</i> or <i>certain</i>, is <a href="#meta-charset-during-parse">used during the parsing</a> to
                   1008:   determine whether to <a href="#change-the-encoding">change the encoding</a>. If no
                   1009:   encoding is necessary, e.g. because the parser is operating on a
                   1010:   stream of Unicode characters and doesn't have to use an encoding at
                   1011:   all, then the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   1012:   <i>irrelevant</i>.</p>
                   1013: 
                   1014:   <ol><li><p>If the transport layer specifies an encoding, and it is
                   1015:    supported, return that encoding with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1016:    <i>certain</i>, and abort these steps.</p></li>
                   1017: 
                   1018:    <li><p>The user agent may wait for more bytes of the resource to be
                   1019:    available, either in this step or at any later step in this
                   1020:    algorithm. For instance, a user agent might wait 500ms or 512
                   1021:    bytes, whichever came first. In general preparsing the source to
                   1022:    find the encoding improves performance, as it reduces the need to
                   1023:    throw away the data structures used when parsing upon finding the
                   1024:    encoding information. However, if the user agent delays too long to
                   1025:    obtain data to determine the encoding, then the cost of the delay
                   1026:    could outweigh any performance improvements from the
                   1027:    preparse.</p></li>
                   1028: 
                   1029:    <li><p>For each of the rows in the following table, starting with
                   1030:    the first one and going down, if there are as many or more bytes
                   1031:    available than the number of bytes in the first column, and the
                   1032:    first bytes of the file match the bytes given in the first column,
                   1033:    then return the encoding given in the cell in the second column of
                   1034:    that row, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1035:    <i>certain</i>, and abort these steps:</p>
                   1036: 
                   1037:     <!-- this table is present in several forms in this file; keep them in sync -->
                   1038:     <table><thead><tr><th>Bytes in Hexadecimal
                   1039:        </th><th>Encoding
                   1040:      </th></tr></thead><tbody><!-- nobody uses this
                   1041:       <tr>
                   1042:        <td>00 00 FE FF
                   1043:        <td>UTF-32BE
                   1044:       <tr>
                   1045:        <td>FF FE 00 00
                   1046:        <td>UTF-32LE
                   1047: --><tr><td>FE FF
                   1048:        </td><td>UTF-16BE
                   1049:       </td></tr><tr><td>FF FE
                   1050:        </td><td>UTF-16LE
                   1051:       </td></tr><tr><td>EF BB BF
                   1052:        </td><td>UTF-8
                   1053: <!-- nobody uses this
                   1054:       <tr>
                   1055:        <td>DD 73 66 73
                   1056:        <td>UTF-EBCDIC
                   1057: -->
                   1058:     </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
                   1059:    (BOMs).</p></li>
                   1060: 
                   1061:    <li><p>Otherwise, the user agent will have to search for explicit
                   1062:    character encoding information in the file itself. This should
                   1063:    proceed as follows:
                   1064: 
                   1065:     </p><p>Let <var title="">position</var> be a pointer to a byte in the
                   1066:     input stream, initially pointing at the first byte. If at any
                   1067:     point during these substeps the user agent either runs out of
                   1068:     bytes or decides that scanning further bytes would not be
                   1069:     efficient, then skip to the next step of the overall character
                   1070:     encoding detection algorithm. User agents may decide that scanning
                   1071:     <em>any</em> bytes is not efficient, in which case these substeps
                   1072:     are entirely skipped.</p>
                   1073: 
                   1074:     <p>Now, repeat the following "two" steps until the algorithm
                   1075:     aborts (either because user agent aborts, as described above, or
                   1076:     because a character encoding is found):</p>
                   1077: 
                   1078:     <ol><li><p>If <var title="">position</var> points to:</p>
                   1079: 
                   1080:       <dl class="switch"><dt>A sequence of bytes starting with: 0x3C 0x21 0x2D 0x2D (ASCII '&lt;!--')</dt>
                   1081:        <dd>
                   1082: 
                   1083:         <p>Advance the <var title="">position</var> pointer so that it
                   1084:         points at the first 0x3E byte which is preceded by two 0x2D
                   1085:         bytes (i.e. at the end of an ASCII '--&gt;' sequence) and comes
                   1086:         after the 0x3C byte that was found. (The two 0x2D bytes can be
                   1087:         the same as the those in the '&lt;!--' sequence.)</p>
                   1088: 
                   1089:        </dd>
                   1090: 
                   1091:        <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>
                   1092:        <dd>
                   1093: 
                   1094:         <ol><li><p>Advance the <var title="">position</var> pointer so
                   1095:          that it points at the next 0x09, 0x0A, 0x0C, 0x0D, 0x20, or
                   1096:          0x2F byte (the one in sequence of characters matched
                   1097:          above).</p></li>
                   1098: 
                   1099:          <li><p><a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">Get
                   1100:          an attribute</a> and its value. If no attribute was
                   1101:          sniffed, then skip this inner set of steps, and jump to the
                   1102:          second step in the overall "two step" algorithm.</p></li>
                   1103: 
                   1104:          <li><p>If the attribute's name is neither "<code title="">charset</code>" nor "<code title="">content</code>",
                   1105:          then return to step 2 in these inner steps.</p></li>
                   1106: 
                   1107:          <li><p>If the attribute's name is "<code title="">charset</code>", let <var title="">charset</var> be
                   1108:          the attribute's value, interpreted as a character
                   1109:          encoding.</p></li>
                   1110: 
                   1111:          <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
                   1112:          extracting an encoding from a Content-Type</a>, giving the
                   1113:          attribute's value as the string to parse. If an encoding is
                   1114:          returned, let <var title="">charset</var> be that
                   1115:          encoding. Otherwise, return to step 2 in these inner
                   1116:          steps.</p></li>
                   1117: 
                   1118:          <li><p>If <var title="">charset</var> is a UTF-16 encoding,
                   1119:          change the value of <var title="">charset</var> to
                   1120:          UTF-8.</p></li>
                   1121: 
                   1122:          <li><p>If <var title="">charset</var> is a supported
                   1123:          character encoding, then return the given encoding, with
                   1124:          <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1125:          <i>tentative</i>, and abort all these steps.</p></li>
                   1126: 
                   1127:          <li><p>Otherwise, return to step 2 in these inner
                   1128:          steps.</p></li>
                   1129: 
                   1130:         </ol></dd>
                   1131: 
1.464     mike     1132:        <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>
1.1       mike     1133:        <dd>
                   1134: 
                   1135:         <ol><li><p>Advance the <var title="">position</var> pointer so
                   1136:          that it points at the next 0x09 (ASCII TAB), 0x0A (ASCII LF),
                   1137:          0x0C (ASCII FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E
1.464     mike     1138:          (ASCII &gt;) byte.</p></li>
1.1       mike     1139: 
                   1140:          <li><p>Repeatedly <a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
                   1141:          attribute</a> until no further attributes can be found,
                   1142:          then jump to the second step in the overall "two step"
                   1143:          algorithm.</p></li>
                   1144: 
                   1145:         </ol></dd>
                   1146: 
                   1147:        <dt>A sequence of bytes starting with: 0x3C 0x21 (ASCII '&lt;!')</dt>
                   1148:        <dt>A sequence of bytes starting with: 0x3C 0x2F (ASCII '&lt;/')</dt>
                   1149:        <dt>A sequence of bytes starting with: 0x3C 0x3F (ASCII '&lt;?')</dt>
                   1150:        <dd>
                   1151: 
                   1152:         <p>Advance the <var title="">position</var> pointer so that it
1.464     mike     1153:         points at the first 0x3E byte (ASCII &gt;) that comes after the
1.1       mike     1154:         0x3C byte that was found.</p>
                   1155: 
                   1156:        </dd>
                   1157: 
                   1158:        <dt>Any other byte</dt>
                   1159:        <dd>
                   1160: 
                   1161:         <p>Do nothing with that byte.</p>
                   1162: 
                   1163:        </dd>
                   1164: 
                   1165:       </dl></li>
                   1166: 
                   1167:      <li>Move <var title="">position</var> so it points at the next
                   1168:      byte in the input stream, and return to the first step of this
                   1169:      "two step" algorithm.</li>
                   1170: 
                   1171:     </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
                   1172:     attribute</dfn>, it means doing this:</p>
                   1173: 
                   1174:     <ol><li><p>If the byte at <var title="">position</var> is one of 0x09
                   1175:      (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII FF), 0x0D (ASCII CR),
1.464     mike     1176:      0x20 (ASCII space), or 0x2F (ASCII /) then advance <var title="">position</var> to the next byte and redo this
1.1       mike     1177:      substep.</p></li>
                   1178: 
                   1179:      <li><p>If the byte at <var title="">position</var> is 0x3E (ASCII
1.464     mike     1180:      &gt;), then abort the "get an attribute" algorithm. There isn't
1.1       mike     1181:      one.</p></li>
                   1182: 
                   1183:      <li><p>Otherwise, the byte at <var title="">position</var> is the
                   1184:      start of the attribute name. Let <var title="">attribute
                   1185:      name</var> and <var title="">attribute value</var> be the empty
                   1186:      string.</p></li>
                   1187: 
                   1188:      <li><p><i>Attribute name</i>: Process the byte at <var title="">position</var> as follows:</p>
                   1189: 
1.464     mike     1190:       <dl class="switch"><dt>If it is 0x3D (ASCII =), and the <var title="">attribute
1.1       mike     1191:        name</var> is longer than the empty string</dt>
                   1192: 
                   1193:        <dd>Advance <var title="">position</var> to the next byte and
                   1194:        jump to the step below labeled <i>value</i>.</dd>
                   1195: 
                   1196:        <dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
                   1197:        FF), 0x0D (ASCII CR), or 0x20 (ASCII space)</dt>
                   1198: 
                   1199:        <dd>Jump to the step below labeled <i>spaces</i>.</dd>
                   1200: 
1.464     mike     1201:        <dt>If it is 0x2F (ASCII /) or 0x3E (ASCII &gt;)</dt>
1.1       mike     1202: 
                   1203:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1204:        name is the value of <var title="">attribute name</var>, its
                   1205:        value is the empty string.</dd>
                   1206: 
1.464     mike     1207:        <dt>If it is in the range 0x41 (ASCII A) to 0x5A (ASCII
                   1208:        Z)</dt>
1.1       mike     1209: 
                   1210:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1211:        name</var> (where <var title="">b</var> is the value of the
                   1212:        byte at <var title="">position</var>).</dd>
                   1213: 
                   1214:        <dt>Anything else</dt>
                   1215: 
                   1216:        <dd>Append the Unicode character with the same code point as the
                   1217:        value of the byte at <var title="">position</var>) to <var title="">attribute name</var>. (It doesn't actually matter how
                   1218:        bytes outside the ASCII range are handled here, since only
                   1219:        ASCII characters can contribute to the detection of a character
                   1220:        encoding.)</dd>
                   1221: 
                   1222:       </dl></li>
                   1223: 
                   1224:      <li><p>Advance <var title="">position</var> to the next byte and
                   1225:      return to the previous step.</p></li>
                   1226: 
                   1227:      <li><p><i>Spaces</i>: If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
                   1228:      LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
                   1229:      advance <var title="">position</var> to the next byte, then,
                   1230:      repeat this step.</p></li>
                   1231: 
                   1232:      <li><p>If the byte at <var title="">position</var> is
1.464     mike     1233:      <em>not</em> 0x3D (ASCII =), abort the "get an attribute"
1.1       mike     1234:      algorithm. The attribute's name is the value of <var title="">attribute name</var>, its value is the empty
                   1235:      string.</p></li>
                   1236: 
                   1237:      <li><p>Advance <var title="">position</var> past the 0x3D (ASCII
1.464     mike     1238:      =) byte.</p></li>
1.1       mike     1239: 
                   1240:      <li><p><i>Value:</i> If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
                   1241:      LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
                   1242:      advance <var title="">position</var> to the next byte, then,
                   1243:      repeat this step.</p></li>
                   1244: 
                   1245:      <li><p>Process the byte at <var title="">position</var> as
                   1246:      follows:</p>
                   1247: 
1.464     mike     1248:       <dl class="switch"><dt>If it is 0x22 (ASCII ") or 0x27 (ASCII ')</dt>
1.1       mike     1249: 
                   1250:        <dd>
                   1251: 
                   1252:         <ol><li>Let <var title="">b</var> be the value of the byte at
                   1253:          <var title="">position</var>.</li>
                   1254: 
                   1255:          <li>Advance <var title="">position</var> to the next
                   1256:          byte.</li>
                   1257: 
                   1258:          <li>If the value of the byte at <var title="">position</var>
                   1259:          is the value of <var title="">b</var>, then advance <var title="">position</var> to the next byte and abort the "get
                   1260:          an attribute" algorithm. The attribute's name is the value of
                   1261:          <var title="">attribute name</var>, and its value is the
                   1262:          value of <var title="">attribute value</var>.</li>
                   1263: 
1.464     mike     1264:          <li>Otherwise, if the value of the byte at <var title="">position</var> is in the range 0x41 (ASCII A) to
                   1265:          0x5A (ASCII Z), then append a Unicode character to <var title="">attribute value</var> whose code point is 0x20 more
1.1       mike     1266:          than the value of the byte at <var title="">position</var>.</li>
                   1267: 
                   1268:          <li>Otherwise, append a Unicode character to <var title="">attribute value</var> whose code point is the same as
                   1269:          the value of the byte at <var title="">position</var>.</li>
                   1270: 
                   1271:          <li>Return to the second step in these substeps.</li>
                   1272: 
                   1273:         </ol></dd>
                   1274: 
1.464     mike     1275:        <dt>If it is 0x3E (ASCII &gt;)</dt>
1.1       mike     1276: 
                   1277:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1278:        name is the value of <var title="">attribute name</var>, its
                   1279:        value is the empty string.</dd>
                   1280: 
                   1281: 
1.464     mike     1282:        <dt>If it is in the range 0x41 (ASCII A) to 0x5A (ASCII
                   1283:        Z)</dt>
1.1       mike     1284: 
                   1285:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1286:        value</var> (where <var title="">b</var> is the value of the
                   1287:        byte at <var title="">position</var>). Advance <var title="">position</var> to the next byte.</dd>
                   1288: 
                   1289:        <dt>Anything else</dt>
                   1290: 
                   1291:        <dd>Append the Unicode character with the same code point as the
                   1292:        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>
                   1293: 
                   1294:       </dl></li>
                   1295: 
                   1296:      <li><p>Process the byte at <var title="">position</var> as
                   1297:      follows:</p>
                   1298: 
                   1299:       <dl class="switch"><dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
                   1300:        FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E (ASCII
1.464     mike     1301:        &gt;)</dt>
1.1       mike     1302: 
                   1303:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1304:        name is the value of <var title="">attribute name</var> and its
                   1305:        value is the value of <var title="">attribute value</var>.</dd>
                   1306: 
1.464     mike     1307:        <dt>If it is in the range 0x41 (ASCII A) to 0x5A (ASCII
                   1308:        Z)</dt>
1.1       mike     1309: 
                   1310:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1311:        value</var> (where <var title="">b</var> is the value of the
                   1312:        byte at <var title="">position</var>).</dd>
                   1313: 
                   1314:        <dt>Anything else</dt>
                   1315: 
                   1316:        <dd>Append the Unicode character with the same code point as the
                   1317:        value of the byte at <var title="">position</var>) to <var title="">attribute value</var>.</dd>
                   1318: 
                   1319:       </dl></li>
                   1320: 
                   1321:      <li><p>Advance <var title="">position</var> to the next byte and
                   1322:      return to the previous step.</p></li>
                   1323: 
                   1324:     </ol><p>For the sake of interoperability, user agents should not use a
                   1325:     pre-scan algorithm that returns different results than the one
                   1326:     described above. (But, if you do, please at least let us know, so
                   1327:     that we can improve this algorithm and benefit everyone...)</p>
                   1328: 
                   1329:    </li>
                   1330: 
                   1331:    <li><p>If the user agent has information on the likely encoding for
                   1332:    this page, e.g. based on the encoding of the page when it was last
                   1333:    visited, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1334:    <i>tentative</i>, and abort these steps.</p></li>
                   1335: 
1.322     mike     1336:    <li>
                   1337: 
                   1338:     <p>The user agent may attempt to autodetect the character encoding
                   1339:     from applying frequency analysis or other algorithms to the data
                   1340:     stream. If autodetection succeeds in determining a character
                   1341:     encoding, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1342:     <i>tentative</i>, and abort these steps. <a href="references.html#refsUNIVCHARDET">[UNIVCHARDET]</a></p>
                   1343: 
                   1344:     <p class="note">The UTF-8 encoding has a highly detectable bit
                   1345:     pattern. Documents that contain bytes with values greater than
                   1346:     0x7F which match the UTF-8 pattern are very likely to be UTF-8,
                   1347:     while documents with byte sequences that do not match it are very
                   1348:     likely not. User-agents are therefore encouraged to search for
1.485     mike     1349:     this common encoding. <a href="references.html#refsPPUTF8">[PPUTF8]</a> <a href="references.html#refsUTF8DET">[UTF8DET]</a></p>
1.322     mike     1350: 
                   1351:    </li>
1.1       mike     1352: 
1.501   ! mike     1353:    <li>
        !          1354: 
        !          1355:     <p>Otherwise, return an implementation-defined or user-specified
        !          1356:     default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
        !          1357:     <i>tentative</i>.</p>
        !          1358: 
        !          1359:     <p>In controlled environments or in environments where the
        !          1360:     encoding of documents can be prescribed (for example, for user
        !          1361:     agents intended for dedicated use in new networks), the
        !          1362:     comprehensive <code title="">UTF-8</code> encoding is
        !          1363:     suggested.</p>
        !          1364: 
        !          1365:     <p>In other environments, the default encoding is typically
        !          1366:     dependent on the user's locale (an approximation of the languages,
        !          1367:     and thus typically encodings, of the pages that the user is likely
        !          1368:     to frequent). The following table gives suggested defaults based
        !          1369:     on the user's locale, for compatibility with legacy content:</p>
        !          1370: 
        !          1371:     <!-- based on mozilla 1.9.1 localizations: 
        !          1372:          http://mxr.mozilla.org/l10n-mozilla1.9.1/find?string=global%2Fintl.properties&tree=l10n-mozilla1.9.1&hint= -->
        !          1373: 
        !          1374:     <table><thead><tr><th>Locale
        !          1375:        </th><th>Suggested default encoding
        !          1376:      </th></tr></thead><tbody><tr><td>ar
        !          1377:        </td><td>UTF-8
        !          1378: 
        !          1379:       </td></tr><tr><td>be
        !          1380:        </td><td>ISO-8859-5
        !          1381: 
        !          1382:       </td></tr><tr><td>bg
        !          1383:        </td><td>windows-1251
        !          1384: 
        !          1385:       </td></tr><tr><td>cs<!-- -CZ -->
        !          1386:        </td><td>ISO-8859-2
        !          1387: 
        !          1388:       </td></tr><tr><td>cy
        !          1389:        </td><td>UTF-8
        !          1390: 
        !          1391:       </td></tr><tr><td>fa<!-- -IR -->
        !          1392:        </td><td>UTF-8
        !          1393: 
        !          1394:       </td></tr><tr><td>he<!-- -IL -->
        !          1395:        </td><td>windows-1255
        !          1396: 
        !          1397:       </td></tr><tr><td>hr
        !          1398:        </td><td>UTF-8
        !          1399: 
        !          1400:       </td></tr><tr><td>hu<!-- -HU -->
        !          1401:        </td><td>ISO-8859-2
        !          1402: 
        !          1403:       </td></tr><tr><td>ja <!-- and ja-JP-mac -->
        !          1404:        </td><td>windows-31J <!-- Shift_JIS -->
        !          1405: 
        !          1406:       </td></tr><tr><td>kk
        !          1407:        </td><td>UTF-8
        !          1408: 
        !          1409:       </td></tr><tr><td>ko<!-- -KR -->
        !          1410:        </td><td>windows-949 <!-- EUC-KR -->
        !          1411: 
        !          1412:       </td></tr><tr><td>ku
        !          1413:        </td><td>windows-1254 <!-- ISO-8859-9 -->
        !          1414: 
        !          1415:       </td></tr><tr><td>lt
        !          1416:        </td><td>windows-1257
        !          1417: 
        !          1418:       </td></tr><tr><td>lv<!-- -LV -->
        !          1419:        </td><td>ISO-8859-13
        !          1420: 
        !          1421:       </td></tr><tr><td>mk<!-- -MK -->
        !          1422:        </td><td>UTF-8
        !          1423: 
        !          1424:       </td></tr><tr><td>or
        !          1425:        </td><td>UTF-8
        !          1426: 
        !          1427:       </td></tr><tr><td>pl<!-- -PL -->
        !          1428:        </td><td>ISO-8859-2
        !          1429: 
        !          1430:       </td></tr><tr><td>ro
        !          1431:        </td><td>UTF-8
        !          1432: 
        !          1433:       </td></tr><tr><td>ru
        !          1434:        </td><td>windows-1251
        !          1435: 
        !          1436:       </td></tr><tr><td>sk
        !          1437:        </td><td>windows-1250
        !          1438: 
        !          1439:       </td></tr><tr><td>sl
        !          1440:        </td><td>ISO-8859-2
        !          1441: 
        !          1442:       </td></tr><tr><td>sr
        !          1443:        </td><td>UTF-8
        !          1444: 
        !          1445:       </td></tr><tr><td>th
        !          1446:        </td><td>windows-874 <!-- TIS-620 -->
        !          1447: 
        !          1448:       </td></tr><tr><td>tr<!-- -TR -->
        !          1449:        </td><td>windows-1254 <!-- ISO-8859-9 -->
        !          1450: 
        !          1451:       </td></tr><tr><td>uk
        !          1452:        </td><td>windows-1251
        !          1453: 
        !          1454:       </td></tr><tr><td>vi
        !          1455:        </td><td>UTF-8
        !          1456: 
        !          1457:       </td></tr><tr><td>zh-CN
        !          1458:        </td><td>GB18030
        !          1459: 
        !          1460:       </td></tr><tr><td>zh-TW
        !          1461:        </td><td>Big5
        !          1462: 
        !          1463:       </td></tr><tr><td>All other locales
        !          1464:        </td><td>windows-1252
        !          1465: 
        !          1466:     </td></tr></tbody></table></li>
1.1       mike     1467: 
                   1468:   </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
                   1469:   be set to the value returned from this algorithm, at the same time
                   1470:   as the user agent uses the returned value to select the decoder to
                   1471:   use for the input stream.</p>
                   1472: 
                   1473: 
1.237     mike     1474:   <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     1475: 
1.237     mike     1476:   <p>User agents must at a minimum support the UTF-8 and Windows-1252
                   1477:   encodings, but may support more.</p>
                   1478: 
                   1479:   <p class="note">It is not unusual for Web browsers to support dozens
                   1480:   if not upwards of a hundred distinct character encodings.</p>
                   1481: 
1.365     mike     1482:   <p>User agents must support the <a href="infrastructure.html#preferred-mime-name">preferred MIME name</a> of
                   1483:   every character encoding they support, and should support all the
                   1484:   IANA-registered names and aliases of every character encoding they
                   1485:   support. <a href="references.html#refsIANACHARSET">[IANACHARSET]</a></p>
1.237     mike     1486: 
                   1487:   <p>When comparing a string specifying a character encoding with the
                   1488:   name or alias of a character encoding to determine if they are
                   1489:   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
                   1490:   then perform the comparison in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   1491:   case-insensitive</a> manner.</p>
                   1492: 
                   1493: <!-- this bit will be replaced by actual alias registrations in due course -->
                   1494: 
                   1495:   <p>In addition, user agents must support the aliases given in the
                   1496:   following table for every character encoding they support, so that
                   1497:   labels from the first column are treated as equivalent to the labels
                   1498:   given in the corresponding cell from the second column on the same
                   1499:   row.</p>
                   1500: 
                   1501:   <table><caption>Additional character encoding aliases</caption>
                   1502:    <thead><tr><th> Alias </th><th> Corresponding encoding </th><th> References
                   1503:    </th></tr></thead><tbody><tr><td> x-sjis </td><td> windows-31J </td><td>
                   1504:          <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
                   1505:          <a href="references.html#refsWIN31J">[WIN31J]</a>
                   1506:     </td></tr><tr><td> windows-932 </td><td> windows-31J </td><td>
                   1507:          <a href="references.html#refsWIN31J">[WIN31J]</a>
                   1508:     </td></tr><tr><td> x-x-big5 </td><td> Big5 </td><td>
                   1509:          <a href="references.html#refsBIG5">[BIG5]</a>
                   1510:    </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
                   1511:   first column of the following table to either convert content to
                   1512:   Unicode characters or convert Unicode characters to bytes, it must
                   1513:   instead use the encoding given in the cell in the second column of
                   1514:   the same row. When a byte or sequence of bytes is treated
                   1515:   differently due to this encoding aliasing, it is said to have been
                   1516:   <dfn id="misinterpreted-for-compatibility">misinterpreted for compatibility</dfn>.</p>
                   1517: 
                   1518:   <table><caption>Character encoding overrides</caption>
                   1519:    <thead><tr><th> Input encoding </th><th> Replacement encoding </th><th> References
                   1520:    </th></tr></thead><tbody><!-- how about EUC-JP? --><tr><td> EUC-KR </td><td> windows-949 </td><td>
                   1521:          <a href="references.html#refsEUCKR">[EUCKR]</a>
                   1522:          <a href="references.html#refsWIN949">[WIN949]</a>
                   1523:     </td></tr><tr><td> GB2312 </td><td> GBK </td><td>
                   1524:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1525:          <a href="references.html#refsGBK">[GBK]</a>
                   1526:     </td></tr><tr><td> GB_2312-80 </td><td> GBK </td><td>
                   1527:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1528:          <a href="references.html#refsGBK">[GBK]</a>
                   1529:     </td></tr><tr><td> ISO-8859-1 </td><td> windows-1252 </td><td>
                   1530:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1531:          <a href="references.html#refsWIN1252">[WIN1252]</a>
                   1532:     </td></tr><tr><td> ISO-8859-9 </td><td> windows-1254 </td><td>
                   1533:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1534:          <a href="references.html#refsWIN1254">[WIN1254]</a>
                   1535:     </td></tr><tr><td> ISO-8859-11 </td><td> windows-874 </td><td>
                   1536:          <a href="references.html#refsISO885911">[ISO885911]</a>
                   1537:          <a href="references.html#refsWIN874">[WIN874]</a>
                   1538:     </td></tr><tr><td> KS_C_5601-1987 </td><td> windows-949 </td><td>
                   1539:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1540:          <a href="references.html#refsWIN949">[WIN949]</a>
                   1541:     </td></tr><tr><td> Shift_JIS </td><td> windows-31J </td><td>
                   1542:          <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
                   1543:          <a href="references.html#refsWIN31J">[WIN31J]</a>
                   1544:     </td></tr><tr><td> TIS-620 </td><td> windows-874 </td><td>
                   1545:          <a href="references.html#refsTIS620">[TIS620]</a>
                   1546:          <a href="references.html#refsWIN874">[WIN874]</a>
                   1547:     </td></tr><tr><td> US-ASCII </td><td> windows-1252 </td><td>
                   1548:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1549:          <a href="references.html#refsWIN1252">[WIN1252]</a>
                   1550:    </td></tr></tbody></table><p class="note">The requirement to treat certain encodings as other
                   1551:   encodings according to the table above is a <a href="introduction.html#willful-violation">willful
                   1552:   violation</a> of the W3C Character Model specification, motivated
                   1553:   by a desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
                   1554: 
                   1555:   <p>When a user agent is to use the UTF-16 encoding but no BOM has
                   1556:   been found, user agents must default to UTF-16LE.</p>
                   1557: 
                   1558:   <p class="note">The requirement to default UTF-16 to LE rather than
                   1559:   BE is a <a href="introduction.html#willful-violation">willful violation</a> of RFC 2781, motivated by a
                   1560:   desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
                   1561: 
                   1562:   <hr><p>User agents must not support the CESU-8, UTF-7, BOCU-1 and SCSU
                   1563:   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>
                   1564: 
                   1565:   <p>Support for encodings based on EBCDIC is not recommended. This
                   1566:   encoding is rarely used for publicly-facing Web content.</p>
                   1567: 
                   1568:   <p>Support for UTF-32 is not recommended. This encoding is rarely
                   1569:   used, and frequently implemented incorrectly.</p>
                   1570: 
                   1571:   <p class="note">This specification does not make any attempt to
                   1572:   support EBCDIC-based encodings and UTF-32 in its algorithms; support
                   1573:   and use of these encodings can thus lead to unexpected behavior in
                   1574:   implementations of this specification.</p>
                   1575: 
                   1576: 
                   1577: 
                   1578:   <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.3 </span>Preprocessing the input stream</h5>
1.1       mike     1579: 
                   1580:   <p>Given an encoding, the bytes in the input stream must be
                   1581:   converted to Unicode characters for the tokenizer, as described by
                   1582:   the rules for that encoding, except that the leading U+FEFF BYTE
                   1583:   ORDER MARK character, if any, must not be stripped by the encoding
                   1584:   layer (it is stripped by the rule below).</p> <!-- this is to
                   1585:   prevent two leading BOMs from being both stripped, once by the
                   1586:   decoder, and once by the parser -->
                   1587: 
                   1588:   <p>Bytes or sequences of bytes in the original byte stream that
1.393     mike     1589:   could not be converted to Unicode code points must be converted to
                   1590:   U+FFFD REPLACEMENT CHARACTERs.</p>
1.1       mike     1591: 
                   1592:   <p class="note">Bytes or sequences of bytes in the original byte
                   1593:   stream that did not conform to the encoding specification
                   1594:   (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
                   1595:   errors that conformance checkers are expected to report.</p>
                   1596: 
1.438     mike     1597:   <p>Any byte or sequence of bytes in the original byte stream that is
                   1598:   <a href="#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
1.1       mike     1599:   error</a>.</p>
                   1600: 
                   1601:   <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
                   1602:   any are present.</p>
                   1603: 
1.300     mike     1604:   <p class="note">The requirement to strip a U+FEFF BYTE ORDER MARK
                   1605:   character regardless of whether that character was used to determine
                   1606:   the byte order is a <a href="introduction.html#willful-violation">willful violation</a> of Unicode,
                   1607:   motivated by a desire to increase the resilience of user agents in
                   1608:   the face of na&#239;ve transcoders.</p>
                   1609: 
1.316     mike     1610:   <p>All U+0000 NULL characters and code points in the range U+D800 to
1.315     mike     1611:   U+DFFF<!-- surrogates not allowed e.g. in UTF-8, and we don't want
                   1612:   them to suddenly turn into codepoints when they go through a UTF-16
                   1613:   pipe --> in the input must be replaced by U+FFFD REPLACEMENT
1.316     mike     1614:   CHARACTERs. Any occurrences of such characters and code points are
                   1615:   <a href="#parse-error" title="parse error">parse errors</a>.</p>
1.1       mike     1616: 
                   1617:   <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
                   1618:   <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
                   1619:   CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
1.315     mike     1620:   <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+FDD0
                   1621:   to U+FDEF, and characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF,
                   1622:   U+2FFFE, U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE,
                   1623:   U+5FFFF, U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF,
                   1624:   U+9FFFE, U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE,
                   1625:   U+CFFFF, U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF,
                   1626:   U+10FFFE, and U+10FFFF are <a href="#parse-error" title="parse error">parse
1.316     mike     1627:   errors</a>. These are all control characters or permanently
                   1628:   undefined Unicode characters (noncharacters).</p>
1.1       mike     1629: 
                   1630:   <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
                   1631:   characters are treated specially. Any CR characters that are
                   1632:   followed by LF characters must be removed, and any CR characters not
                   1633:   followed by LF characters must be converted to LF characters. Thus,
                   1634:   newlines in HTML DOMs are represented by LF characters, and there
                   1635:   are never any CR characters in the input to the
                   1636:   <a href="#tokenization">tokenization</a> stage.</p>
                   1637: 
                   1638:   <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
                   1639:   input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
                   1640:   the <i><a href="#next-input-character">next input character</a></i> is the first character in the
                   1641:   input. The <dfn id="current-input-character">current input character</dfn> is the last character
                   1642:   to have been <i><a href="#consumed">consumed</a></i>.</p>
                   1643: 
                   1644:   <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
                   1645:   character or just before the end of the input stream) where content
1.159     mike     1646:   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     1647:   inserted. The insertion point is relative to the position of the
                   1648:   character immediately after it, it is not an absolute offset into
                   1649:   the input stream. Initially, the insertion point is
1.10      mike     1650:   undefined.</p>
1.1       mike     1651: 
                   1652:   <p>The "EOF" character in the tables below is a conceptual character
                   1653:   representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
1.159     mike     1654:   is a <a href="embedded-content-0.html#script-created-parser">script-created parser</a>, then the end of the
1.1       mike     1655:   <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
1.159     mike     1656:   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     1657:   consumed. Otherwise, the "EOF" character is not a real character in
                   1658:   the stream, but rather the lack of any further characters.</p>
                   1659: 
                   1660: 
1.237     mike     1661:   <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.4 </span>Changing the encoding while parsing</h5>
1.1       mike     1662: 
                   1663:   <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
                   1664:   encoding</dfn>, it must run the following steps. This might happen
                   1665:   if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
                   1666:   failed to find an encoding, or if it found an encoding that was not
                   1667:   the actual encoding of the file.</p>
                   1668: 
                   1669:   <ol><li>If the new encoding is identical or equivalent to the encoding
                   1670:    that is already being used to interpret the input stream, then set
                   1671:    the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1672:    <i>certain</i> and abort these steps. This happens when the
                   1673:    encoding information found in the file matches what the
                   1674:    <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
                   1675:    encoding, and in the second pass through the parser if the first
                   1676:    pass found that the encoding sniffing algorithm described in the
                   1677:    earlier section failed to find the right encoding.</li>
                   1678: 
                   1679:    <li>If the encoding that is already being used to interpret the
                   1680:    input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1681:    <i>certain</i> and abort these steps. The new encoding is ignored;
                   1682:    if it was anything but the same encoding, then it would be clearly
                   1683:    incorrect.</li>
                   1684: 
                   1685:    <li>If the new encoding is a UTF-16 encoding, change it to
                   1686:    UTF-8.</li>
                   1687: 
                   1688:    <li>If all the bytes up to the last byte converted by the current
                   1689:    decoder have the same Unicode interpretations in both the current
                   1690:    encoding and the new encoding, and if the user agent supports
                   1691:    changing the converter on the fly, then the user agent may change
                   1692:    to the new converter for the encoding on the fly. Set the
                   1693:    <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
                   1694:    convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1695:    <i>certain</i>, and abort these steps.</li>
                   1696: 
                   1697:    <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
                   1698:    <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
                   1699:    browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
                   1700:    sniffing algorithm</a> and instead just set the encoding to the
                   1701:    new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1702:    <i>certain</i>. Whenever possible, this should be done without
                   1703:    actually contacting the network layer (the bytes should be
                   1704:    re-parsed from memory), even if, e.g., the document is marked as
                   1705:    not being cacheable. If this is not possible and contacting the
                   1706:    network layer would involve repeating a request that uses a method
                   1707:    other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
                   1708:    equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1709:    <i>certain</i> and ignore the new encoding. The resource will be
                   1710:    misinterpreted. User agents may notify the user of the situation,
                   1711:    to aid in application development.</li>
                   1712: 
1.266     mike     1713:   </ol></div><div class="impl">
                   1714: 
                   1715:   <h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4>
1.1       mike     1716: 
                   1717:   <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5>
                   1718: 
                   1719:   <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
                   1720:   the primary operation of the tree construction stage.</p>
                   1721: 
                   1722:   <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
                   1723:   "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
                   1724:   "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
                   1725:   "<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     1726:   "<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     1727:   "<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>",
                   1728:   "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
                   1729:   "<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
                   1730:   table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
                   1731:   foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
                   1732:   body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
                   1733:   frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
                   1734:   frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
                   1735:   after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
                   1736:   frameset</a>" during the course of the parsing, as described in
                   1737:   the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
                   1738:   how tokens are processed and whether CDATA sections are
                   1739:   supported.</p>
                   1740: 
                   1741:   <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
                   1742:   head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   1743:   body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
                   1744:   table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   1745:   body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
                   1746:   "<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
                   1747:   that the other modes defer to them at various times. When the
                   1748:   algorithm below says that the user agent is to do something
                   1749:   "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
                   1750:   mode", where <var title="">m</var> is one of these modes, the user
                   1751:   agent must use the rules described under the <var title="">m</var>
                   1752:   <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
                   1753:   <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>
                   1754:   to a new value.</p>
                   1755: 
                   1756:   <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.91      mike     1757:   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     1758:   <dfn id="original-insertion-mode">original insertion mode</dfn> is also set. This is the
                   1759:   insertion mode to which the tree construction stage will return.</p>
                   1760: 
                   1761:   <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
                   1762:   mode: in foreign content">in foreign content</a>", the
                   1763:   <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
                   1764:   is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1765:   foreign content">in foreign content</a>" mode to handle HTML
                   1766:   (i.e. not foreign) content.</p>
                   1767: 
                   1768:   <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
                   1769:   mode appropriately</dfn>, it means the UA must follow these
                   1770:   steps:</p>
                   1771: 
                   1772:   <ol><li>Let <var title="">last</var> be false.</li>
                   1773: 
                   1774:    <li>Let <var title="">node</var> be the last node in the
                   1775:    <a href="#stack-of-open-elements">stack of open elements</a>.</li>
                   1776: 
                   1777:    <li>If <var title="">node</var> is the first node in the stack of
                   1778:    open elements, then set <var title="">last</var> to true and set
                   1779:    <var title="">node</var> to the <var title="">context</var>
                   1780:    element. (<a href="#fragment-case">fragment case</a>)</li>
                   1781: 
                   1782:    <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
                   1783:    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
                   1784:    steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1785: 
                   1786:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
                   1787:    <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
                   1788:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
                   1789:    mode: in cell">in cell</a>" and abort these steps.</li>
                   1790: 
                   1791:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
                   1792:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
                   1793:    mode: in row">in row</a>" and abort these steps.</li>
                   1794: 
                   1795:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
                   1796:    <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
                   1797:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
                   1798:    table body">in table body</a>" and abort these steps.</li>
                   1799: 
                   1800:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
                   1801:    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
                   1802:    these steps.</li>
                   1803: 
                   1804:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
                   1805:    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
                   1806:    abort these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1807: 
                   1808:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   1809:    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
                   1810:    steps.</li>
                   1811: 
                   1812:    <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
                   1813:    namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then switch the
                   1814:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1815:    foreign content">in foreign content</a>", let the
                   1816:    <a href="#secondary-insertion-mode">secondary insertion mode</a> be "<a href="#parsing-main-inbody" title="insertion
                   1817:    mode: in body">in body</a>", and abort these steps.</li>
                   1818: 
1.159     mike     1819:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element-0">head</a></code> element,
1.1       mike     1820:    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
                   1821:    these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- This is only
                   1822:    here for now in case people think that the spec accidentally
                   1823:    omitted it and try to "fix" it. Note that noscript-in-head is also
                   1824:    handled this way. This is all intentional. The only thing it
                   1825:    doesn't handle is the scripting-disabled fragment parsing case for
                   1826:    a <head> element containing a <noscript> which itself contains
                   1827:    something other than a <link> or a <style> element; you'd expect
                   1828:    that to break out of the <noscript> but it doesn't. This is an edge
                   1829:    case that doesn't affect the spec, since the algorithm for fragment
                   1830:    parsing is only used for innerHTML/outerHTML/insertAdjacentHTML(),
1.333     mike     1831:    where we know scripting is enabled. -->
1.1       mike     1832: 
1.159     mike     1833:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element-0">body</a></code> element,
1.1       mike     1834:    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
                   1835:    steps.</li>
                   1836: 
1.5       mike     1837:    <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.1       mike     1838:    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
                   1839:    these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1840: 
1.159     mike     1841:    <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element-0">html</a></code> element,
1.333     mike     1842:    then <!--: if the <span><code title="">head</code> element
                   1843:    pointer</span> is null,--> switch the <a href="#insertion-mode">insertion mode</a>
                   1844:    to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before
                   1845:    head</a>"<!--, otherwise, switch the <span>insertion mode</span>
                   1846:    to "<span title="insertion mode: after head">after head</span>".-->
                   1847:    Then, <!-- in either case, --> abort these steps. (<a href="#fragment-case">fragment
                   1848:    case</a>)</li> <!-- if the head element pointer can ever be
                   1849:    non-null when we're going through these steps, we'll need to
                   1850:    uncomment out the commented-out bits -->
1.1       mike     1851: 
                   1852:    <li>If <var title="">last</var> is true, then switch the
                   1853:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
                   1854:    body">in body</a>" and abort these steps. (<a href="#fragment-case">fragment
                   1855:    case</a>)</li>
                   1856: 
                   1857:    <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
                   1858:    elements</a>.</li>
                   1859: 
                   1860:    <li>Return to step 3.</li>
                   1861: 
                   1862:   </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5>
                   1863: 
                   1864:   <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
                   1865:   stack grows downwards; the topmost node on the stack is the first
                   1866:   one added to the stack, and the bottommost node of the stack is the
                   1867:   most recently added node in the stack (notwithstanding when the
                   1868:   stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
                   1869: 
                   1870:   <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
                   1871:   html</a>" <a href="#insertion-mode">insertion mode</a> creates the
1.159     mike     1872:   <code><a href="semantics.html#the-html-element-0">html</a></code> root element node, which is then added to the
1.1       mike     1873:   stack.</p>
                   1874: 
                   1875:   <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
1.159     mike     1876:   elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1       mike     1877:   element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
                   1878:   parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
                   1879:   case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
                   1880:   html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
                   1881: 
1.159     mike     1882:   <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     1883:   node of the stack. It never gets popped off the stack.</p>
                   1884: 
                   1885:   <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
                   1886:   stack.</p>
                   1887: 
                   1888:   <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
                   1889:   element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
                   1890:   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
                   1891:   open elements</a> (<a href="#fragment-case">fragment case</a>), then the
                   1892:   <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
1.159     mike     1893:   of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code> element).</p>
1.1       mike     1894: 
                   1895:   <p>Elements in the stack fall into the following categories:</p>
                   1896: 
                   1897:   <dl><dt><dfn id="special">Special</dfn></dt>
                   1898: 
                   1899:    <dd><p>The following HTML elements have varying levels of special
                   1900:    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>,
                   1901:    <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     1902:    <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.159     mike     1903:    <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     1904:    <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     1905:    <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
1.422     mike     1906:    <code><a href="semantics.html#the-dd-element">dd</a></code>, <code><a href="interactive-elements.html#the-details-element">details</a></code>, <code><a href="obsolete.html#dir">dir</a></code>,
                   1907:    <code><a href="semantics.html#the-div-element">div</a></code>, <code><a href="semantics.html#the-dl-element">dl</a></code>, <code><a href="semantics.html#the-dt-element">dt</a></code>,
                   1908:    <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>, <code><a href="forms.html#the-fieldset-element">fieldset</a></code>, <code><a href="text-level-semantics.html#the-figure-element">figure</a></code>,
                   1909:    <code><a href="semantics.html#the-footer-element">footer</a></code>, <code><a href="forms.html#the-form-element">form</a></code>, <code><a href="obsolete.html#frame">frame</a></code>,
                   1910:    <code><a href="obsolete.html#frameset">frameset</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h1</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h2</a></code>,
                   1911:    <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h3</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h4</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h5</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h6</a></code>,
                   1912:    <code><a href="semantics.html#the-head-element-0">head</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>, <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>,
                   1913:    <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>, <!-- <code>image</code>,
                   1914:    (commented out because this isn't an element that can end up on the
                   1915:    stack, so it doesn't matter) --> <code><a href="text-level-semantics.html#the-img-element">img</a></code>,
                   1916:    <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="obsolete.html#isindex-0">isindex</a></code>, <code><a href="semantics.html#the-li-element">li</a></code>,
                   1917:    <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="obsolete.html#listing">listing</a></code>, <code><a href="interactive-elements.html#menus">menu</a></code>,
                   1918:    <code><a href="semantics.html#meta">meta</a></code>, <code><a href="semantics.html#the-nav-element">nav</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>,
                   1919:    <code><a href="obsolete.html#noframes">noframes</a></code>, <code><a href="semantics.html#the-noscript-element">noscript</a></code>, <code><a href="semantics.html#the-ol-element">ol</a></code>,
                   1920:    <code><a href="semantics.html#the-p-element">p</a></code>, <code><a href="text-level-semantics.html#the-param-element">param</a></code>, <code><a href="obsolete.html#plaintext">plaintext</a></code>,
                   1921:    <code><a href="semantics.html#the-pre-element">pre</a></code>, <code><a href="semantics.html#script">script</a></code>, <code><a href="semantics.html#the-section-element">section</a></code>,
                   1922:    <code><a href="forms.html#the-select-element">select</a></code>, <code><a href="obsolete.html#spacer">spacer</a></code>, <code><a href="semantics.html#the-style-element">style</a></code>,
                   1923:    <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="forms.html#the-textarea-element">textarea</a></code>, <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>,
                   1924:    <code><a href="tabular-data.html#the-thead-element">thead</a></code>, <code><a href="semantics.html#the-title-element-0">title</a></code>, <code><a href="tabular-data.html#the-tr-element">tr</a></code>,
                   1925:    <code><a href="semantics.html#the-ul-element">ul</a></code>, <code>wbr</code>, and <code><a href="obsolete.html#xmp">xmp</a></code>.</p></dd>
1.1       mike     1926: 
                   1927:    <dt><dfn id="scoping">Scoping</dfn></dt>
                   1928:    <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
                   1929:    an element in scope">scopes</a> for various parts of the
1.5       mike     1930:    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     1931:    <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>,
                   1932:    <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     1933:    <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
                   1934: 
                   1935:    <dt><dfn id="formatting">Formatting</dfn></dt>
                   1936:    <dd><p>The following HTML elements are those that end up in the
                   1937:    <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     1938:    <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>,
                   1939:    <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>,
                   1940:    <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>,
                   1941:    <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
                   1942:    <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1       mike     1943: 
                   1944:    <dt><dfn id="phrasing">Phrasing</dfn></dt>
                   1945:    <dd><p>All other elements found while parsing an HTML
                   1946:    document.</p></dd>
                   1947: 
1.234     mike     1948:   </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
                   1949:   specific scope</dfn> consisting of a list of element types <var title="">list</var> when the following algorithm terminates in a
                   1950:   match state:</p>
1.1       mike     1951: 
                   1952:   <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   1953:    node</a> (the bottommost node of the stack).</p></li>
                   1954: 
                   1955:    <li><p>If <var title="">node</var> is the target node, terminate in
                   1956:    a match state.</p></li>
                   1957: 
1.234     mike     1958:    <li><p>Otherwise, if <var title="">node</var> is one of the element
                   1959:    types in <var title="">list</var>, terminate in a failure
                   1960:    state.</p></li>
1.1       mike     1961: 
                   1962:    <li><p>Otherwise, set <var title="">node</var> to the previous
                   1963:    entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
                   1964:    2. (This will never fail, since the loop will always terminate in
                   1965:    the previous step if the top of the stack &#8212; an
1.159     mike     1966:    <code><a href="semantics.html#the-html-element-0">html</a></code> element &#8212; is reached.)</p></li>
1.1       mike     1967: 
1.234     mike     1968:   </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
                   1969:   it <a href="#has-an-element-in-the-specific-scope">has an element in the specific scope</a> consisting
                   1970:   of the following element types:</p>
                   1971: 
                   1972:   <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
                   1973:    <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
                   1974:    <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.) -->
                   1975:    <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1976:    <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
                   1977:    <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
                   1978:    <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
                   1979:    <li><code><a href="obsolete.html#the-marquee-element">marquee</a></code> in the HTML namespace</li>
                   1980:    <li><code><a href="text-level-semantics.html#the-object-element">object</a></code> in the HTML namespace</li>
                   1981:    <li><code title="">foreignObject</code> in the SVG namespace</li>
                   1982:   </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
                   1983:   item scope</dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
                   1984:   scope</a> consisting of the following element types:</p>
                   1985: 
                   1986:   <ul class="brief"><li>All the element types listed above for the <i><a href="#has-an-element-in-scope">has an element
                   1987:    in scope</a></i> algorithm.</li>
                   1988:    <li><code><a href="semantics.html#the-ol-element">ol</a></code> in the HTML namespace</li>
                   1989:    <li><code><a href="semantics.html#the-ul-element">ul</a></code> in the HTML namespace</li>
                   1990:   </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
                   1991:   scope</em></dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
                   1992:   scope</a> consisting of the following element types:</p>
                   1993: 
                   1994:   <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.) -->
                   1995:    <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1996:   </ul><p>Nothing happens if at any time any of the elements in the
1.1       mike     1997:   <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
                   1998:   or removed from, the <code>Document</code> tree. In particular, the
                   1999:   stack is not changed in this situation. This can cause, amongst
                   2000:   other strange effects, content to be appended to nodes that are no
                   2001:   longer in the DOM.</p>
                   2002: 
                   2003:   <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
                   2004:   the stack is manipulated in a random-access fashion.</p>
                   2005: 
                   2006: 
                   2007:   <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5>
                   2008: 
                   2009:   <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
                   2010:   empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
                   2011: 
                   2012:   <p>The list contains elements in the <a href="#formatting">formatting</a>
                   2013:   category, and scope markers. The scope markers are inserted when
1.159     mike     2014:   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     2015:   elements, marquees, table cells, and table captions, and are used to
1.5       mike     2016:   prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.159     mike     2017:   elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code> elements, marquees, and
1.1       mike     2018:   tables.</p>
                   2019: 
                   2020:   <p class="note">The scope markers are unrelated to the concept of an
                   2021:   element being <a href="#has-an-element-in-scope" title="has an element in scope">in
                   2022:   scope</a>.</p>
                   2023: 
                   2024:   <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   2025:   elements</a> is associated with the token for which it was
                   2026:   created, so that further elements can be created for that token if
                   2027:   necessary.</p>
                   2028: 
                   2029:   <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
                   2030:   active formatting elements</dfn>, the UA must perform the following
                   2031:   steps:</p>
                   2032: 
                   2033:   <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
                   2034:    elements</a>, then there is nothing to reconstruct; stop this
                   2035:    algorithm.</li>
                   2036: 
                   2037:    <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
                   2038:    active formatting elements</a> is a marker, or if it is an
                   2039:    element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
                   2040:    there is nothing to reconstruct; stop this algorithm.</li>
                   2041: 
                   2042:    <li>Let <var title="">entry</var> be the last (most recently added)
                   2043:    element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   2044:    elements</a>.</li>
                   2045: 
                   2046:    <li>If there are no entries before <var title="">entry</var> in the
                   2047:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
                   2048:    8.</li>
                   2049: 
                   2050:    <li>Let <var title="">entry</var> be the entry one earlier than
                   2051:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   2052:    elements</a>.</li>
                   2053: 
                   2054:    <li>If <var title="">entry</var> is neither a marker nor an element
                   2055:    that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
                   2056:    4.</li>
                   2057: 
                   2058:    <li>Let <var title="">entry</var> be the element one later than
                   2059:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   2060:    elements</a>.</li>
                   2061: 
                   2062:    <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   2063:    element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
                   2064: 
                   2065:    <li>Append <var title="">new element</var> to the <a href="#current-node">current
                   2066:    node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
                   2067:    elements</a> so that it is the new <a href="#current-node">current
                   2068:    node</a>.</li>
                   2069: 
                   2070:    <li>Replace the entry for <var title="">entry</var> in the list
                   2071:    with an entry for <var title="">new element</var>.</li>
                   2072: 
                   2073:    <li>If the entry for <var title="">new element</var> in the
                   2074:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
                   2075:    entry in the list, return to step 7.</li>
                   2076: 
                   2077:   </ol><p>This has the effect of reopening all the formatting elements that
                   2078:   were opened in the current body, cell, or caption (whichever is
                   2079:   youngest) that haven't been explicitly closed.</p>
                   2080: 
                   2081:   <p class="note">The way this specification is written, the
                   2082:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
                   2083:   elements in chronological order with the least recently added
                   2084:   element first and the most recently added element last (except for
                   2085:   while steps 8 to 11 of the above algorithm are being executed, of
                   2086:   course).</p>
                   2087: 
                   2088:   <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
                   2089:   active formatting elements up to the last marker</dfn>, the UA must
                   2090:   perform the following steps:</p>
                   2091: 
                   2092:   <ol><li>Let <var title="">entry</var> be the last (most recently added)
                   2093:    entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
                   2094: 
                   2095:    <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
                   2096:    formatting elements</a>.</li>
                   2097: 
                   2098:    <li>If <var title="">entry</var> was a marker, then stop the
                   2099:    algorithm at this point. The list has been cleared up to the last
                   2100:    marker.</li>
                   2101: 
                   2102:    <li>Go to step 1.</li>
                   2103: 
                   2104:   </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5>
                   2105: 
                   2106:   <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
                   2107:   pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
                   2108:   pointer</dfn> are both null.</p>
                   2109: 
1.159     mike     2110:   <p>Once a <code><a href="semantics.html#the-head-element-0">head</a></code> element has been parsed (whether
1.1       mike     2111:   implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
                   2112:   element pointer</a> gets set to point to this node.</p>
                   2113: 
                   2114:   <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   2115:   points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
                   2116:   whose end tag has not yet been seen. It is used to make form
                   2117:   controls associate with forms in the face of dramatically bad
                   2118:   markup, for historical reasons.</p>
                   2119: 
                   2120: 
                   2121:   <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5>
                   2122: 
                   2123:   <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
                   2124:   <code>Document</code> with which the parser is associated when the
                   2125:   parser was created, and "disabled" otherwise.</p>
                   2126: 
                   2127:   <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
                   2128:   when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
                   2129:   parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
                   2130:   don't execute in that case.</p>
                   2131: 
                   2132:   <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
                   2133:   created. It is set to "not ok" after certain tokens are seen.</p>
                   2134: 
1.266     mike     2135:   </div><div class="impl">
1.1       mike     2136: 
1.159     mike     2137:   <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     2138: 
                   2139:   <p>Implementations must act as if they used the following state
                   2140:   machine to tokenize HTML. The state machine must start in the
                   2141:   <a href="#data-state">data state</a>. Most states consume a single character,
                   2142:   which may have various side-effects, and either switches the state
                   2143:   machine to a new state to <em>reconsume</em> the same character, or
                   2144:   switches it to a new state (to consume the next character), or
                   2145:   repeats the same state (to consume the next character). Some states
                   2146:   have more complicated behavior and can consume several characters
                   2147:   before switching to another state.</p>
                   2148: 
                   2149:   <p>The exact behavior of certain states depends on a <dfn id="content-model-flag">content
                   2150:   model flag</dfn> that is set after certain tokens are emitted. The
1.91      mike     2151:   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
                   2152:   state. In the RCDATA and RAWTEXT states, a further <dfn id="escape-flag">escape
1.1       mike     2153:   flag</dfn> is used to control the behavior of the tokenizer. It is
                   2154:   either true or false, and initially must be set to the false
                   2155:   state. The <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
                   2156:   elements</a> also affects tokenization.</p>
                   2157: 
                   2158:   <p>The output of the tokenization step is a series of zero or more
                   2159:   of the following tokens: DOCTYPE, start tag, end tag, comment,
                   2160:   character, end-of-file. DOCTYPE tokens have a name, a public
                   2161:   identifier, a system identifier, and a <i>force-quirks
                   2162:   flag</i>. When a DOCTYPE token is created, its name, public
                   2163:   identifier, and system identifier must be marked as missing (which
                   2164:   is a distinct state from the empty string), and the <i>force-quirks
                   2165:   flag</i> must be set to <i>off</i> (its other state is
                   2166:   <i>on</i>). Start and end tag tokens have a tag name, a
                   2167:   <i>self-closing flag</i>, and a list of attributes, each of which
                   2168:   has a name and a value. When a start or end tag token is created,
                   2169:   its <i>self-closing flag</i> must be unset (its other state is that
                   2170:   it be set), and its attributes list must be empty. Comment and
                   2171:   character tokens have data.</p>
                   2172: 
                   2173:   <p>When a token is emitted, it must immediately be handled by the
                   2174:   <a href="#tree-construction">tree construction</a> stage. The tree construction stage
                   2175:   can affect the state of the <a href="#content-model-flag">content model flag</a>, and can
                   2176:   insert additional characters into the stream. (For example, the
                   2177:   <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
1.159     mike     2178:   using the <a href="embedded-content-0.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
1.1       mike     2179:   characters into the stream being tokenized.)</p>
                   2180: 
                   2181:   <p>When a start tag token is emitted with its <i>self-closing
                   2182:   flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
                   2183:   self-closing flag">acknowledged</dfn> when it is processed by the
                   2184:   tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
                   2185: 
                   2186:   <p>When an end tag token is emitted, the <a href="#content-model-flag">content model
                   2187:   flag</a> must be switched to the PCDATA state.</p>
                   2188: 
                   2189:   <p>When an end tag token is emitted with attributes, that is a
                   2190:   <a href="#parse-error">parse error</a>.</p>
                   2191: 
                   2192:   <p>When an end tag token is emitted with its <i>self-closing
                   2193:   flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
                   2194: 
                   2195:   <p>Before each step of the tokenizer, the user agent must first
                   2196:   check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
                   2197:   tokenizer must abort the processing of any nested invocations of the
1.479     mike     2198:   tokenizer, yielding control back to the caller.</p>
1.1       mike     2199: 
                   2200:   <p>The tokenizer state machine consists of the states defined in the
                   2201:   following subsections.</p>
                   2202: 
1.333     mike     2203:   <!-- Order of the lists below is supposed to be non-error then
                   2204:   error, by unicode, then EOF, ending with "anything else" -->
1.1       mike     2205: 
                   2206:   <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5>
                   2207: 
                   2208:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2209: 
                   2210:   <dl class="switch"><dt>U+0026 AMPERSAND (&amp;)</dt>
                   2211:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to one of the
                   2212:    PCDATA or RCDATA states and the <a href="#escape-flag">escape flag</a> is
1.299     mike     2213:    false: switch to the <a href="#character-reference-in-data-state">character reference in data
1.56      mike     2214:    state</a>.</dd>
                   2215:    <dd>Otherwise: treat it as per the "anything else" entry
                   2216:    below.</dd>
1.1       mike     2217: 
                   2218:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2219:    <dd>
                   2220: 
                   2221:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2222:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     2223:     is false, and there are at least three characters before this
                   2224:     one in the input stream, and the last four characters in the
                   2225:     input stream, including this one, are U+003C LESS-THAN SIGN,
                   2226:     U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, and U+002D
                   2227:     HYPHEN-MINUS ("&lt;!--"), then set the <a href="#escape-flag">escape flag</a>
                   2228:     to true.</p>
                   2229: 
                   2230:     <p>In any case, emit the input character as a character
                   2231:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   2232: 
                   2233:    </dd>
                   2234: 
                   2235:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2236:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   2237:    state: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   2238:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2239:    RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     2240:    is false: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   2241:    <dd>Otherwise: treat it as per the "anything else" entry
                   2242:    below.</dd>
                   2243: 
                   2244:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2245:    <dd>
                   2246: 
                   2247:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2248:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape
1.1       mike     2249:     flag</a> is true, and the last three characters in the input
                   2250:     stream including this one are U+002D HYPHEN-MINUS, U+002D
                   2251:     HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("--&gt;"), set the
                   2252:     <a href="#escape-flag">escape flag</a> to false.</p> <!-- no need to check
                   2253:     that there are enough characters, since you can only run into
                   2254:     this if the flag is true in the first place, which requires four
                   2255:     characters. -->
                   2256: 
                   2257:     <p>In any case, emit the input character as a character
                   2258:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   2259: 
                   2260:    </dd>
                   2261: 
                   2262:    <dt>EOF</dt>
                   2263:    <dd>Emit an end-of-file token.</dd>
                   2264: 
                   2265:    <dt>Anything else</dt>
                   2266:    <dd>Emit the input character as a character token. Stay in the
                   2267:    <a href="#data-state">data state</a>.</dd>
                   2268: 
1.299     mike     2269:   </dl><h5 id="character-reference-in-data-state"><span class="secno">9.2.4.2 </span><dfn>Character reference in data state</dfn></h5>
1.1       mike     2270: 
                   2271:   <p><i>(This cannot happen if the <a href="#content-model-flag">content model flag</a>
1.91      mike     2272:   is set to the RAWTEXT state.)</i></p>
1.1       mike     2273: 
                   2274:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
                   2275:   <a href="#additional-allowed-character">additional allowed character</a>.</p>
                   2276: 
                   2277:   <p>If nothing is returned, emit a U+0026 AMPERSAND character
                   2278:   token.</p>
                   2279: 
                   2280:   <p>Otherwise, emit the character token that was returned.</p>
                   2281: 
                   2282:   <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
                   2283: 
                   2284: 
                   2285:   <h5 id="tag-open-state"><span class="secno">9.2.4.3 </span><dfn>Tag open state</dfn></h5>
                   2286: 
                   2287:   <p>The behavior of this state depends on the <a href="#content-model-flag">content model
                   2288:   flag</a>.</p>
                   2289: 
                   2290:   <dl><dt>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA
1.91      mike     2291:    or RAWTEXT states</dt>
1.1       mike     2292: 
                   2293:    <dd>
                   2294: 
                   2295:     <p>Consume the <a href="#next-input-character">next input character</a>. If it is a
1.464     mike     2296:     U+002F SOLIDUS character (/), switch to the <a href="#close-tag-open-state">close tag open
1.1       mike     2297:     state</a>. Otherwise, emit a U+003C LESS-THAN SIGN character
                   2298:     token and reconsume the <a href="#current-input-character">current input character</a> in the
                   2299:     <a href="#data-state">data state</a>.</p>
                   2300: 
                   2301:    </dd>
                   2302: 
                   2303:    <dt>If the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   2304:    state</dt>
                   2305: 
                   2306:    <dd>
                   2307: 
                   2308:     <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2309: 
                   2310:     <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2311:      <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
                   2312: 
                   2313:      <dt>U+002F SOLIDUS (/)</dt>
                   2314:      <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
                   2315: 
                   2316:      <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2317:      <dd>Create a new start tag token, set its tag name to the
                   2318:      lowercase version of the input character (add 0x0020 to the
                   2319:      character's code point), then switch to the <a href="#tag-name-state">tag name
                   2320:      state</a>. (Don't emit the token yet; further details will
                   2321:      be filled in before it is emitted.)</dd>
                   2322: 
                   2323:      <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2324:      <dd>Create a new start tag token, set its tag name to the input
                   2325:      character, then switch to the <a href="#tag-name-state">tag name
                   2326:      state</a>. (Don't emit the token yet; further details will
                   2327:      be filled in before it is emitted.)</dd>
                   2328: 
                   2329:      <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2330:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2331:      character token and a U+003E GREATER-THAN SIGN character
                   2332:      token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2333: 
                   2334:      <dt>U+003F QUESTION MARK (?)</dt>
                   2335:      <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2336:      comment state</a>.</dd>
                   2337: 
                   2338:      <dt>Anything else</dt>
                   2339:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2340:      character token and reconsume the <a href="#current-input-character">current input character</a> in the
                   2341:      <a href="#data-state">data state</a>.</dd>
                   2342: 
                   2343:     </dl></dd>
                   2344: 
                   2345:   </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.4 </span><dfn>Close tag open state</dfn></h5>
                   2346: 
                   2347:   <p>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA or
1.91      mike     2348:   RAWTEXT states but no start tag token has ever been emitted by this
1.1       mike     2349:   instance of the tokenizer (<a href="#fragment-case">fragment case</a>), or, if the
1.91      mike     2350:   <a href="#content-model-flag">content model flag</a> is set to the RCDATA or RAWTEXT states
1.1       mike     2351:   and the next few characters do not match the tag name of the last
                   2352:   start tag token emitted (compared in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2353:   case-insensitive</a> manner), or if they do but they are not
                   2354:   immediately followed by one of the following characters:</p>
                   2355: 
                   2356:   <ul class="brief"><li>U+0009 CHARACTER TABULATION</li>
                   2357:    <li>U+000A LINE FEED (LF)</li>
                   2358:    <li>U+000C FORM FEED (FF)</li>
                   2359:    <!--<li>U+000D CARRIAGE RETURN (CR)</li>-->
                   2360:    <li>U+0020 SPACE</li>
                   2361:    <li>U+003E GREATER-THAN SIGN (&gt;)</li>
                   2362:    <li>U+002F SOLIDUS (/)</li>
                   2363:    <li>EOF</li>
                   2364:   </ul><p>...then emit a U+003C LESS-THAN SIGN character token, a U+002F
                   2365:   SOLIDUS character token, and switch to the <a href="#data-state">data state</a>
                   2366:   to process the <a href="#next-input-character">next input character</a>.</p>
                   2367: 
                   2368:   <p>Otherwise, if the <a href="#content-model-flag">content model flag</a> is set to the
                   2369:   PCDATA state, or if the next few characters <em>do</em> match that tag
                   2370:   name, consume the <a href="#next-input-character">next input character</a>:</p>
                   2371: 
                   2372:   <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2373:    <dd>Create a new end tag token, set its tag name to the lowercase
                   2374:    version of the input character (add 0x0020 to the character's
                   2375:    code point), then switch to the <a href="#tag-name-state">tag name
                   2376:    state</a>. (Don't emit the token yet; further details will be
                   2377:    filled in before it is emitted.)</dd>
                   2378: 
                   2379:    <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2380:    <dd>Create a new end tag token, set its tag name to the input
                   2381:    character, then switch to the <a href="#tag-name-state">tag name state</a>. (Don't
                   2382:    emit the token yet; further details will be filled in before it
                   2383:    is emitted.)</dd>
                   2384: 
                   2385:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2386:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
                   2387:    state</a>.</dd>
                   2388: 
                   2389:    <dt>EOF</dt>
                   2390:    <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2391:    character token and a U+002F SOLIDUS character token. Reconsume
                   2392:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2393: 
                   2394:    <dt>Anything else</dt>
                   2395:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2396:    comment state</a>.</dd>
                   2397: 
                   2398:   </dl><h5 id="tag-name-state"><span class="secno">9.2.4.5 </span><dfn>Tag name state</dfn></h5>
                   2399: 
                   2400:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2401: 
                   2402:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2403:    <dt>U+000A LINE FEED (LF)</dt>
                   2404:    <dt>U+000C FORM FEED (FF)</dt>
                   2405:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2406:    <dt>U+0020 SPACE</dt>
                   2407:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2408: 
                   2409:    <dt>U+002F SOLIDUS (/)</dt>
                   2410:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2411: 
                   2412:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2413:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2414:    state</a>.</dd>
                   2415: 
                   2416:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2417:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2418:    (add 0x0020 to the character's code point) to the current tag
                   2419:    token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2420: 
                   2421:    <dt>EOF</dt>
                   2422:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2423:    <a href="#data-state">data state</a>.</dd>
                   2424: 
                   2425:    <dt>Anything else</dt>
                   2426:    <dd>Append the <a href="#current-input-character">current input character</a> to the current tag token's
                   2427:    tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2428: 
                   2429:   </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.6 </span><dfn>Before attribute name state</dfn></h5>
                   2430: 
                   2431:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2432: 
                   2433:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2434:    <dt>U+000A LINE FEED (LF)</dt>
                   2435:    <dt>U+000C FORM FEED (FF)</dt>
                   2436:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2437:    <dt>U+0020 SPACE</dt>
                   2438:    <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2439: 
                   2440:    <dt>U+002F SOLIDUS (/)</dt>
                   2441:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2442: 
                   2443:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2444:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2445:    state</a>.</dd>
                   2446: 
                   2447:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2448:    <dd>Start a new attribute in the current tag token. Set that
                   2449:    attribute's name to the lowercase version of the <a href="#current-input-character">current input
                   2450:    character</a> (add 0x0020 to the character's code point), and its
                   2451:    value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2452:    state</a>.</dd>
                   2453: 
                   2454:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2455:    <dt>U+0027 APOSTROPHE (')</dt>
                   2456:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2457:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2458:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2459:    entry below.</dd>
                   2460: 
                   2461:    <dt>EOF</dt>
                   2462:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2463:    <a href="#data-state">data state</a>.</dd>
                   2464: 
                   2465:    <dt>Anything else</dt>
                   2466:    <dd>Start a new attribute in the current tag token. Set that
                   2467:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2468:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2469:    state</a>.</dd>
                   2470: 
                   2471:   </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.7 </span><dfn>Attribute name state</dfn></h5>
                   2472: 
                   2473:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2474: 
                   2475:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2476:    <dt>U+000A LINE FEED (LF)</dt>
                   2477:    <dt>U+000C FORM FEED (FF)</dt>
                   2478:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2479:    <dt>U+0020 SPACE</dt>
                   2480:    <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2481: 
                   2482:    <dt>U+002F SOLIDUS (/)</dt>
                   2483:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2484: 
                   2485:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2486:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2487: 
                   2488:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2489:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2490:    state</a>.</dd>
                   2491: 
                   2492:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2493:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2494:    (add 0x0020 to the character's code point) to the current
                   2495:    attribute's name. Stay in the <a href="#attribute-name-state">attribute name
                   2496:    state</a>.</dd>
                   2497: 
                   2498:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2499:    <dt>U+0027 APOSTROPHE (')</dt>
                   2500:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2501:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2502:    entry below.</dd>
                   2503: 
                   2504:    <dt>EOF</dt>
                   2505:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2506:    <a href="#data-state">data state</a>.</dd>
                   2507: 
                   2508:    <dt>Anything else</dt>
                   2509:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2510:    name. Stay in the <a href="#attribute-name-state">attribute name state</a>.</dd>
                   2511: 
                   2512:   </dl><p>When the user agent leaves the attribute name state (and before
                   2513:   emitting the tag token, if appropriate), the complete attribute's
                   2514:   name must be compared to the other attributes on the same token;
                   2515:   if there is already an attribute on the token with the exact same
                   2516:   name, then this is a <a href="#parse-error">parse error</a> and the new
                   2517:   attribute must be dropped, along with the value that gets
                   2518:   associated with it (if any).</p>
                   2519: 
                   2520: 
                   2521:   <h5 id="after-attribute-name-state"><span class="secno">9.2.4.8 </span><dfn>After attribute name state</dfn></h5>
                   2522: 
                   2523:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2524: 
                   2525:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2526:    <dt>U+000A LINE FEED (LF)</dt>
                   2527:    <dt>U+000C FORM FEED (FF)</dt>
                   2528:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2529:    <dt>U+0020 SPACE</dt>
                   2530:    <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2531: 
                   2532:    <dt>U+002F SOLIDUS (/)</dt>
                   2533:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2534: 
                   2535:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2536:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2537: 
                   2538:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2539:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2540:    state</a>.</dd>
                   2541: 
                   2542:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2543:    <dd>Start a new attribute in the current tag token. Set that
                   2544:    attribute's name to the lowercase version of the <a href="#current-input-character">current input character</a>
                   2545:    (add 0x0020 to the character's code point), and its value to
                   2546:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2547:    state</a>.</dd>
                   2548: 
                   2549:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2550:    <dt>U+0027 APOSTROPHE (')</dt>
                   2551:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2552:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2553:    entry below.</dd>
                   2554: 
                   2555:    <dt>EOF</dt>
                   2556:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2557:    <a href="#data-state">data state</a>.</dd>
                   2558: 
                   2559:    <dt>Anything else</dt>
                   2560:    <dd>Start a new attribute in the current tag token. Set that
                   2561:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2562:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2563:    state</a>.</dd>
                   2564: 
                   2565:   </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.9 </span><dfn>Before attribute value state</dfn></h5>
                   2566: 
                   2567:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2568: 
                   2569:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2570:    <dt>U+000A LINE FEED (LF)</dt>
                   2571:    <dt>U+000C FORM FEED (FF)</dt>
                   2572:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2573:    <dt>U+0020 SPACE</dt>
                   2574:    <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2575: 
                   2576:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2577:    <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
                   2578: 
                   2579:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2580:    <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
                   2581:    and reconsume this input character.</dd>
                   2582: 
                   2583:    <dt>U+0027 APOSTROPHE (')</dt>
                   2584:    <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
                   2585: 
                   2586:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2587:    <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
                   2588:    the <a href="#data-state">data state</a>.</dd>
                   2589: 
                   2590:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2591:    <dt>U+003D EQUALS SIGN (=)</dt>
1.463     mike     2592:    <dt>U+0060 GRAVE ACCENT (`)</dt>
1.1       mike     2593:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2594:    entry below.</dd>
                   2595: 
                   2596:    <dt>EOF</dt>
                   2597:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2598:    <a href="#data-state">data state</a>.</dd>
                   2599: 
                   2600:    <dt>Anything else</dt>
                   2601:    <dd>Append the <a href="#current-input-character">current input character</a> to the current
                   2602:    attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2603:    state</a>.</dd>
                   2604: 
                   2605:   </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.10 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
                   2606: 
                   2607:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2608: 
                   2609:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2610:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2611:    state</a>.</dd>
                   2612: 
                   2613:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2614:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2615:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2616:    being U+0022 QUOTATION MARK (").</dd>
                   2617: 
                   2618:    <dt>EOF</dt>
                   2619:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2620:    <a href="#data-state">data state</a>.</dd>
                   2621: 
                   2622:    <dt>Anything else</dt>
                   2623:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2624:    value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted)
                   2625:    state</a>.</dd>
                   2626: 
                   2627:   </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.11 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
                   2628: 
                   2629:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2630: 
                   2631:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   2632:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2633:    state</a>.</dd>
                   2634: 
                   2635:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2636:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2637:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2638:    being U+0027 APOSTROPHE (').</dd>
                   2639: 
                   2640:    <dt>EOF</dt>
                   2641:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2642:    <a href="#data-state">data state</a>.</dd>
                   2643: 
                   2644:    <dt>Anything else</dt>
                   2645:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2646:    value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted)
                   2647:    state</a>.</dd>
                   2648: 
                   2649:   </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.12 </span><dfn>Attribute value (unquoted) state</dfn></h5>
                   2650: 
                   2651:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2652: 
                   2653:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2654:    <dt>U+000A LINE FEED (LF)</dt>
                   2655:    <dt>U+000C FORM FEED (FF)</dt>
                   2656:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2657:    <dt>U+0020 SPACE</dt>
                   2658:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2659: 
                   2660:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2661:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
1.299     mike     2662:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2663:    being U+003E GREATER-THAN SIGN (&gt;).</dd>
1.1       mike     2664: 
                   2665:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2666:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2667:    state</a>.</dd>
                   2668: 
                   2669:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2670:    <dt>U+0027 APOSTROPHE (')</dt>
                   2671:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2672:    <dt>U+003D EQUALS SIGN (=)</dt>
1.463     mike     2673:    <dt>U+0060 GRAVE ACCENT (`)</dt>
1.1       mike     2674:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2675:    entry below.</dd>
                   2676: 
                   2677:    <dt>EOF</dt>
                   2678:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2679:    <a href="#data-state">data state</a>.</dd>
                   2680: 
                   2681:    <dt>Anything else</dt>
                   2682:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2683:    value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2684:    state</a>.</dd>
                   2685: 
                   2686:   </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>
                   2687: 
                   2688:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
                   2689: 
                   2690:   <p>If nothing is returned, append a U+0026 AMPERSAND character to
                   2691:   the current attribute's value.</p>
                   2692: 
                   2693:   <p>Otherwise, append the returned character token to the current
                   2694:   attribute's value.</p>
                   2695: 
                   2696:   <p>Finally, switch back to the attribute value state that you were
                   2697:   in when were switched into this state.</p>
                   2698: 
                   2699: 
                   2700:   <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.14 </span><dfn>After attribute value (quoted) state</dfn></h5>
                   2701: 
                   2702:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2703: 
                   2704:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2705:    <dt>U+000A LINE FEED (LF)</dt>
                   2706:    <dt>U+000C FORM FEED (FF)</dt>
                   2707:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2708:    <dt>U+0020 SPACE</dt>
                   2709:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2710: 
                   2711:    <dt>U+002F SOLIDUS (/)</dt>
                   2712:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2713: 
                   2714:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2715:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2716:    state</a>.</dd>
                   2717: 
                   2718:    <dt>EOF</dt>
                   2719:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2720:    <a href="#data-state">data state</a>.</dd>
                   2721: 
                   2722:    <dt>Anything else</dt>
                   2723:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2724:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2725: 
                   2726:   </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.15 </span><dfn>Self-closing start tag 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>Set the <i>self-closing flag</i> of the current tag
                   2732:    token. Emit the current tag token. Switch to the <a href="#data-state">data
                   2733:    state</a>.</dd>
                   2734: 
                   2735:    <dt>EOF</dt>
                   2736:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2737:    <a href="#data-state">data state</a>.</dd>
                   2738: 
                   2739:    <dt>Anything else</dt>
                   2740:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2741:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2742: 
                   2743:   </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.16 </span><dfn>Bogus comment state</dfn></h5>
                   2744: 
                   2745:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2746:   flag</a> is set to the PCDATA state.)</i></p>
                   2747: 
                   2748:   <p>Consume every character up to and including the first U+003E
                   2749:   GREATER-THAN SIGN character (&gt;) or the end of the file (EOF),
                   2750:   whichever comes first. Emit a comment token whose data is the
                   2751:   concatenation of all the characters starting from and including
                   2752:   the character that caused the state machine to switch into the
                   2753:   bogus comment state, up to and including the character immediately
                   2754:   before the last consumed character (i.e. up to the character just
                   2755:   before the U+003E or EOF character). (If the comment was started
                   2756:   by the end of the file (EOF), the token is empty.)</p>
                   2757: 
                   2758:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   2759: 
                   2760:   <p>If the end of the file was reached, reconsume the EOF
                   2761:   character.</p>
                   2762: 
                   2763: 
                   2764:   <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.17 </span><dfn>Markup declaration open state</dfn></h5>
                   2765: 
                   2766:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2767:   flag</a> is set to the PCDATA state.)</i></p>
                   2768: 
                   2769:   <p>If the next two characters are both U+002D HYPHEN-MINUS (-)
                   2770:   characters, consume those two characters, create a comment token
                   2771:   whose data is the empty string, and switch to the <a href="#comment-start-state">comment
                   2772:   start state</a>.</p>
                   2773: 
                   2774:   <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2775:   case-insensitive</a> match for the word "DOCTYPE", then consume
                   2776:   those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
                   2777: 
                   2778:   <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
                   2779:   content</a>" and the <a href="#current-node">current node</a> is not an element
                   2780:   in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
                   2781:   an <span>ASCII case-sensitive</span> match for the string "[CDATA["
                   2782:   (the five uppercase letters "CDATA" with a U+005B LEFT SQUARE
                   2783:   BRACKET character before and after), then consume those characters
1.91      mike     2784:   and switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1       mike     2785: 
                   2786:   <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
                   2787:   <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
                   2788:   consumed, if any, is the first character that will be in the
                   2789:   comment.</p>
                   2790: 
                   2791: 
                   2792:   <h5 id="comment-start-state"><span class="secno">9.2.4.18 </span><dfn>Comment start state</dfn></h5>
                   2793: 
                   2794:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2795: 
                   2796:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2797:    <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
                   2798: 
                   2799:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2800:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
                   2801:    <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
                   2802:    -->
                   2803: 
                   2804:    <dt>EOF</dt>
                   2805:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2806:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2807: 
                   2808:    <dt>Anything else</dt>
                   2809:    <dd>Append the input character to the comment token's
                   2810:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2811: 
                   2812:   </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.19 </span><dfn>Comment start dash state</dfn></h5>
                   2813: 
                   2814:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2815: 
                   2816:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2817:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2818: 
                   2819:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2820:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
                   2821:    the <a href="#data-state">data state</a>.</dd>
                   2822: 
                   2823:    <dt>EOF</dt>
                   2824:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2825:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2826:    in comment end state -->
                   2827: 
                   2828:    <dt>Anything else</dt>
1.464     mike     2829:    <dd>Append a U+002D HYPHEN-MINUS character (-) and the input
1.1       mike     2830:    character to the comment token's data. Switch to the
                   2831:    <a href="#comment-state">comment state</a>.</dd>
                   2832: 
                   2833:   </dl><h5 id="comment-state"><span class="secno">9.2.4.20 </span><dfn id="comment">Comment state</dfn></h5>
                   2834: 
                   2835:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2836: 
                   2837:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2838:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
                   2839: 
                   2840:    <dt>EOF</dt>
                   2841:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2842:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2843:    in comment end state -->
                   2844: 
                   2845:    <dt>Anything else</dt>
                   2846:    <dd>Append the input character to the comment token's data. Stay
                   2847:    in the <a href="#comment-state">comment state</a>.</dd>
                   2848: 
                   2849:   </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.21 </span><dfn>Comment end dash state</dfn></h5>
                   2850: 
                   2851:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2852: 
                   2853:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2854:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2855: 
                   2856:    <dt>EOF</dt>
                   2857:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2858:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2859:    in comment end state -->
                   2860: 
                   2861:    <dt>Anything else</dt>
1.464     mike     2862:    <dd>Append a U+002D HYPHEN-MINUS character (-) and the input
1.1       mike     2863:    character to the comment token's data. Switch to the
                   2864:    <a href="#comment-state">comment state</a>.</dd>
                   2865: 
                   2866:   </dl><h5 id="comment-end-state"><span class="secno">9.2.4.22 </span><dfn>Comment end state</dfn></h5>
                   2867: 
                   2868:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2869: 
                   2870:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2871:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2872:    state</a>.</dd>
                   2873: 
                   2874:    <dt>U+0009 CHARACTER TABULATION</dt>
                   2875:    <dt>U+000A LINE FEED (LF)</dt>
                   2876:    <dt>U+000C FORM FEED (FF)</dt>
                   2877:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2878:    <dt>U+0020 SPACE</dt>
                   2879:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2880:    characters and the input character to the comment token's
                   2881:    data. Switch to the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2882: 
                   2883:    <dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2884:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
                   2885:    state</a>.</dd>
                   2886: 
1.333     mike     2887:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2888:    <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
1.464     mike     2889:    character (-) to the comment token's data. Stay in the
1.333     mike     2890:    <a href="#comment-end-state">comment end state</a>.</dd>
                   2891: 
1.1       mike     2892:    <dt>EOF</dt>
                   2893:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2894:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
                   2895:    security reasons: otherwise, hostile user could put a <script> in
                   2896:    a comment e.g. in a blog comment and then DOS the server so that
                   2897:    the end tag isn't read, and then the commented <script> tag would
                   2898:    be treated as live code -->
                   2899: 
                   2900:    <dt>Anything else</dt>
                   2901:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2902:    characters and the input character to the comment token's
                   2903:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2904: 
                   2905:   </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.23 </span><dfn>Comment end bang state</dfn></h5>
                   2906: 
                   2907:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2908: 
1.333     mike     2909:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
1.1       mike     2910:    <dd>Append two U+002D HYPHEN-MINUS (-) characters and a U+0021
1.464     mike     2911:    EXCLAMATION MARK character (!) to the comment token's data. Switch
1.1       mike     2912:    to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2913: 
1.333     mike     2914:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2915:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2916:    state</a>.</dd>
                   2917: 
1.1       mike     2918:    <dt>EOF</dt>
                   2919:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2920:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2921:    comment in comment end state -->
                   2922: 
                   2923:    <dt>Anything else</dt>
                   2924:    <dd>Append two U+002D HYPHEN-MINUS (-) characters, a U+0021
1.464     mike     2925:    EXCLAMATION MARK character (!), and the input character to the
1.1       mike     2926:    comment token's data. Switch to the <a href="#comment-state">comment
                   2927:    state</a>.</dd>
                   2928: 
                   2929:   </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.24 </span><dfn>Comment end space state</dfn></h5>
                   2930: 
                   2931:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2932: 
1.333     mike     2933:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
1.1       mike     2934:    <dt>U+000A LINE FEED (LF)</dt>
                   2935:    <dt>U+000C FORM FEED (FF)</dt>
                   2936:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2937:    <dt>U+0020 SPACE</dt>
                   2938:    <dd>Append the input character to the comment token's data. Stay in
                   2939:    the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2940: 
1.333     mike     2941:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2942:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2943: 
                   2944:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2945:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2946:    state</a>.</dd>
                   2947: 
1.1       mike     2948:    <dt>EOF</dt>
                   2949:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2950:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2951:    comment in comment end state -->
                   2952: 
                   2953:    <dt>Anything else</dt>
                   2954:    <dd>Append the input character to the comment token's data. Switch
                   2955:    to the <a href="#comment-state">comment state</a>.</dd>
                   2956: 
                   2957:   </dl><h5 id="doctype-state"><span class="secno">9.2.4.25 </span><dfn>DOCTYPE state</dfn></h5>
                   2958: 
                   2959:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2960: 
                   2961:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2962:    <dt>U+000A LINE FEED (LF)</dt>
                   2963:    <dt>U+000C FORM FEED (FF)</dt>
                   2964:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2965:    <dt>U+0020 SPACE</dt>
                   2966:    <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2967: 
                   2968:    <dt>EOF</dt>
                   2969:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2970:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2971:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2972: 
                   2973:    <dt>Anything else</dt>
                   2974:    <dd><a href="#parse-error">Parse error</a>. Reconsume the current
                   2975:    character in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2976: 
                   2977:   </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.26 </span><dfn>Before DOCTYPE name state</dfn></h5>
                   2978: 
                   2979:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2980: 
                   2981:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2982:    <dt>U+000A LINE FEED (LF)</dt>
                   2983:    <dt>U+000C FORM FEED (FF)</dt>
                   2984:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2985:    <dt>U+0020 SPACE</dt>
                   2986:    <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2987: 
                   2988:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2989:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2990:    lowercase version of the input character (add 0x0020 to the
                   2991:    character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2992:    state</a>.</dd>
                   2993: 
1.333     mike     2994:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2995:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2996:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
                   2997:    the <a href="#data-state">data state</a>.</dd>
                   2998: 
1.1       mike     2999:    <dt>EOF</dt>
                   3000:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   3001:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   3002:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3003: 
                   3004:    <dt>Anything else</dt>
                   3005:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   3006:    <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
                   3007:    state</a>.</dd>
                   3008: 
                   3009:   </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.27 </span><dfn>DOCTYPE name state</dfn></h5>
                   3010: 
                   3011:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3012: 
                   3013:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3014:    <dt>U+000A LINE FEED (LF)</dt>
                   3015:    <dt>U+000C FORM FEED (FF)</dt>
                   3016:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3017:    <dt>U+0020 SPACE</dt>
                   3018:    <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   3019: 
                   3020:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3021:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3022:    state</a>.</dd>
                   3023: 
                   3024:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   3025:    <dd>Append the lowercase version of the input character (add 0x0020
                   3026:    to the character's code point) to the current DOCTYPE token's
                   3027:    name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   3028: 
                   3029:    <dt>EOF</dt>
                   3030:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3031:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3032:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3033: 
                   3034:    <dt>Anything else</dt>
                   3035:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3036:    token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   3037: 
                   3038:   </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.28 </span><dfn>After DOCTYPE name state</dfn></h5>
                   3039: 
                   3040:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3041: 
                   3042:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3043:    <dt>U+000A LINE FEED (LF)</dt>
                   3044:    <dt>U+000C FORM FEED (FF)</dt>
                   3045:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3046:    <dt>U+0020 SPACE</dt>
                   3047:    <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   3048: 
                   3049:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3050:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3051:    state</a>.</dd>
                   3052: 
                   3053:    <dt>EOF</dt>
                   3054:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3055:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3056:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3057: 
                   3058:    <dt>Anything else</dt>
                   3059:    <dd>
                   3060: 
                   3061:     <p>If the six characters starting from the <a href="#current-input-character">current input
                   3062:     character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
                   3063:     for the word "PUBLIC", then consume those characters and switch to
1.444     mike     3064:     the <a href="#after-doctype-public-keyword-state">after DOCTYPE public keyword state</a>.</p>
1.1       mike     3065: 
                   3066:     <p>Otherwise, if the six characters starting from the
                   3067:     <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   3068:     case-insensitive</a> match for the word "SYSTEM", then consume
1.444     mike     3069:     those characters and switch to the <a href="#after-doctype-system-keyword-state">after DOCTYPE system
                   3070:     keyword state</a>.</p>
1.1       mike     3071: 
                   3072:     <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
                   3073:     DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
                   3074:     the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
                   3075: 
                   3076:    </dd>
                   3077: 
1.444     mike     3078:   </dl><h5 id="after-doctype-public-keyword-state"><span class="secno">9.2.4.29 </span><dfn>After DOCTYPE public keyword state</dfn></h5>
                   3079: 
                   3080:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3081: 
                   3082:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3083:    <dt>U+000A LINE FEED (LF)</dt>
                   3084:    <dt>U+000C FORM FEED (FF)</dt>
                   3085:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3086:    <dt>U+0020 SPACE</dt>
                   3087:    <dd>Switch to the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier
                   3088:    state</a>.</dd>
                   3089: 
                   3090:    <dt>EOF</dt>
                   3091:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3092:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3093:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3094: 
                   3095:    <dt>Anything else</dt>
                   3096:    <dd><a href="#parse-error">Parse error</a>. Reconsume the current character in
                   3097:    the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
                   3098: 
                   3099:   </dl><h5 id="before-doctype-public-identifier-state"><span class="secno">9.2.4.30 </span><dfn>Before DOCTYPE public identifier state</dfn></h5>
1.1       mike     3100: 
                   3101:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3102: 
                   3103:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3104:    <dt>U+000A LINE FEED (LF)</dt>
                   3105:    <dt>U+000C FORM FEED (FF)</dt>
                   3106:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3107:    <dt>U+0020 SPACE</dt>
                   3108:    <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
                   3109: 
                   3110:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3111:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   3112:    (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
                   3113:    (double-quoted) state</a>.</dd>
                   3114: 
                   3115:    <dt>U+0027 APOSTROPHE (')</dt>
                   3116:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   3117:    (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
                   3118:    (single-quoted) state</a>.</dd>
                   3119: 
                   3120:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3121:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3122:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3123:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3124: 
                   3125:    <dt>EOF</dt>
                   3126:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3127:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3128:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3129: 
                   3130:    <dt>Anything else</dt>
                   3131:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3132:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3133:    DOCTYPE state</a>.</dd>
                   3134: 
1.444     mike     3135:   </dl><h5 id="doctype-public-identifier-double-quoted-state"><span class="secno">9.2.4.31 </span><dfn>DOCTYPE public identifier (double-quoted) state</dfn></h5>
1.1       mike     3136: 
                   3137:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3138: 
                   3139:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   3140:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   3141: 
                   3142:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3143:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3144:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3145:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3146: 
                   3147:    <dt>EOF</dt>
                   3148:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3149:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3150:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3151: 
                   3152:    <dt>Anything else</dt>
                   3153:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3154:    token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
                   3155:    identifier (double-quoted) state</a>.</dd>
                   3156: 
1.444     mike     3157:   </dl><h5 id="doctype-public-identifier-single-quoted-state"><span class="secno">9.2.4.32 </span><dfn>DOCTYPE public identifier (single-quoted) state</dfn></h5>
1.1       mike     3158: 
                   3159:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3160: 
                   3161:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   3162:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   3163: 
                   3164:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3165:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3166:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3167:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3168: 
                   3169:    <dt>EOF</dt>
                   3170:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3171:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3172:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3173: 
                   3174:    <dt>Anything else</dt>
                   3175:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3176:    token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
                   3177:    identifier (single-quoted) state</a>.</dd>
                   3178: 
1.444     mike     3179:   </dl><h5 id="after-doctype-public-identifier-state"><span class="secno">9.2.4.33 </span><dfn>After DOCTYPE public identifier state</dfn></h5>
1.1       mike     3180: 
                   3181:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3182: 
                   3183:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3184:    <dt>U+000A LINE FEED (LF)</dt>
                   3185:    <dt>U+000C FORM FEED (FF)</dt>
                   3186:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3187:    <dt>U+0020 SPACE</dt>
1.444     mike     3188:    <dd>Switch to the <a href="#between-doctype-public-and-system-identifiers-state">between DOCTYPE public and system identifiers state</a>.</dd>
                   3189: 
                   3190:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3191:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3192:    state</a>.</dd>
                   3193: 
                   3194:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3195:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
                   3196:    identifier to the empty string (not missing), then switch to the
                   3197:    <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier (double-quoted) state</a>.</dd>
                   3198: 
                   3199:    <dt>U+0027 APOSTROPHE (')</dt>
                   3200:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
                   3201:    identifier to the empty string (not missing), then switch to the
                   3202:    <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier (single-quoted) state</a>.</dd>
                   3203: 
                   3204:    <dt>EOF</dt>
                   3205:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3206:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3207:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3208: 
                   3209:    <dt>Anything else</dt>
                   3210:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3211:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3212:    DOCTYPE state</a>.</dd>
                   3213: 
                   3214:   </dl><h5 id="between-doctype-public-and-system-identifiers-state"><span class="secno">9.2.4.34 </span><dfn>Between DOCTYPE public and system identifiers state</dfn></h5>
                   3215: 
                   3216:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3217: 
                   3218:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3219:    <dt>U+000A LINE FEED (LF)</dt>
                   3220:    <dt>U+000C FORM FEED (FF)</dt>
                   3221:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3222:    <dt>U+0020 SPACE</dt>
                   3223:    <dd>Stay in the <a href="#between-doctype-public-and-system-identifiers-state">between DOCTYPE public and system identifiers state</a>.</dd>
                   3224: 
                   3225:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3226:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3227:    state</a>.</dd>
1.1       mike     3228: 
                   3229:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3230:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3231:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   3232:    (double-quoted) state</a>.</dd>
                   3233: 
                   3234:    <dt>U+0027 APOSTROPHE (')</dt>
                   3235:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3236:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   3237:    (single-quoted) state</a>.</dd>
                   3238: 
                   3239:    <dt>EOF</dt>
                   3240:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3241:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3242:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3243: 
                   3244:    <dt>Anything else</dt>
                   3245:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3246:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3247:    DOCTYPE state</a>.</dd>
                   3248: 
1.444     mike     3249:   </dl><h5 id="after-doctype-system-keyword-state"><span class="secno">9.2.4.35 </span><dfn>After DOCTYPE system keyword state</dfn></h5>
                   3250: 
                   3251:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3252: 
                   3253:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3254:    <dt>U+000A LINE FEED (LF)</dt>
                   3255:    <dt>U+000C FORM FEED (FF)</dt>
                   3256:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3257:    <dt>U+0020 SPACE</dt>
                   3258:    <dd>Switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier
                   3259:    state</a>.</dd>
                   3260: 
                   3261:    <dt>EOF</dt>
                   3262:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3263:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3264:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3265: 
                   3266:    <dt>Anything else</dt>
                   3267:    <dd><a href="#parse-error">Parse error</a>. Reconsume the current character in
                   3268:    the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
                   3269: 
                   3270:   </dl><h5 id="before-doctype-system-identifier-state"><span class="secno">9.2.4.36 </span><dfn>Before DOCTYPE system identifier state</dfn></h5>
1.1       mike     3271: 
                   3272:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3273: 
                   3274:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3275:    <dt>U+000A LINE FEED (LF)</dt>
                   3276:    <dt>U+000C FORM FEED (FF)</dt>
                   3277:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3278:    <dt>U+0020 SPACE</dt>
                   3279:    <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
                   3280: 
                   3281:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3282:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3283:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   3284:    (double-quoted) state</a>.</dd>
                   3285: 
                   3286:    <dt>U+0027 APOSTROPHE (')</dt>
                   3287:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3288:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   3289:    (single-quoted) state</a>.</dd>
                   3290: 
                   3291:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3292:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3293:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3294:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3295: 
                   3296:    <dt>EOF</dt>
                   3297:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3298:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3299:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3300: 
                   3301:    <dt>Anything else</dt>
                   3302:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3303:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3304:    DOCTYPE state</a>.</dd>
                   3305: 
1.444     mike     3306:   </dl><h5 id="doctype-system-identifier-double-quoted-state"><span class="secno">9.2.4.37 </span><dfn>DOCTYPE system identifier (double-quoted) state</dfn></h5>
1.1       mike     3307: 
                   3308:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3309: 
                   3310:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   3311:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3312: 
                   3313:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3314:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3315:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3316:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3317: 
                   3318:    <dt>EOF</dt>
                   3319:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3320:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3321:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3322: 
                   3323:    <dt>Anything else</dt>
                   3324:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3325:    token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
                   3326:    identifier (double-quoted) state</a>.</dd>
                   3327: 
1.444     mike     3328:   </dl><h5 id="doctype-system-identifier-single-quoted-state"><span class="secno">9.2.4.38 </span><dfn>DOCTYPE system identifier (single-quoted) state</dfn></h5>
1.1       mike     3329: 
                   3330:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3331: 
                   3332:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   3333:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3334: 
                   3335:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3336:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3337:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3338:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3339: 
                   3340:    <dt>EOF</dt>
                   3341:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3342:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3343:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3344: 
                   3345:    <dt>Anything else</dt>
                   3346:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3347:    token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
                   3348:    identifier (single-quoted) state</a>.</dd>
                   3349: 
1.444     mike     3350:   </dl><h5 id="after-doctype-system-identifier-state"><span class="secno">9.2.4.39 </span><dfn>After DOCTYPE system identifier state</dfn></h5>
1.1       mike     3351: 
                   3352:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3353: 
                   3354:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3355:    <dt>U+000A LINE FEED (LF)</dt>
                   3356:    <dt>U+000C FORM FEED (FF)</dt>
                   3357:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3358:    <dt>U+0020 SPACE</dt>
                   3359:    <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3360: 
                   3361:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3362:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3363:    state</a>.</dd>
                   3364: 
                   3365:    <dt>EOF</dt>
                   3366:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3367:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3368:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3369: 
                   3370:    <dt>Anything else</dt>
                   3371:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
                   3372:    state</a>. (This does <em>not</em> set the DOCTYPE token's
                   3373:    <i>force-quirks flag</i> to <i>on</i>.)</dd>
                   3374: 
1.444     mike     3375:   </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.40 </span><dfn>Bogus DOCTYPE state</dfn></h5>
1.1       mike     3376: 
                   3377:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3378: 
                   3379:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3380:    <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
                   3381:    state</a>.</dd>
                   3382: 
                   3383:    <dt>EOF</dt>
                   3384:    <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
                   3385:    <a href="#data-state">data state</a>.</dd>
                   3386: 
                   3387:    <dt>Anything else</dt>
                   3388:    <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
                   3389: 
1.444     mike     3390:   </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.41 </span><dfn>CDATA section state</dfn></h5>
1.1       mike     3391: 
                   3392:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
1.91      mike     3393:   flag</a> is set to the PCDATA state.)</i></p>
1.1       mike     3394: 
                   3395:   <p>Consume every character up to the next occurrence of the three
                   3396:   character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
                   3397:   BRACKET U+003E GREATER-THAN SIGN (<code title="">]]&gt;</code>), or the
                   3398:   end of the file (EOF), whichever comes first. Emit a series of
                   3399:   character tokens consisting of all the characters consumed except
                   3400:   the matching three character sequence at the end (if one was found
                   3401:   before the end of the file).</p>
                   3402: 
                   3403:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   3404: 
                   3405:   <p>If the end of the file was reached, reconsume the EOF
                   3406:   character.</p>
                   3407: 
                   3408: 
                   3409: 
1.444     mike     3410:   <h5 id="tokenizing-character-references"><span class="secno">9.2.4.42 </span>Tokenizing character references</h5>
1.1       mike     3411: 
                   3412:   <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
                   3413:   reference</dfn>. This definition is used when parsing character
1.299     mike     3414:   references <a href="#character-reference-in-data-state" title="character reference in data state">in
1.1       mike     3415:   text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
                   3416:   state">in attributes</a>.</p>
                   3417: 
                   3418:   <p>The behavior depends on the identity of the next character (the
                   3419:   one immediately after the U+0026 AMPERSAND character):</p>
                   3420: 
                   3421:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3422:    <dt>U+000A LINE FEED (LF)</dt>
                   3423:    <dt>U+000C FORM FEED (FF)</dt>
                   3424:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3425:    <dt>U+0020 SPACE</dt>
                   3426:    <dt>U+003C LESS-THAN SIGN</dt>
                   3427:    <dt>U+0026 AMPERSAND</dt>
                   3428:    <dt>EOF</dt>
                   3429:    <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
                   3430: 
                   3431:    <dd>Not a character reference. No characters are consumed, and
                   3432:    nothing is returned. (This is not an error, either.)</dd>
                   3433: 
                   3434: 
                   3435:    <dt>U+0023 NUMBER SIGN (#)</dt>
                   3436: 
                   3437:    <dd>
                   3438: 
                   3439:     <p>Consume the U+0023 NUMBER SIGN.</p>
                   3440: 
                   3441:     <p>The behavior further depends on the character after the U+0023
                   3442:     NUMBER SIGN:</p>
                   3443: 
                   3444:     <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
                   3445:      <dt>U+0058 LATIN CAPITAL LETTER X</dt>
                   3446: 
                   3447:      <dd>
                   3448: 
                   3449:       <p>Consume the X.</p>
                   3450: 
                   3451:       <p>Follow the steps below, but using the range of characters
1.464     mike     3452:       U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), U+0061 LATIN
                   3453:       SMALL LETTER A to U+0066 LATIN SMALL LETTER F, and U+0041 LATIN
                   3454:       CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F (in other
                   3455:       words, 0-9, A-F, a-f).</p>
1.1       mike     3456: 
                   3457:       <p>When it comes to interpreting the number, interpret it as a
                   3458:       hexadecimal number.</p>
                   3459: 
                   3460:      </dd>
                   3461: 
                   3462: 
                   3463:      <dt>Anything else</dt>
                   3464: 
                   3465:      <dd>
                   3466: 
                   3467:       <p>Follow the steps below, but using the range of characters
1.464     mike     3468:       U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9).</p>
1.1       mike     3469: 
                   3470:       <p>When it comes to interpreting the number, interpret it as a
                   3471:       decimal number.</p>
                   3472: 
                   3473:      </dd>
                   3474: 
                   3475:     </dl><p>Consume as many characters as match the range of characters
                   3476:     given above.</p>
                   3477: 
                   3478:     <p>If no characters match the range, then don't consume any
                   3479:     characters (and unconsume the U+0023 NUMBER SIGN character and, if
                   3480:     appropriate, the X character). This is a <a href="#parse-error">parse
                   3481:     error</a>; nothing is returned.</p>
                   3482: 
                   3483:     <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
                   3484:     that too. If it isn't, there is a <a href="#parse-error">parse
                   3485:     error</a>.</p>
                   3486: 
                   3487:     <p>If one or more characters match the range, then take them all
                   3488:     and interpret the string of characters as a number (either
                   3489:     hexadecimal or decimal as appropriate).</p>
                   3490: 
                   3491:     <p>If that number is one of the numbers in the first column of the
                   3492:     following table, then this is a <a href="#parse-error">parse error</a>. Find the
                   3493:     row with that number in the first column, and return a character
                   3494:     token for the Unicode character given in the second column of that
                   3495:     row.</p>
                   3496: 
                   3497:     <table><thead><tr><th>Number </th><th colspan="2">Unicode character
                   3498:      </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
                   3499:       </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
1.464     mike     3500:       </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN (&#8364;)
1.1       mike     3501:       </td></tr><tr><td>0x81 </td><td>U+0081 </td><td>&lt;control&gt;
1.464     mike     3502:       </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK (&#8218;)
                   3503:       </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK (&#402;)
                   3504:       </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK (&#8222;)
                   3505:       </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS (&#8230;)
                   3506:       </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER (&#8224;)
                   3507:       </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER (&#8225;)
                   3508:       </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT (&#710;)
                   3509:       </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN (&#8240;)
                   3510:       </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON (&#352;)
                   3511:       </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK (&#8249;)
                   3512:       </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE (&#338;)
1.1       mike     3513:       </td></tr><tr><td>0x8D </td><td>U+008D </td><td>&lt;control&gt;
1.464     mike     3514:       </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON (&#381;)
1.1       mike     3515:       </td></tr><tr><td>0x8F </td><td>U+008F </td><td>&lt;control&gt;
                   3516:       </td></tr><tr><td>0x90 </td><td>U+0090 </td><td>&lt;control&gt;
1.464     mike     3517:       </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK (&#8216;)
                   3518:       </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK (&#8217;)
                   3519:       </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK (&#8220;)
                   3520:       </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK (&#8221;)
                   3521:       </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET (&#8226;)
                   3522:       </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH (&#8211;)
                   3523:       </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH (&#8212;)
                   3524:       </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE (&#732;)
                   3525:       </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN (&#8482;)
                   3526:       </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON (&#353;)
                   3527:       </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK (&#8250;)
                   3528:       </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE (&#339;)
1.1       mike     3529:       </td></tr><tr><td>0x9D </td><td>U+009D </td><td>&lt;control&gt;
1.464     mike     3530:       </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON (&#382;)
                   3531:       </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS (&#376;)
1.315     mike     3532:     </td></tr></tbody></table><p>Otherwise, if the number is in the range 0xD800 to 0xDFFF<!--
                   3533:     surrogates not allowed; see the comment in the "preprocessing the
                   3534:     input stream" section for details --> or is greater than 0x10FFFF,
                   3535:     then this is a <a href="#parse-error">parse error</a>. Return a U+FFFD
                   3536:     REPLACEMENT CHARACTER.</p>
1.18      mike     3537: 
                   3538:     <p>Otherwise, return a character token for the Unicode character
1.1       mike     3539:     whose code point is that number.
                   3540: 
                   3541:     <!-- this is the same as the equivalent list in the input stream
                   3542:     section -->
                   3543:     If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
                   3544:     allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
                   3545:     allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
1.315     mike     3546:     0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xFDD0 to
                   3547:     0xFDEF, or is one of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF,
                   3548:     0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE,
                   3549:     0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF,
                   3550:     0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE,
                   3551:     0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF,
                   3552:     0x10FFFE, or 0x10FFFF, then this is a <a href="#parse-error">parse
                   3553:     error</a>.</p>
1.1       mike     3554: 
                   3555:    </dd>
                   3556: 
                   3557: 
                   3558:    <dt>Anything else</dt>
                   3559: 
                   3560:    <dd>
                   3561: 
                   3562:     <p>Consume the maximum number of characters possible, with the
                   3563:     consumed characters matching one of the identifiers in the first
                   3564:     column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
                   3565:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
                   3566: 
                   3567:     <p>If no match can be made, then this is a <a href="#parse-error">parse
                   3568:     error</a>. No characters are consumed, and nothing is
                   3569:     returned.</p>
                   3570: 
                   3571:     <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>
                   3572: 
                   3573:     <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
                   3574:     attribute</a>, and the last character matched is not a U+003B
1.464     mike     3575:     SEMICOLON character (<code title="">;</code>), and the next
                   3576:     character is in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT
                   3577:     NINE (9), U+0041 LATIN CAPITAL LETTER A to U+005A LATIN CAPITAL
                   3578:     LETTER Z, or U+0061 LATIN SMALL LETTER A to U+007A LATIN SMALL
                   3579:     LETTER Z, then, for historical reasons, all the characters that
                   3580:     were matched after the U+0026 AMPERSAND character (&amp;) must be
                   3581:     unconsumed, and nothing is returned.</p>
1.1       mike     3582: 
                   3583:     <p>Otherwise, return a character token for the character
                   3584:     corresponding to the character reference name (as given by the
                   3585:     second column of the <a href="named-character-references.html#named-character-references">named character references</a>
                   3586:     table).</p>
                   3587: 
                   3588:     <div class="example">
                   3589: 
                   3590:      <p>If the markup contains <code title="">I'm &amp;notit; I tell
                   3591:      you</code>, the character reference is parsed as "not", as in,
                   3592:      <code title="">I'm &#172;it; I tell you</code>. But if the markup
                   3593:      was <code title="">I'm &amp;notin; I tell you</code>, the
                   3594:      character reference would be parsed as "notin;", resulting in
                   3595:      <code title="">I'm &#8713; I tell you</code>.</p>
                   3596: 
                   3597:     </div>
                   3598: 
                   3599:    </dd>
                   3600: 
1.266     mike     3601:   </dl></div><div class="impl">
                   3602: 
1.363     mike     3603:   <!-- v2: One thing that this doesn't define is handling deeply
                   3604:   nested documents. There are compatibility requirements around that:
                   3605:   you can't throw away the elements altogether, consider Tux made only
                   3606:   with opening <font> elements, one per character. Seems that the best
                   3607:   thing to do is to close some formatting elements from the middle of
                   3608:   the stack when you hit a limit, or something. -->
                   3609: 
1.266     mike     3610:   <h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4>
1.1       mike     3611: 
                   3612:   <p>The input to the tree construction stage is a sequence of tokens
                   3613:   from the <a href="#tokenization">tokenization</a> stage. The tree construction
                   3614:   stage is associated with a DOM <code>Document</code> object when a
                   3615:   parser is created. The "output" of this stage consists of
                   3616:   dynamically modifying or extending that document's DOM tree.</p>
                   3617: 
                   3618:   <p>This specification does not define when an interactive user agent
                   3619:   has to render the <code>Document</code> so that it is available to
                   3620:   the user, or when it has to begin accepting user input.</p>
                   3621: 
                   3622:   <p>As each token is emitted from the tokenizer, the user agent must
                   3623:   process the token according to the rules given in the section
                   3624:   corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
                   3625: 
                   3626:   <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
                   3627:   character</dfn> into a node, if that node has a child immediately
                   3628:   before where the character is to be inserted, and that child is a
                   3629:   <code>Text</code> node, and that <code>Text</code> node was the last
                   3630:   node that the parser inserted into the document, then the character
                   3631:   must be appended to that <code>Text</code> node; otherwise, a new
                   3632:   <code>Text</code> node whose data is just that character must be
                   3633:   inserted in the appropriate place.</p>
                   3634: 
                   3635:   <div class="example">
                   3636: 
                   3637:    <p>Here are some sample inputs to the parser and the corresponding
                   3638:    number of text nodes that they result in, assuming a user agent
                   3639:    that executes scripts.</p>
                   3640: 
                   3641:    <table><thead><tr><th>Input </th><th>Number of text nodes
                   3642:     </th></tr></thead><tbody><tr><td><pre>A&lt;script&gt;
                   3643: var&#160;script&#160;=&#160;document.getElementsByTagName('script')[0];
                   3644: document.body.removeChild(script);
                   3645: &lt;/script&gt;B</pre>
                   3646:       </td><td>Two adjacent text nodes in the document, containing "A" and "B".
                   3647:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3648: var&#160;text&#160;=&#160;document.createTextNode('B');
                   3649: document.body.appendChild(text);
                   3650: &lt;/script&gt;C</pre>
                   3651:       </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
                   3652:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3653: var&#160;text&#160;=&#160;document.getElementsByTagName('script')[0].firstChild;
                   3654: text.data&#160;=&#160;'B';
                   3655: document.body.appendChild(text);
                   3656: &lt;/script&gt;B</pre>
                   3657:       </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
                   3658:      </td></tr><tr><td><pre>A&lt;table&gt;B&lt;tr&gt;C&lt;/tr&gt;C&lt;/table&gt;</pre>
                   3659:       </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>.)
                   3660:      </td></tr><tr><td><pre>A&lt;table&gt;&lt;tr&gt;&#160;B&lt;/tr&gt;&#160;B&lt;/table&gt;</pre>
                   3661:       </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>.)
                   3662:      </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>
                   3663:       </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.)
                   3664:    </td></tr></tbody></table></div>
                   3665: 
                   3666:   <p id="mutation-during-parsing">DOM mutation events must not fire
                   3667:   for changes caused by the UA parsing the document. (Conceptually,
                   3668:   the parser is not mutating the DOM, it is constructing it.) This
1.159     mike     3669:   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     3670: 
                   3671:   <p class="note">Not all of the tag names mentioned below are
                   3672:   conformant tag names in this specification; many are included to
                   3673:   handle legacy content. They still form part of the algorithm that
                   3674:   implementations are required to implement to claim conformance.</p>
                   3675: 
                   3676:   <p class="note">The algorithm described below places no limit on the
                   3677:   depth of the DOM tree generated, or on the length of tag names,
                   3678:   attribute names, attribute values, text nodes, etc. While
                   3679:   implementors are encouraged to avoid arbitrary limits, it is
                   3680:   recognized that <a href="infrastructure.html#hardwareLimitations">practical
1.445     mike     3681:   concerns</a> will likely force user agents to impose nesting depth
                   3682:   constraints.</p>
1.1       mike     3683: 
                   3684: 
                   3685:   <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5>
                   3686: 
                   3687:   <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
                   3688:   element for the token">create an element for a token</dfn> in a
                   3689:   particular namespace, the UA must create a node implementing the
                   3690:   interface appropriate for the element type corresponding to the tag
                   3691:   name of the token in the given namespace (as given in the
                   3692:   specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
                   3693:   element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
                   3694:   defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
                   3695:   the tag name being the name of that element, with the node being in
                   3696:   the given namespace, and with the attributes on the node being those
                   3697:   given in the given token.</p>
                   3698: 
                   3699:   <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
1.426     mike     3700:   namespace</a> that is not defined in this specification (or
                   3701:   <a href="infrastructure.html#other-applicable-specifications">other applicable specifications</a>) is
1.44      mike     3702:   <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1       mike     3703:   interface is not defined by that namespace's specification must use
                   3704:   the interface <code>Element</code>.</p>
                   3705: 
                   3706:   <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
                   3707:   created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
                   3708:   invoked once the attributes are set. (This initializes the element's
                   3709:   <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
                   3710:   attributes.)</p>
                   3711: 
                   3712:   <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
                   3713:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3714:   for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
                   3715:   append this node to the <a href="#current-node">current node</a>, and push it onto
                   3716:   the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3717:   <a href="#current-node">current node</a>.</p>
                   3718: 
                   3719:   <p>The steps below may also require that the UA insert an HTML
                   3720:   element in a particular place, in which case the UA must follow the
                   3721:   same steps except that it must insert or append the new node in the
                   3722:   location specified instead of appending it to the <a href="#current-node">current
                   3723:   node</a>. (This happens in particular during the parsing of
                   3724:   tables with invalid content.)</p>
                   3725: 
                   3726:   <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
                   3727:   algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
                   3728:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
                   3729:   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
                   3730:   <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
                   3731:   created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
                   3732:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
                   3733:   inserting it wherever it is to be inserted.</p>
                   3734: 
                   3735:   <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
                   3736:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3737:   for the token</a> in the given namespace, and then append this
                   3738:   node to the <a href="#current-node">current node</a>, and push it onto the
                   3739:   <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3740:   <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>
                   3741:   whose value is not exactly the same as the element's namespace, that
                   3742:   is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
                   3743:   element has an <code title="">xmlns:xlink</code> attribute in the
                   3744:   <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
                   3745:   Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
                   3746: 
                   3747:   <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
                   3748:   attributes</dfn> for a token, then, if the token has an attribute
                   3749:   named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
                   3750: 
                   3751:   <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
                   3752:   attributes</dfn> for a token, then, for each attribute on the token
                   3753:   whose attribute name is one of the ones in the first column of the
                   3754:   following table, change the attribute's name to the name given in
                   3755:   the corresponding cell in the second column. (This fixes the case of
                   3756:   SVG attributes that are not all lowercase.)</p>
                   3757: 
                   3758:   <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
                   3759:    </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
                   3760:     </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
                   3761:     </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
                   3762:     </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
                   3763:     </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
                   3764:     </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
                   3765:     </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
                   3766:     </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
                   3767:     </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
                   3768:     </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
                   3769:     </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
                   3770:     </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
                   3771:     </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
                   3772:     </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   3773:     </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
                   3774:     </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
                   3775:     </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
                   3776:     </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
                   3777:     </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
                   3778:     </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
                   3779:     </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
                   3780:     </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
                   3781:     </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
                   3782:     </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
                   3783:     </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
                   3784:     </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
                   3785:     </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
                   3786:     </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
                   3787:     </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
                   3788:     </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
                   3789:     </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
                   3790:     </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
                   3791:     </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
                   3792:     </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
                   3793:     </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
                   3794:     </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
                   3795:     </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
                   3796:     </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
                   3797:     </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
                   3798:     </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
                   3799:     </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
                   3800:     </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
                   3801:     </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
                   3802:     </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
                   3803:     </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
                   3804:     </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
                   3805:     </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
                   3806:     </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
                   3807:     </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
                   3808:     </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
                   3809:     </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
                   3810:     </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
                   3811:     </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
                   3812:     </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
                   3813:     </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
                   3814:     </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
                   3815:     </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
                   3816:     </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
                   3817:     </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
                   3818:     </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
                   3819:     </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
                   3820:     </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
                   3821:   </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
                   3822:   foreign attributes</dfn> for a token, then, if any of the attributes
                   3823:   on the token match the strings given in the first column of the
                   3824:   following table, let the attribute be a namespaced attribute, with
                   3825:   the prefix being the string given in the corresponding cell in the
                   3826:   second column, the local name being the string given in the
                   3827:   corresponding cell in the third column, and the namespace being the
                   3828:   namespace given in the corresponding cell in the fourth
                   3829:   column. (This fixes the use of namespaced attributes, in particular
                   3830:   <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
                   3831:   the <span>XML namespace</span></a>.)</p>
                   3832: 
                   3833:   <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
                   3834:    </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>
                   3835:     </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>
                   3836:     </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>
                   3837:     </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>
                   3838:     </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>
                   3839:     </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>
                   3840:     </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>
                   3841:     </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 -->
                   3842:     </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>
                   3843:     </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>
                   3844:     </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>
                   3845:     </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     3846:   </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     3847:   <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
                   3848:   following steps. These algorithms are always invoked in response to
                   3849:   a start tag token.</p>
                   3850: 
                   3851:   <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
                   3852: 
1.91      mike     3853:    <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
                   3854:    text element parsing algorithm</a>, switch the tokenizer's
                   3855:    <a href="#content-model-flag">content model flag</a> to the RAWTEXT state; otherwise the
1.1       mike     3856:    algorithm invoked was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing
                   3857:    algorithm</a>, switch the tokenizer's <a href="#content-model-flag">content model
                   3858:    flag</a> to the RCDATA state.</p></li>
                   3859: 
                   3860:    <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   3861:    <a href="#insertion-mode">insertion mode</a>.</p>
                   3862: 
1.91      mike     3863:    </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
                   3864:    RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     3865: 
                   3866:   </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>
                   3867: 
                   3868:   <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
                   3869:   tags</dfn>, then, while the <a href="#current-node">current node</a> is a
1.422     mike     3870:   <code><a href="semantics.html#the-dd-element">dd</a></code> element, a <code><a href="semantics.html#the-dt-element">dt</a></code> element, an
1.1       mike     3871:   <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
                   3872:   <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
                   3873:   <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
                   3874:   pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   3875:   elements</a>.</p>
                   3876: 
                   3877:   <p>If a step requires the UA to generate implied end tags but lists
                   3878:   an element to exclude from the process, then the UA must perform the
                   3879:   above steps as if that element was not in the above list.</p>
                   3880: 
                   3881: 
                   3882:   <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5>
                   3883: 
                   3884:   <p>Foster parenting happens when content is misnested in tables.</p>
                   3885: 
                   3886:   <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
                   3887:   parent">foster parented</dfn>, the node <var title="">node</var>
                   3888:   must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3889: 
                   3890:   <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
                   3891:   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
                   3892:   elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
                   3893:   such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3894:   the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
                   3895:   case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
                   3896:   element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
1.159     mike     3897:   <code><a href="semantics.html#the-html-element-0">html</a></code> element). Otherwise, if there is a
1.1       mike     3898:   <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
                   3899:   elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3900:   <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
                   3901:   node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
                   3902:   the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3903:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   3904: 
                   3905:   <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
                   3906:   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
                   3907:   elements</a>, then <var title="">node</var> must be inserted
                   3908:   immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3909:   the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
                   3910:   element</a></i>; otherwise, <var title="">node</var> must be
                   3911:   <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3912: 
                   3913: 
                   3914: 
                   3915:   <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>
                   3916: 
                   3917:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
                   3918:   mode: initial">initial</a>", tokens must be handled as follows:</p>
                   3919: 
                   3920:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3921:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3922:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3923:    <dd>
                   3924:     <p>Ignore the token.</p>
                   3925:    </dd>
                   3926: 
                   3927:    <dt>A comment token</dt>
                   3928:    <dd>
                   3929:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   3930:     object with the <code title="">data</code> attribute set to the
                   3931:     data given in the comment token.</p>
                   3932:    </dd>
                   3933: 
                   3934:    <dt>A DOCTYPE token</dt>
                   3935:    <dd>
                   3936: 
                   3937:     <p>If the DOCTYPE token's name is not a
                   3938:     <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
                   3939:     missing, or the token's system identifier is neither missing nor a
                   3940:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
1.465     mike     3941:     "<code><a href="infrastructure.html#about:legacy-compat">about:legacy-compat</a></code>", and none of the sets of
1.1       mike     3942:     conditions in the following list are matched, then there is a
                   3943:     <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
                   3944:     following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
                   3945:     permitted DOCTYPE</dfn>.</p>
                   3946: 
                   3947:     <ul><!-- only things that trigger no-quirks mode and were valid in
                   3948:      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     3949:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3950:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.0//EN</code>", and the
                   3951:      token's system identifier is either missing or the
                   3952:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
                   3953: 
                   3954:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3955:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3956:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.01//EN</code>", and the
                   3957:      token's system identifier is either missing or the
                   3958:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
                   3959: 
                   3960:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3961:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3962:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.0&#160;Strict//EN</code>",
                   3963:      and the token's system identifier is the
                   3964:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
                   3965: 
                   3966:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3967:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3968:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.1//EN</code>", and the
                   3969:      token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
                   3970:      string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
                   3971: 
                   3972:     </ul><p>Conformance checkers may, based on the values (including
                   3973:     presence or lack thereof) of the DOCTYPE token's name, public
                   3974:     identifier, or system identifier, switch to a conformance checking
                   3975:     mode for another language (e.g. based on the DOCTYPE token a
                   3976:     conformance checker could recognize that the document is an
1.183     mike     3977:     HTML4-era document, and defer to an HTML4 conformance
1.1       mike     3978:     checker.)</p>
                   3979: 
                   3980:     <p>Append a <code>DocumentType</code> node to the
                   3981:     <code>Document</code> node, with the <code title="">name</code>
                   3982:     attribute set to the name given in the DOCTYPE token, or the empty
                   3983:     string if the name was missing; the <code title="">publicId</code>
                   3984:     attribute set to the public identifier given in the DOCTYPE token,
                   3985:     or the empty string if the public identifier was missing; the
                   3986:     <code title="">systemId</code> attribute set to the system
                   3987:     identifier given in the DOCTYPE token, or the empty string if the
                   3988:     system identifier was missing; and the other attributes specific
                   3989:     to <code>DocumentType</code> objects set to null and empty lists
                   3990:     as appropriate. Associate the <code>DocumentType</code> node with
                   3991:     the <code>Document</code> object so that it is returned as the
                   3992:     value of the <code title="">doctype</code> attribute of the
                   3993:     <code>Document</code> object.</p>
                   3994: 
                   3995:     <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
                   3996:     one of the conditions in the following list, then set the
                   3997:     <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
                   3998: 
                   3999:     <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
                   4000:      <li> The name is set to anything other than "<code title="">HTML</code>". </li>
                   4001:      <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
                   4002:      <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   4003:      <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   4004:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
                   4005:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
                   4006:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
                   4007:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
                   4008:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
                   4009:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
                   4010:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
                   4011:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
                   4012:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
                   4013:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   4014:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
                   4015:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
                   4016:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
                   4017:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
                   4018:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
                   4019:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
                   4020:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
                   4021:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
                   4022:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
                   4023:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
                   4024:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
                   4025:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
                   4026:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
                   4027:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
                   4028:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
                   4029:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
                   4030:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
                   4031:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
                   4032:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
                   4033:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
                   4034:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
                   4035:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
                   4036:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
                   4037:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
                   4038:      <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
                   4039:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
                   4040:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
                   4041:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
                   4042:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
                   4043:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
                   4044:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
                   4045:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
                   4046:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
                   4047:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
                   4048:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
                   4049:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
                   4050:      <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
                   4051:      <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
                   4052:      <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
                   4053:      <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
                   4054:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
                   4055:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
                   4056:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
                   4057:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
                   4058:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   4059:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
                   4060:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
                   4061:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
                   4062:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
                   4063:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
                   4064:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
                   4065:      <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
                   4066:      <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
                   4067:    <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
                   4068:      <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
                   4069:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
                   4070:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
                   4071:      <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
                   4072:      <li> The public identifier is set to: "<code title="">HTML</code>" </li>
                   4073:      <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
                   4074:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   4075:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   4076:     </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
                   4077:     in the following list, then set the <code>Document</code> to
                   4078:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
                   4079: 
                   4080:     <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
                   4081:      <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
                   4082:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   4083:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   4084:     </ul><p>The name, system identifier, and public identifier strings must
                   4085:     be compared to the values given in the lists above in an
                   4086:     <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
                   4087:     whose value is the empty string is not considered missing for the
                   4088:     purposes of the conditions above.</p>
                   4089: 
                   4090:     <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>
                   4091: 
                   4092:    </dd>
                   4093: 
                   4094:    <dt>Anything else</dt>
                   4095:    <dd>
                   4096: 
                   4097:     <p><a href="#parse-error">Parse error</a>.</p>
                   4098: 
                   4099:     <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
                   4100: 
                   4101:     <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
                   4102:     reprocess the current token.</p>
                   4103: 
                   4104:    </dd>
                   4105: 
                   4106:   </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>
                   4107: 
                   4108:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
                   4109:   mode: before html">before html</a>", tokens must be handled as follows:</p>
                   4110: 
                   4111:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   4112:    <dd>
                   4113:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4114:    </dd>
                   4115: 
                   4116:    <dt>A comment token</dt>
                   4117:    <dd>
                   4118:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   4119:     object with the <code title="">data</code> attribute set to the
                   4120:     data given in the comment token.</p>
                   4121:    </dd>
                   4122: 
                   4123:    <dt>A character token that is one of U+0009 CHARACTER
                   4124:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4125:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4126:    <dd>
                   4127:     <p>Ignore the token.</p>
                   4128:    </dd>
                   4129: 
                   4130:    <dt>A start tag whose tag name is "html"</dt>
                   4131:    <dd>
                   4132: 
                   4133:     <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
                   4134:     namespace</a>. Append it to the <code>Document</code>
                   4135:     object. Put this element in the <a href="#stack-of-open-elements">stack of open
                   4136:     elements</a>.</p>
                   4137: 
                   4138:     <p id="parser-appcache">If the <code>Document</code> is being
                   4139:     loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
                   4140:     <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
                   4141:     has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
                   4142:     then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
                   4143:     attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
                   4144:     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     4145:     algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
                   4146:     any <a href="infrastructure.html#url-fragment" title="url-fragment">&lt;fragment&gt;</a> component
                   4147:     removed; otherwise, if there is no such attribute or resolving it
                   4148:     fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
                   4149:     cache selection algorithm</a> with no manifest. The algorithm
                   4150:     must be passed the <code>Document</code> object.</p>
1.1       mike     4151: 
                   4152:     <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>
                   4153: 
                   4154:    </dd>
                   4155: 
1.334     mike     4156:    <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
                   4157:    <dd>
                   4158:     <p>Act as described in the "anything else" entry below.</p>
                   4159:    </dd>
                   4160: 
                   4161:    <dt>Any other end tag</dt>
                   4162:    <dd>
                   4163:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4164:    </dd>
                   4165: 
1.1       mike     4166:    <dt>Anything else</dt>
                   4167:    <dd>
                   4168: 
1.159     mike     4169:     <p>Create an <code><a href="semantics.html#the-html-element-0">html</a></code> element. Append it to the
1.1       mike     4170:     <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
                   4171:     of open elements</a>.</p>
                   4172: 
                   4173:     <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
                   4174:     context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
                   4175:     algorithm</a> with no manifest, passing it the
                   4176:     <code>Document</code> object.</p>
                   4177: 
                   4178:     <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
                   4179:     reprocess the current token.</p>
                   4180: 
                   4181:    </dd>
                   4182: 
                   4183:   </dl><p>The root element can end up being removed from the
                   4184:   <code>Document</code> object, e.g. by scripts; nothing in particular
                   4185:   happens in such cases, content continues being appended to the nodes
                   4186:   as described in the next section.</p>
                   4187: 
                   4188: 
                   4189:   <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>
                   4190: 
                   4191:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
                   4192:   mode: before head">before head</a>", tokens must be handled as follows:</p>
                   4193: 
                   4194:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4195:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4196:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4197:    <dd>
                   4198:     <p>Ignore the token.</p> <!-- :-( -->
                   4199:    </dd>
                   4200: 
                   4201:    <dt>A comment token</dt>
                   4202:    <dd>
                   4203:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4204:     node</a> with the <code title="">data</code> attribute set to
                   4205:     the data given in the comment token.</p>
                   4206:    </dd>
                   4207: 
                   4208:    <dt>A DOCTYPE token</dt>
                   4209:    <dd>
                   4210:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4211:    </dd>
                   4212: 
                   4213:    <dt>A start tag whose tag name is "html"</dt>
                   4214:    <dd>
                   4215:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   4216:     mode</a>.</p>
                   4217:    </dd>
                   4218: 
                   4219:    <dt>A start tag whose tag name is "head"</dt>
                   4220:    <dd>
                   4221: 
                   4222:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4223: 
                   4224:     <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
1.159     mike     4225:     to the newly created <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike     4226: 
                   4227:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>".</p>
                   4228: 
                   4229:    </dd>
                   4230: 
                   4231:    <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
                   4232:    <dd>
                   4233: 
                   4234:     <p>Act as if a start tag token with the tag name "head" and no
                   4235:     attributes had been seen, then reprocess the current token.</p>
                   4236: 
                   4237:    </dd>
                   4238: 
                   4239:    <dt>Any other end tag</dt>
                   4240:    <dd>
                   4241: 
                   4242:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4243: 
                   4244:    </dd>
                   4245: 
                   4246:    <dt>Anything else</dt>
                   4247:    <dd>
                   4248: 
                   4249:     <p>Act as if a start tag token with the tag name "head" and no
                   4250:     attributes had been seen, then reprocess the current
                   4251:     token.</p>
                   4252: 
                   4253:    </dd>
                   4254: 
                   4255:   </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>
                   4256: 
                   4257:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
                   4258:   mode: in head">in head</a>", tokens must be handled as follows:</p>
                   4259: 
                   4260:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4261:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4262:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4263:    <dd>
                   4264:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   4265:     the <a href="#current-node">current node</a>.</p>
                   4266:    </dd>
                   4267: 
                   4268:    <dt>A comment token</dt>
                   4269:    <dd>
                   4270:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4271:     node</a> with the <code title="">data</code> attribute set to
                   4272:     the data given in the comment token.</p>
                   4273:    </dd>
                   4274: 
                   4275:    <dt>A DOCTYPE token</dt>
                   4276:    <dd>
                   4277:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4278:    </dd>
                   4279: 
                   4280:    <dt>A start tag whose tag name is "html"</dt>
                   4281:    <dd>
                   4282:     <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
                   4283:     mode</a>.</p>
                   4284:    </dd>
                   4285: 
                   4286:    <dt>A start tag whose tag name is one of: "base", "command",
                   4287:    "link"</dt>
                   4288:    <dd>
                   4289: 
                   4290:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   4291:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   4292:     elements</a>.</p>
                   4293: 
                   4294:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4295:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4296: 
                   4297:    </dd>
                   4298: 
                   4299:    <dt>A start tag whose tag name is "meta"</dt>
                   4300:    <dd>
                   4301: 
                   4302:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   4303:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   4304:     elements</a>.</p>
                   4305: 
                   4306:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4307:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4308: 
                   4309:     <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
                   4310:     value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   4311:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   4312:     encoding</a> to the encoding given by the value of the
                   4313:     <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
                   4314: 
                   4315:     <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
                   4316:     applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
                   4317:     Content-Type</a> to its value returns a supported encoding
                   4318:     <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   4319:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   4320:     encoding</a> to the encoding <var title="">encoding</var>.</p>
                   4321: 
                   4322:    </dd>
                   4323: 
                   4324:    <dt>A start tag whose tag name is "title"</dt>
                   4325:    <dd>
                   4326:     <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
                   4327:    </dd>
                   4328: 
                   4329:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   4330:    <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
                   4331:    <dd>
1.91      mike     4332:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     4333:    </dd>
                   4334: 
                   4335:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
                   4336:    <dd>
                   4337: 
                   4338:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4339: 
                   4340:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
                   4341:     noscript</a>".</p>
                   4342: 
                   4343:    </dd>
                   4344: 
                   4345:    <dt id="scriptTag">A start tag whose tag name is "script"</dt>
                   4346:    <dd>
                   4347: 
                   4348:     <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
                   4349:      <a href="#html-namespace-0">HTML namespace</a>.</p></li>
                   4350: 
                   4351:      <li>
                   4352: 
                   4353:       <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
                   4354: 
                   4355:       <p class="note">This ensures that, if the script is external,
1.159     mike     4356:       any <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>
1.1       mike     4357:       calls in the script will execute in-line, instead of blowing the
                   4358:       document away, as would happen in most other cases. It also
                   4359:       prevents the script from executing until the end tag is
                   4360:       seen.</p>
                   4361: 
                   4362:      </li>
                   4363: 
                   4364:      <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
                   4365:      fragment parsing algorithm</a>, then mark the
1.484     mike     4366:      <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-started">"already
                   4367:      started"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
1.1       mike     4368: 
                   4369:      <li><p>Append the new element to the <a href="#current-node">current node</a>
                   4370:      and push it onto the <a href="#stack-of-open-elements">stack of open
                   4371:      elements</a>.</p></li>
                   4372: 
                   4373:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
1.91      mike     4374:      the RAWTEXT state.</p></li>
1.1       mike     4375: 
                   4376:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   4377:      <a href="#insertion-mode">insertion mode</a>.</p>
                   4378: 
1.91      mike     4379:      </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
                   4380:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     4381: 
                   4382:     </ol></dd>
                   4383: 
                   4384:    <dt>An end tag whose tag name is "head"</dt>
                   4385:    <dd>
                   4386: 
                   4387:     <p>Pop the <a href="#current-node">current node</a> (which will be the
1.159     mike     4388:     <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     4389:     elements</a>.</p>
                   4390: 
                   4391:     <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>
                   4392: 
                   4393:    </dd>
                   4394: 
                   4395:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4396:    <dd>
                   4397:     <p>Act as described in the "anything else" entry below.</p>
                   4398:    </dd>
                   4399: 
                   4400:    <dt>A start tag whose tag name is "head"</dt>
                   4401:    <dt>Any other end tag</dt>
                   4402:    <dd>
                   4403:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4404:    </dd>
                   4405: 
                   4406:    <dt>Anything else</dt>
                   4407:    <dd>
                   4408: 
                   4409:     <!-- can't get here with an EOF and a fragment case -->
                   4410: 
                   4411:     <p>Act as if an end tag token with the tag name "head" had
                   4412:     been seen, and reprocess the current token.</p>
                   4413: 
                   4414:    </dd>
                   4415: 
                   4416:   </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>
                   4417: 
                   4418:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
                   4419:   mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
                   4420: 
                   4421:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   4422:    <dd>
                   4423:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4424:    </dd>
                   4425: 
                   4426:    <dt>A start tag whose tag name is "html"</dt>
                   4427:    <dd>
                   4428:     <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
                   4429:     mode</a>.</p>
                   4430:    </dd>
                   4431: 
                   4432:    <dt>An end tag whose tag name is "noscript"</dt>
                   4433:    <dd>
                   4434: 
                   4435:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   4436:     <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   4437:     elements</a>; the new <a href="#current-node">current node</a> will be a
1.159     mike     4438:     <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike     4439: 
                   4440:     <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>
                   4441: 
                   4442:    </dd>
                   4443: 
                   4444:    <dt>A character token that is one of U+0009 CHARACTER
                   4445:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4446:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4447:    <dt>A comment token</dt>
                   4448:    <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
                   4449:    <dd>
                   4450:     <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
                   4451:     mode</a>.</p>
                   4452:    </dd>
                   4453: 
                   4454:    <dt>An end tag whose tag name is "br"</dt>
                   4455:    <dd>
                   4456:     <p>Act as described in the "anything else" entry below.</p>
                   4457:    </dd>
                   4458: 
                   4459:    <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
                   4460:    <dt>Any other end tag</dt>
                   4461:    <dd>
                   4462:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4463:    </dd>
                   4464: 
                   4465:    <dt>Anything else</dt>
                   4466:    <dd>
                   4467: 
                   4468:     <!-- can't get here with an EOF and a fragment case -->
                   4469: 
                   4470:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   4471:     name "noscript" had been seen and reprocess the current
                   4472:     token.</p>
                   4473: 
                   4474:    </dd>
                   4475: 
                   4476:   </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>
                   4477: 
                   4478:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
                   4479:   mode: after head">after head</a>", tokens must be handled as follows:</p>
                   4480: 
                   4481:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4482:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4483:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4484:    <dd>
                   4485:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   4486:     the <a href="#current-node">current node</a>.</p>
                   4487:    </dd>
                   4488: 
                   4489:    <dt>A comment token</dt>
                   4490:    <dd>
                   4491:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4492:     node</a> with the <code title="">data</code> attribute set to
                   4493:     the data given in the comment token.</p>
                   4494:    </dd>
                   4495: 
                   4496:    <dt>A DOCTYPE token</dt>
                   4497:    <dd>
                   4498:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4499:    </dd>
                   4500: 
                   4501:    <dt>A start tag whose tag name is "html"</dt>
                   4502:    <dd>
                   4503:     <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
                   4504:     mode</a>.</p>
                   4505:    </dd>
                   4506: 
                   4507:    <dt>A start tag whose tag name is "body"</dt>
                   4508:    <dd>
                   4509: 
                   4510:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4511: 
                   4512:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4513: 
                   4514:     <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>
                   4515: 
                   4516:    </dd>
                   4517: 
                   4518:    <dt>A start tag whose tag name is "frameset"</dt>
                   4519:    <dd>
                   4520: 
                   4521:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4522: 
                   4523:     <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>
                   4524: 
                   4525:    </dd>
                   4526: 
                   4527:    <dt>A start tag token whose tag name is one of: "base", "link",
                   4528:    "meta", "noframes", "script", "style", "title"</dt>
                   4529:    <dd>
                   4530: 
                   4531:     <p><a href="#parse-error">Parse error</a>.</p>
                   4532: 
                   4533:     <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
                   4534:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4535: 
                   4536:     <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
                   4537:     mode</a>.</p>
                   4538: 
                   4539:     <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
                   4540:     of open elements</a>.</p>
                   4541: 
                   4542:     <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
                   4543:     pointer</a> cannot be null at this point.</p>
                   4544: 
                   4545:    </dd>
                   4546: 
                   4547:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4548:    <dd>
                   4549:     <p>Act as described in the "anything else" entry below.</p>
                   4550:    </dd>
                   4551: 
                   4552:    <dt>A start tag whose tag name is "head"</dt>
                   4553:    <dt>Any other end tag</dt>
                   4554:    <dd>
                   4555:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4556:    </dd>
                   4557: 
                   4558:    <dt>Anything else</dt>
                   4559:    <dd>
                   4560:     <p>Act as if a start tag token with the tag name "body" and no
                   4561:     attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
                   4562:     flag</a> back to "ok", and then reprocess the current
                   4563:     token.</p>
                   4564:    </dd>
                   4565: 
                   4566:   </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>
                   4567: 
                   4568:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
                   4569:   mode: in body">in body</a>", tokens must be handled as follows:</p>
                   4570: 
                   4571:   <dl class="switch"><dt>A character token</dt>
                   4572:    <dd>
                   4573: 
                   4574:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4575:     any.</p>
                   4576: 
                   4577:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   4578:     character</a> into the <a href="#current-node">current node</a>.</p>
                   4579: 
                   4580:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   4581:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   4582:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   4583:     flag</a> to "not ok".</p>
                   4584: 
                   4585:    </dd>
                   4586: 
                   4587:    <dt>A comment token</dt>
                   4588:    <dd>
                   4589:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4590:     node</a> with the <code title="">data</code> attribute set to
                   4591:     the data given in the comment token.</p>
                   4592:    </dd>
                   4593: 
                   4594:    <dt>A DOCTYPE token</dt>
                   4595:    <dd>
                   4596:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4597:    </dd>
                   4598: 
                   4599:    <dt>A start tag whose tag name is "html"</dt>
                   4600:    <dd>
                   4601:     <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
                   4602:     check to see if the attribute is already present on the top
                   4603:     element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
                   4604:     add the attribute and its corresponding value to that element.</p>
                   4605:    </dd>
                   4606: 
                   4607:    <dt>A start tag token whose tag name is one of: "base", "command",
                   4608:    "link", "meta", "noframes", "script", "style", "title"</dt>
                   4609:    <dd>
                   4610:     <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
                   4611:     mode</a>.</p>
                   4612:    </dd>
                   4613: 
                   4614:    <dt>A start tag whose tag name is "body"</dt>
                   4615:    <dd>
                   4616: 
                   4617:     <p><a href="#parse-error">Parse error</a>.</p>
                   4618: 
                   4619:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159     mike     4620:     elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1       mike     4621:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4622:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4623: 
                   4624:     <p>Otherwise, for each attribute on the token, check to see if
1.159     mike     4625:     the attribute is already present on the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1       mike     4626:     element (the second element) on the <a href="#stack-of-open-elements">stack of open
                   4627:     elements</a>. If it is not, add the attribute and its
                   4628:     corresponding value to that element.</p>
                   4629: 
                   4630:    </dd>
                   4631: 
                   4632:    <dt>A start tag whose tag name is "frameset"</dt>
                   4633:    <dd>
                   4634: 
                   4635:     <p><a href="#parse-error">Parse error</a>.</p>
                   4636: 
                   4637:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159     mike     4638:     elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1       mike     4639:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4640:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4641: 
                   4642:     <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
                   4643:     the token.</p>
                   4644: 
                   4645:     <p>Otherwise, run the following steps:</p>
                   4646: 
                   4647:     <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
                   4648:      elements</a> from its parent node, if it has one.</p></li>
                   4649: 
                   4650:      <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
                   4651:      open elements</a>, from the <a href="#current-node">current node</a> up to,
1.159     mike     4652:      but not including, the root <code><a href="semantics.html#the-html-element-0">html</a></code> element.</p>
1.1       mike     4653: 
                   4654:      </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   4655:      token.</p></li>
                   4656: 
                   4657:      <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>
                   4658: 
                   4659:     </li></ol></dd>
                   4660: 
                   4661:    <dt>An end-of-file token</dt>
                   4662:    <dd>
                   4663: 
                   4664:     <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
1.422     mike     4665:     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>
                   4666:     element, an <code><a href="semantics.html#the-li-element">li</a></code> element, a <code><a href="semantics.html#the-p-element">p</a></code> element, a
1.1       mike     4667:     <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
                   4668:     <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
                   4669:     <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     4670:     <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     4671:     this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
1.422     mike     4672:     fragment cases) -->
1.1       mike     4673: 
                   4674:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   4675: 
                   4676:    </dd>
                   4677: 
                   4678:    <dt>An end tag whose tag name is "body"</dt>
                   4679:    <dd>
                   4680: 
                   4681:     <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
                   4682:     in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
                   4683:     token.</p>
                   4684: 
                   4685:     <!-- if we get here, the insertion mode here is forcibly "in
                   4686:     body". -->
                   4687: 
                   4688:     <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
1.422     mike     4689:     elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
1.1       mike     4690:     <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
                   4691:     <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
                   4692:     <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
                   4693:     <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
                   4694:     <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
                   4695:     <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     4696:     <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
                   4697:     <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     4698:     error</a>.</p> <!-- (some of those are fragment cases, e.g. for
                   4699:     <tbody> you'd have hit the first paragraph since the <body>
1.422     mike     4700:     wouldn't be in scope, unless it was a fragment case) -->
1.1       mike     4701: 
                   4702:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   4703:     then we'd have to somehow keep track of its state when we switch
                   4704:     to after-body. -->
                   4705: 
                   4706:     <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>
                   4707: 
                   4708:    </dd>
                   4709: 
                   4710:    <dt>An end tag whose tag name is "html"</dt>
                   4711:    <dd>
                   4712: 
                   4713:     <p>Act as if an end tag with tag name "body" had been seen,
                   4714:     then, if that token wasn't ignored, reprocess the current
                   4715:     token.</p>
                   4716: 
                   4717:     <p class="note">The fake end tag token here can only be
                   4718:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   4719: 
                   4720:    </dd>
                   4721: 
                   4722:    <!-- start tags for non-phrasing flow content elements -->
                   4723: 
                   4724:    <!-- the normal ones -->
                   4725:    <dt>A start tag whose tag name is one of: "address", "article",
1.86      mike     4726:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305     mike     4727:    "details", "dir", "div", "dl", "fieldset", "figure", "footer",
                   4728:    "header", "hgroup", "menu", "nav", "ol", "p", "section", "ul"</dt>
1.1       mike     4729:    <dd>
                   4730: 
                   4731:     <!-- As of May 2008 this doesn't match any browser exactly, but is
                   4732:     as close to what IE does as I can get without doing the non-tree
                   4733:     DOM nonsense, and thus should actually afford better compatibility
                   4734:     when implemented by the other browsers. -->
                   4735: 
                   4736:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4737:     an element in scope">has a <code>p</code> element in
                   4738:     scope</a>, then act as if an end tag with the tag name
                   4739:     "p" had been seen.</p>
                   4740: 
                   4741:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4742: 
                   4743:    </dd>
                   4744: 
                   4745:    <!-- as normal, but close h1-h6 if it's the current node -->
                   4746:    <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
                   4747:    "h5", "h6"</dt>
                   4748:    <dd>
                   4749: 
                   4750:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4751:     an element in scope">has a <code>p</code> element in
                   4752:     scope</a>, then act as if an end tag with the tag name
                   4753:     "p" had been seen.</p>
                   4754: 
                   4755:     <p>If the <a href="#current-node">current node</a> is an element whose tag name
                   4756:     is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
                   4757:     <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
                   4758:     the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4759:     <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
                   4760: 
                   4761:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4762: 
                   4763:    </dd>
                   4764: 
                   4765:    <!-- as normal, but drops leading newline -->
                   4766:    <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
                   4767:    <dd>
                   4768: 
                   4769:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4770:     an element in scope">has a <code>p</code> element in
                   4771:     scope</a>, then act as if an end tag with the tag name
                   4772:     "p" had been seen.</p>
                   4773: 
                   4774:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4775: 
                   4776:     <p>If the next token is a U+000A LINE FEED (LF) character
                   4777:     token, then ignore that token and move on to the next
                   4778:     one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
                   4779:     ignored as an authoring convenience.)</p>
                   4780: 
                   4781:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4782: 
                   4783:    </dd>
                   4784: 
                   4785:    <!-- as normal, but interacts with the form element pointer -->
                   4786:    <dt>A start tag whose tag name is "form"</dt>
                   4787:    <dd>
                   4788: 
                   4789:     <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
                   4790:     pointer</a> is not null, then this is a <a href="#parse-error">parse
                   4791:     error</a>; ignore the token.</p>
                   4792: 
                   4793:     <p>Otherwise:</p>
                   4794: 
                   4795:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4796:     an element in scope">has a <code>p</code> element in
                   4797:     scope</a>, then act as if an end tag with the tag name
                   4798:     "p" had been seen.</p>
                   4799: 
                   4800:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
                   4801:     <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
                   4802:     point to the element created.</p>
                   4803: 
                   4804:    </dd>
                   4805: 
                   4806:    <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
                   4807:    <dt>A start tag whose tag name is "li"</dt>
                   4808:    <dd>
                   4809: 
                   4810:     <p>Run the following algorithm:</p>
                   4811: 
                   4812:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4813: 
                   4814:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4815:      node</a> (the bottommost node of the stack).</p></li>
                   4816: 
                   4817:      <li><p>If <var title="">node</var> is an <code><a href="semantics.html#the-li-element">li</a></code> element,
                   4818:      then act as if an end tag with the tag name "li" had
                   4819:      been seen, then jump to the last step.</p></li>
                   4820: 
                   4821:      <li><p><i>Loop</i>: If <var title="">node</var> is not in the
                   4822:      <a href="#formatting">formatting</a> category, and is not in the
                   4823:      <a href="#phrasing">phrasing</a> category, and is not an
1.306     mike     4824:      <code><a href="semantics.html#the-address-element">address</a></code>, <code><a href="semantics.html#the-div-element">div</a></code>, or <code><a href="semantics.html#the-p-element">p</a></code>
1.1       mike     4825:      element, then jump to the last step.</p></li> <!-- an element
                   4826:      <foo> is in this list if the following markup:
                   4827: 
                   4828:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
                   4829: 
                   4830:      ...results in the second <li> not being (in any way) a descendant
                   4831:      of the first <li>, or if <foo> is a formatting element that gets
                   4832:      reopened later. -->
                   4833: 
                   4834:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4835:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4836:      the step labeled <i>loop</i>.</p></li>
                   4837: 
                   4838:      <li>
                   4839: 
                   4840:       <p>This is the last step.</p>
                   4841: 
                   4842:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4843:       an element in scope">has a <code>p</code> element in
                   4844:       scope</a>, then act as if an end tag with the tag name
                   4845:       "p" had been seen.</p>
                   4846: 
                   4847:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4848:       token.</p>
                   4849: 
                   4850:      </li>
                   4851: 
                   4852:     </ol></dd>
                   4853: 
                   4854:    <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases  -->
1.422     mike     4855:    <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
1.1       mike     4856:    <dd>
                   4857: 
                   4858:     <p>Run the following algorithm:</p>
                   4859: 
                   4860:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4861: 
                   4862:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4863:      node</a> (the bottommost node of the stack).</p></li>
                   4864: 
                   4865:      <li><p><i>Loop</i>: If <var title="">node</var> is a
1.422     mike     4866:      <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
                   4867:      tag with the same tag name as <var title="">node</var> had been
                   4868:      seen, then jump to the last step.</p></li>
1.1       mike     4869: 
                   4870:      <li><p>If <var title="">node</var> is not in the
                   4871:      <a href="#formatting">formatting</a> category, and is not in the
                   4872:      <a href="#phrasing">phrasing</a> category, and is not an
1.306     mike     4873:      <code><a href="semantics.html#the-address-element">address</a></code>, <code><a href="semantics.html#the-div-element">div</a></code>, or <code><a href="semantics.html#the-p-element">p</a></code>
1.1       mike     4874:      element, then jump to the last step.</p></li> <!-- an element
                   4875:      <foo> is in this list if the following markup:
                   4876: 
                   4877:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
                   4878: 
                   4879:      ...results in the second <dt> not being (in any way) a descendant
                   4880:      of the first <dt>, or if <foo> is a formatting element that gets
                   4881:      reopened later. -->
                   4882: 
                   4883:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4884:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4885:      the step labeled <i>loop</i>.</p></li>
                   4886: 
                   4887:      <li>
                   4888: 
                   4889:       <p>This is the last step.</p>
                   4890: 
                   4891:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4892:       an element in scope">has a <code>p</code> element in
                   4893:       scope</a>, then act as if an end tag with the tag name
                   4894:       "p" had been seen.</p>
                   4895: 
                   4896:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4897:       token.</p>
                   4898: 
                   4899:      </li>
                   4900: 
                   4901:     </ol></dd>
                   4902: 
                   4903:    <!-- same as normal, but effectively ends parsing -->
                   4904:    <dt>A start tag whose tag name is "plaintext"</dt>
                   4905:    <dd>
                   4906: 
                   4907:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4908:     an element in scope">has a <code>p</code> element in
                   4909:     scope</a>, then act as if an end tag with the tag name
                   4910:     "p" had been seen.</p>
                   4911: 
                   4912:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4913: 
                   4914:     <p>Switch the <a href="#content-model-flag">content model flag</a> to the PLAINTEXT
                   4915:     state.</p>
                   4916: 
                   4917:     <p class="note">Once a start tag with the tag name "plaintext"
                   4918:     has been seen, that will be the last token ever seen other
                   4919:     than character tokens (and the end-of-file token), because
                   4920:     there is no way to switch the <a href="#content-model-flag">content model flag</a>
                   4921:     out of the PLAINTEXT state.</p>
                   4922: 
                   4923:    </dd>
                   4924: 
                   4925:    <!-- end tags for non-phrasing flow content elements -->
                   4926: 
                   4927:    <!-- the normal ones -->
                   4928:    <dt>An end tag whose tag name is one of: "address", "article",
1.86      mike     4929:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305     mike     4930:    "details", "dir", "div", "dl", "fieldset", "figure", "footer",
                   4931:    "header", "hgroup", "listing", "menu", "nav", "ol", "pre",
                   4932:    "section", "ul"</dt>
1.1       mike     4933:    <dd>
                   4934: 
                   4935:     <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>
                   4936:     with the same tag name as that of the token, then this is a
                   4937:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4938: 
                   4939:     <p>Otherwise, run these steps:</p>
                   4940: 
                   4941:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4942: 
                   4943:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4944:      the same tag name as that of the token, then this is a
                   4945:      <a href="#parse-error">parse error</a>.</p></li>
                   4946: 
                   4947:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4948:      until an element with the same tag name as the token has been
                   4949:      popped from the stack.</p></li>
                   4950: 
                   4951:     </ol></dd>
                   4952: 
                   4953:    <!-- removes the form element pointer instead of the matching node -->
                   4954:    <dt>An end tag whose tag name is "form"</dt>
                   4955:    <dd>
                   4956: 
                   4957:     <p>Let <var title="">node</var> be the element that the
                   4958:     <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
                   4959:     to.</p>
                   4960: 
                   4961:     <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   4962:     to null.</p>
                   4963: 
                   4964:     <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
                   4965:     elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
                   4966:     scope">have <var title="">node</var> in scope</a>, then this is
                   4967:     a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4968: 
                   4969:     <p>Otherwise, run these steps:</p>
                   4970: 
                   4971:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4972: 
                   4973:      <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
                   4974:      error</a>.</p></li>
                   4975: 
                   4976:      <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
                   4977:      open elements</a>.</p></li>
                   4978: 
                   4979:     </ol></dd>
                   4980: 
                   4981:    <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
                   4982:    <dt>An end tag whose tag name is "p"</dt>
                   4983:    <dd>
                   4984: 
                   4985:     <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>
                   4986:     with the same tag name as that of the token, then this is a
                   4987:     <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
                   4988:     "p" had been seen, then reprocess the current token.</p>
                   4989: 
                   4990:     <p>Otherwise, run these steps:</p>
                   4991: 
                   4992:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4993:      for elements with the same tag name as the token.</p></li>
                   4994: 
                   4995:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4996:      the same tag name as that of the token, then this is a
                   4997:      <a href="#parse-error">parse error</a>.</p></li>
                   4998: 
                   4999:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   5000:      until an element with the same tag name as the token has been
                   5001:      popped from the stack.</p></li>
                   5002: 
                   5003:     </ol></dd>
                   5004: 
1.234     mike     5005:    <!-- as normal, but needs care as the elements have optional tags, and are further scoped by <ol>/<ul> -->
                   5006:    <dt>An end tag whose tag name is "li"</dt>
                   5007:    <dd>
                   5008: 
                   5009:     <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
                   5010:     item scope</a> with the same tag name as that of the token,
                   5011:     then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   5012: 
                   5013:     <p>Otherwise, run these steps:</p>
                   5014: 
                   5015:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   5016:      for elements with the same tag name as the token.</p></li>
                   5017: 
                   5018:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   5019:      the same tag name as that of the token, then this is a
                   5020:      <a href="#parse-error">parse error</a>.</p></li>
                   5021: 
                   5022:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   5023:      until an element with the same tag name as the token has been
                   5024:      popped from the stack.</p></li>
                   5025: 
                   5026:     </ol></dd>
                   5027: 
1.1       mike     5028:    <!-- as normal, but needs care as the elements have optional tags -->
1.422     mike     5029:    <dt>An end tag whose tag name is one of: "dd", "dt"</dt>
1.1       mike     5030:    <dd>
                   5031: 
                   5032:     <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>
                   5033:     with the same tag name as that of the token, then this is a
                   5034:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   5035: 
                   5036:     <p>Otherwise, run these steps:</p>
                   5037: 
                   5038:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   5039:      for elements with the same tag name as the token.</p></li>
                   5040: 
                   5041:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   5042:      the same tag name as that of the token, then this is a
                   5043:      <a href="#parse-error">parse error</a>.</p></li>
                   5044: 
                   5045:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   5046:      until an element with the same tag name as the token has been
                   5047:      popped from the stack.</p></li>
                   5048: 
                   5049:     </ol></dd>
                   5050: 
                   5051:    <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
                   5052:    <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</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:     whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
                   5057:     then this is a <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 whose tag name is one of "h1", "h2", "h3", "h4",
                   5069:      "h5", or "h6" has been popped from the stack.</p></li>
                   5070: 
                   5071:     </ol></dd>
                   5072: 
                   5073:    <dt>An end tag whose tag name is "sarcasm"</dt>
                   5074:    <dd>
                   5075:     <p>Take a deep breath, then act as described in the "any other end
                   5076:     tag" entry below.</p>
                   5077:    </dd>
                   5078: 
                   5079:    <!-- ADOPTION AGENCY ELEMENTS
                   5080:         Mozilla-only: bdo blink del ins sub sup q
                   5081:         Safari-only: code dfn kbd nobr samp var wbr
                   5082:         Both: a b big em font i s small strike strong tt u -->
                   5083: 
                   5084:    <dt>A start tag whose tag name is "a"</dt>
                   5085:    <dd>
                   5086: 
                   5087:     <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
                   5088:     contains an element whose tag name is "a" between the end of
                   5089:     the list and the last marker on the list (or the start of the
                   5090:     list if there is no marker on the list), then this is a
                   5091:     <a href="#parse-error">parse error</a>; act as if an end tag with the tag
                   5092:     name "a" had been seen, then remove that element from the
                   5093:     <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
                   5094:     <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
                   5095:     already remove it (it might not have if the element is not
                   5096:     <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
                   5097:     scope</a>).</p>
                   5098: 
                   5099:     <p class="example">In the non-conforming stream
                   5100:     <code>&lt;a&#160;href="a"&gt;a&lt;table&gt;&lt;a&#160;href="b"&gt;b&lt;/table&gt;x</code>,
                   5101:     the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
                   5102:     the second one, and the "x" character would be inside a link
                   5103:     to "b", not to "a". This is despite the fact that the outer
                   5104:     <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
                   5105:     regular <code>&lt;/a&gt;</code> end tag at the start of the table
                   5106:     wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
                   5107: 
                   5108:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5109:     any.</p>
                   5110: 
                   5111:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   5112:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   5113:     elements</a>.</p>
                   5114: 
                   5115:    </dd>
                   5116: 
                   5117:    <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
                   5118:    "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
                   5119:    <dd>
                   5120: 
                   5121:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5122:     any.</p>
                   5123: 
                   5124:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   5125:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   5126:     elements</a>.</p>
                   5127: 
                   5128:    </dd>
                   5129: 
                   5130:    <dt>A start tag whose tag name is "nobr"</dt>
                   5131:    <dd>
                   5132: 
                   5133:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5134:     any.</p>
                   5135: 
                   5136:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5137:     element in scope">has a <code>nobr</code> element in scope</a>,
                   5138:     then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
                   5139:     the tag name "nobr" had been seen, then once again
                   5140:     <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
                   5141:     any.</p>
                   5142: 
                   5143:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   5144:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   5145:     elements</a>.</p>
                   5146: 
                   5147:    </dd>
                   5148: 
                   5149:    <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
                   5150:    "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
                   5151:    "strike", "strong", "tt", "u"</dt>
                   5152:    <dd>
                   5153: 
                   5154:     <p>Follow these steps:</p>
                   5155: 
                   5156:     <ol><li>
                   5157: 
                   5158:       <p>Let the <var title="">formatting element</var> be the
                   5159:       last element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   5160:       elements</a> that:</p>
                   5161: 
                   5162:       <ul><li>is between the end of the list and the last scope
                   5163:        marker in the list, if any, or the start of the list
                   5164:        otherwise, and</li>
                   5165: 
                   5166:        <li>has the same tag name as the token.</li>
                   5167: 
                   5168:       </ul><p>If there is no such node, or, if that node is also in the
                   5169:       <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
                   5170:       <a href="#parse-error">parse error</a>; ignore the token, and abort these
                   5171:       steps.</p>
                   5172: 
                   5173:       <p>Otherwise, if there is such a node, but that node is not
                   5174:       in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
                   5175:       <a href="#parse-error">parse error</a>; remove the element from the list,
                   5176:       and abort these steps.</p>
                   5177: 
                   5178:       <p>Otherwise, there is a <var title="">formatting
                   5179:       element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
                   5180:       open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
                   5181:       element in scope">in scope</a>. If the element is not the
                   5182:       <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
                   5183:       error</a>. In any case, proceed with the algorithm as
                   5184:       written in the following steps.</p>
                   5185: 
                   5186:      </li>
                   5187: 
                   5188:      <li><p>Let the <var title="">furthest block</var> be the
                   5189:      topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
                   5190:      is lower in the stack than the <var title="">formatting
                   5191:      element</var>, and is not an element in the
                   5192:      <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
                   5193:      categories. There might not be one.</p></li>
                   5194: 
                   5195:      <li><p>If there is no <var title="">furthest block</var>,
                   5196:      then the UA must skip the subsequent steps and instead just
                   5197:      pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
                   5198:      elements</a>, from the <a href="#current-node">current node</a> up to and
                   5199:      including the <var title="">formatting element</var>, and
                   5200:      remove the <var title="">formatting element</var> from the
                   5201:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
                   5202: 
                   5203:      <li><p>Let the <var title="">common ancestor</var> be the element
                   5204:      immediately above the <var title="">formatting element</var> in the
                   5205:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   5206: 
                   5207:      <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
                   5208:      formatting elements</a> relative to the elements on either
                   5209:      side of it in the list.</p></li>
                   5210: 
                   5211:      <li>
                   5212: 
                   5213:       <p>Let <var title="">node</var> and <var title="">last node</var> be the
                   5214:       <var title="">furthest block</var>. Follow these steps:</p>
                   5215: 
                   5216:       <ol><li>Let <var title="">node</var> be the element immediately
                   5217:        above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
1.436     mike     5218:        elements</a>, or if <var title="">node</var> is no longer in
                   5219:        the <a href="#stack-of-open-elements">stack of open elements</a> (e.g. because it got
                   5220:        removed by the next step), the element that was immediately
                   5221:        above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
                   5222:        elements</a> before <var title="">node</var> was
                   5223:        removed.</li>
1.1       mike     5224: 
                   5225:        <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
                   5226:        active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
                   5227:        elements</a> and then go back to step 1.</li>
                   5228: 
                   5229:        <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
                   5230:        in the overall algorithm.</li>
                   5231: 
                   5232:        <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
                   5233:        bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   5234:        elements</a>.</li>
                   5235: 
                   5236:        <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   5237:        element <var title="">node</var> was created, replace the entry
                   5238:        for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
                   5239:        formatting elements</a> with an entry for the new element,
                   5240:        replace the entry for <var title="">node</var> in the
                   5241:        <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
                   5242:        element, and let <var title="">node</var> be the new
                   5243:        element.</li>
                   5244: 
                   5245:        <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
                   5246:        parent node if any.</li>
                   5247: 
                   5248:        <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
                   5249: 
                   5250:        <li>Return to step 1 of this inner set of steps.</li>
                   5251: 
                   5252:       </ol></li>
                   5253: 
                   5254:      <li>
                   5255: 
                   5256:       <p>If the <var title="">common ancestor</var> node is a
                   5257:       <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>,
                   5258:       <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,
                   5259:       <a href="#foster-parent">foster parent</a> whatever <var title="">last
                   5260:       node</var> ended up being in the previous step, first removing
                   5261:       it from its previous parent node if any.</p>
                   5262: 
                   5263:       <p>Otherwise, append whatever <var title="">last node</var>
                   5264:       ended up being in the previous step to the <var title="">common
                   5265:       ancestor</var> node, first removing it from its previous parent
                   5266:       node if any.</p>
                   5267: 
                   5268:      </li>
                   5269: 
                   5270:      <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   5271:      <var title="">formatting element</var> was created.</p></li>
                   5272: 
                   5273:      <li><p>Take all of the child nodes of the <var title="">furthest
                   5274:      block</var> and append them to the element created in the last
                   5275:      step.</p></li>
                   5276: 
                   5277:      <li><p>Append that new element to the <var title="">furthest
                   5278:      block</var>.</p></li>
                   5279: 
                   5280:      <li><p>Remove the <var title="">formatting element</var> from the
                   5281:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
                   5282:      new element into the <a href="#list-of-active-formatting-elements">list of active formatting
                   5283:      elements</a> at the position of the aforementioned
                   5284:      bookmark.</p></li>
                   5285: 
                   5286:      <li><p>Remove the <var title="">formatting element</var> from the
                   5287:      <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
                   5288:      into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
                   5289:      the position of the <var title="">furthest block</var> in that
                   5290:      stack.</p></li>
                   5291: 
                   5292:      <li><p>Jump back to step 1 in this series of steps.</p></li>
                   5293: 
1.334     mike     5294:     </ol><p class="note">Because of the way this algorithm causes elements
1.304     mike     5295:     to change parents, it has been dubbed the "adoption agency
                   5296:     algorithm" (in contrast with other possible algorithms for dealing
                   5297:     with misnested content, which included the "incest algorithm", the
1.1       mike     5298:     "secret affair algorithm", and the "Heisenberg algorithm").</p>
                   5299: 
                   5300:    </dd>
                   5301: 
                   5302:    <dt>A start tag whose tag name is "button"</dt>
                   5303:    <dd>
                   5304: 
                   5305:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5306:     an element in scope">has a <code>button</code> element in
                   5307:     scope</a>, then this is a <a href="#parse-error">parse error</a>;
                   5308:     act as if an end tag with the tag name "button" had been seen,
                   5309:     then reprocess the token.</p>
                   5310: 
                   5311:     <p>Otherwise:</p>
                   5312: 
                   5313:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5314:     any.</p>
                   5315: 
                   5316:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5317: 
                   5318:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5319:     formatting elements</a>.</p>
                   5320: 
                   5321:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5322: 
                   5323:    </dd>
                   5324: 
                   5325:    <dt>A start tag token whose tag name is one of: "applet",
                   5326:    "marquee", "object"</dt>
                   5327:    <dd>
                   5328: 
                   5329:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5330:     any.</p>
                   5331: 
                   5332:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5333: 
                   5334:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5335:     formatting elements</a>.</p>
                   5336: 
                   5337:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5338: 
                   5339:    </dd>
                   5340: 
                   5341:    <dt>An end tag token whose tag name is one of: "applet", "button",
                   5342:    "marquee", "object"</dt>
                   5343:    <dd>
                   5344: 
                   5345:     <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>
                   5346:     with the same tag name as that of the token, then this is a
                   5347:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   5348: 
                   5349:     <p>Otherwise, run these steps:</p>
                   5350: 
                   5351:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5352: 
                   5353:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   5354:      the same tag name as that of the token, then this is a
                   5355:      <a href="#parse-error">parse error</a>.</p></li>
                   5356: 
                   5357:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   5358:      until an element with the same tag name as the token has been
                   5359:      popped from the stack.</p></li>
                   5360: 
                   5361:      <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
                   5362:      last marker</a>.</li>
                   5363: 
                   5364:     </ol></dd>
                   5365: 
                   5366:    <dt>A start tag whose tag name is "table"</dt>
                   5367:    <dd>
                   5368: 
                   5369:     <p>If the <code>Document</code> is <em>not</em> set to
                   5370:     <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
                   5371:     elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
                   5372:     <code>p</code> element in scope</a>, then act as if an end tag
                   5373:     with the tag name "p" had been seen.</p> <!-- i hate myself (this
                   5374:     quirk was basically caused by acid2; if i'd realised we could
                   5375:     change the specs when i wrote acid2, we could have avoided having
                   5376:     any parsing-mode quirks) -Hixie -->
                   5377: 
                   5378:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5379: 
                   5380:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5381: 
                   5382:     <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>
                   5383: 
                   5384:    </dd>
                   5385: 
                   5386:    <dt>A start tag whose tag name is one of: "area", "basefont",
                   5387:    "bgsound", "br", "embed", "img", "input", "keygen", "spacer",
                   5388:    "wbr"</dt>
                   5389:    <dd>
                   5390: 
                   5391:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5392:     any.</p>
                   5393: 
                   5394:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5395:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5396:     elements</a>.</p>
                   5397: 
                   5398:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5399:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5400: 
                   5401:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
                   5402:     shouldn't really do it for <area>, <basefont>, <bgsound>, and
                   5403:     <spacer> -->
                   5404: 
                   5405:    </dd>
                   5406: 
                   5407:    <dt>A start tag whose tag name is one of: "param", "source"</dt>
                   5408:    <dd>
                   5409: 
                   5410:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5411:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5412:     elements</a>.</p>
                   5413: 
                   5414:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5415:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5416: 
                   5417:    </dd>
                   5418: 
                   5419:    <dt>A start tag whose tag name is "hr"</dt>
                   5420:    <dd>
                   5421: 
                   5422:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5423:     an element in scope">has a <code>p</code> element in
                   5424:     scope</a>, then act as if an end tag with the tag name
                   5425:     "p" had been seen.</p>
                   5426: 
                   5427:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5428:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5429:     elements</a>.</p>
                   5430: 
                   5431:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5432:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5433: 
                   5434:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5435: 
                   5436:    </dd>
                   5437: 
                   5438:    <dt>A start tag whose tag name is "image"</dt>
                   5439:    <dd>
                   5440:     <p><a href="#parse-error">Parse error</a>. Change the token's tag name
                   5441:     to "img" and reprocess it. (Don't ask.)</p> <!-- As of
                   5442:     2005-12, studies showed that around 0.2% of pages used the
                   5443:     <image> element. -->
                   5444:    </dd>
                   5445: 
                   5446:    <dt id="isindex">A start tag whose tag name is "isindex"</dt>
                   5447:    <dd>
                   5448: 
                   5449:     <p><a href="#parse-error">Parse error</a>.</p>
                   5450: 
                   5451:     <p>If the <a href="#form-element-pointer"><code title="">form</code> element
                   5452:     pointer</a> is not null, then ignore the token.</p>
                   5453: 
                   5454:     <p>Otherwise:</p>
                   5455: 
                   5456:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5457:     token's <i>self-closing flag</i></a>, if it is set.</p> <!--
                   5458:     purely to reduce the number of errors (we don't care if they
                   5459:     included the /, they're not supposed to be including the tag at
                   5460:     all! -->
                   5461: 
                   5462:     <p>Act as if a start tag token with the tag name "form" had been seen.</p>
                   5463: 
                   5464:     <p>If the token has an attribute called "action", set the
                   5465:     <code title="attr-form-action">action</code> attribute on the
                   5466:     resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
                   5467:     "action" attribute of the token.</p>
                   5468: 
                   5469:     <p>Act as if a start tag token with the tag name "hr" had been
                   5470:     seen.</p>
                   5471: 
                   5472:     <p>Act as if a start tag token with the tag name "label" had been
                   5473:     seen.</p>
                   5474: 
                   5475:     <p>Act as if a stream of character tokens had been seen (see below
                   5476:     for what they should say).</p>
                   5477: 
                   5478:     <p>Act as if a start tag token with the tag name "input" had been
                   5479:     seen, with all the attributes from the "isindex" token except
                   5480:     "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
                   5481:     <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
                   5482: 
                   5483:     <p>Act as if a stream of character tokens had been seen (see
                   5484:     below for what they should say).</p>
                   5485: 
                   5486:     <p>Act as if an end tag token with the tag name "label" had been
                   5487:     seen.</p>
                   5488: 
                   5489:     <p>Act as if a start tag token with the tag name "hr" had been
                   5490:     seen.</p>
                   5491: 
                   5492:     <p>Act as if an end tag token with the tag name "form" had been
                   5493:     seen.</p>
                   5494: 
                   5495:     <p>If the token has an attribute with the name "prompt", then the
                   5496:     first stream of characters must be the same string as given in
                   5497:     that attribute, and the second stream of characters must be
                   5498:     empty. Otherwise, the two streams of character tokens together
                   5499:     should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
                   5500:     equivalent of "This is a searchable index. Insert your search
                   5501:     keywords here: (input field)" in the user's preferred
                   5502:     language.</p>
                   5503: 
                   5504:    </dd>
                   5505: 
                   5506:    <dt>A start tag whose tag name is "textarea"</dt>
                   5507:    <dd>
                   5508: 
                   5509:     <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   5510:      token.</p></li>
                   5511: 
                   5512:      <li><p>If the next token is a U+000A LINE FEED (LF) character
                   5513:      token, then ignore that token and move on to the next
                   5514:      one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
                   5515:      ignored as an authoring convenience.)</p></li>
                   5516: 
                   5517:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
                   5518:      the RCDATA state.</p></li>
                   5519: 
                   5520:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
                   5521:      current <a href="#insertion-mode">insertion mode</a>.</p>
                   5522: 
                   5523:      </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
                   5524:      ok".</p></li>
                   5525: 
1.91      mike     5526:      <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
                   5527:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     5528: 
                   5529:     </ol></dd>
                   5530: 
                   5531:    <dt>A start tag whose tag name is "xmp"</dt>
                   5532:    <dd>
                   5533: 
1.233     mike     5534:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5535:     an element in scope">has a <code>p</code> element in
                   5536:     scope</a>, then act as if an end tag with the tag name
                   5537:     "p" had been seen.</p>
                   5538: 
1.1       mike     5539:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5540:     any.</p>
                   5541: 
                   5542:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5543: 
1.91      mike     5544:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5545: 
                   5546:    </dd>
                   5547: 
                   5548:    <dt>A start tag whose tag name is "iframe"</dt>
                   5549:    <dd>
                   5550: 
                   5551:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5552: 
1.91      mike     5553:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5554: 
                   5555:    </dd>
                   5556: 
                   5557:    <dt>A start tag whose tag name is "noembed"</dt>
                   5558:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   5559:    <dd>
                   5560: 
1.91      mike     5561:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5562: 
                   5563:    </dd>
                   5564: 
                   5565:    <dt>A start tag whose tag name is "select"</dt>
                   5566:    <dd>
                   5567: 
                   5568:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5569:     any.</p>
                   5570: 
                   5571:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5572: 
                   5573:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5574: 
                   5575:     <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>",
                   5576:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5577:     body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   5578:     row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   5579:     cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
                   5580:     "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
                   5581:     table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
                   5582:     to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
                   5583: 
                   5584:    </dd>
                   5585: 
                   5586:    <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
                   5587:    <dd>
                   5588: 
                   5589:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5590:     element in scope">has an <code>option</code> element in
                   5591:     scope</a>, then act as if an end tag with the tag name "option"
                   5592:     had been seen.</p>
                   5593: 
                   5594:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5595:     any.</p>
                   5596: 
                   5597:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5598: 
                   5599:    </dd>
                   5600: 
                   5601:    <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
                   5602:    <dd>
                   5603: 
                   5604:     <!-- the parsing rules for ruby really don't match IE much at all,
                   5605:          but in practice the markup used is very simple and so strict
                   5606:          compatibility with IE isn't required. For example, as defined
                   5607:          here we get very, very different behaviour than IE for
                   5608:          pathological cases like:
                   5609: 
                   5610:            <ruby><ol><li><p>a<rt>b
                   5611:            <ruby>a<rt>b<p>c
                   5612: 
                   5613:          But in practice most ruby markup falls into these cases:
                   5614: 
                   5615:            <ruby>a<rt>b</ruby>
                   5616:            <ruby>a<rp>b<rt>c<rp>d</ruby>
                   5617:            <ruby>a<rt>b</rt></ruby>
                   5618:            <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
                   5619: 
                   5620:     -->
                   5621: 
                   5622:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5623:     element in scope">has a <code>ruby</code> element in scope</a>,
                   5624:     then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
                   5625:     node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
                   5626:     <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
                   5627:     node</a> up to the node immediately before the bottommost
                   5628:     <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
                   5629:     elements</a>.</p>
                   5630: 
                   5631:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5632: 
                   5633:    </dd>
                   5634: 
                   5635:    <dt>An end tag whose tag name is "br"</dt>
                   5636:    <dd>
                   5637:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
                   5638:     the tag name "br" had been seen. Ignore the end tag token.</p>
                   5639:    </dd>
                   5640: 
                   5641:    <dt>A start tag whose tag name is "math"</dt>
                   5642:    <dd>
                   5643: 
                   5644:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5645:     any.</p>
                   5646: 
                   5647:     <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
                   5648:     fixes the case of MathML attributes that are not all
                   5649:     lowercase.)</p>
                   5650: 
                   5651:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5652:     fixes the use of namespaced attributes, in particular XLink.)</p>
                   5653: 
                   5654:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5655:     <a href="#mathml-namespace">MathML namespace</a>.</p>
                   5656: 
                   5657:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5658:     the following change would be implied, except we'd have to do it
                   5659:     even in the face of a self-closed tag:
                   5660:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5661:     -->
                   5662: 
                   5663:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5664:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5665:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5666:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5667: 
                   5668:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5669:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5670:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5671:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5672:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5673:     foreign content">in foreign content</a>".</p>
                   5674: 
                   5675:    </dd>
                   5676: 
                   5677:    <dt>A start tag whose tag name is "svg"</dt>
                   5678:    <dd>
                   5679: 
                   5680:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5681:     any.</p>
                   5682: 
                   5683:     <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
                   5684:     the case of SVG attributes that are not all lowercase.)</p>
                   5685: 
                   5686:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5687:     fixes the use of namespaced attributes, in particular XLink in
                   5688:     SVG.)</p>
                   5689: 
                   5690:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5691:     <a href="#svg-namespace">SVG namespace</a>.</p>
                   5692: 
                   5693:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5694:     the following change would be implied, except we'd have to do it
                   5695:     even in the face of a self-closed tag:
                   5696:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5697:     -->
                   5698: 
                   5699:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5700:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5701:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5702:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5703: 
                   5704:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5705:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5706:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5707:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5708:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5709:     foreign content">in foreign content</a>".</p>
                   5710: 
                   5711:    </dd>
                   5712: 
                   5713:    <dt>A start <!--or end--> tag whose tag name is one of: "caption",
                   5714:    "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
                   5715:    "thead", "tr"</dt>
                   5716:    <!--<dt>An end tag whose tag name is one of: "area", "base",
                   5717:    "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
                   5718:    "img", "input", "isindex", "keygen", "link", "meta", "noembed",
                   5719:    "noframes", "param", "script", "select", "source", "spacer",
                   5720:    "style", "table", "textarea", "title", "wbr"</dt>-->
                   5721:    <!--<dt>An end tag whose tag name is "noscript", if the
                   5722:    <span>scripting flag</span> is enabled</dt>-->
                   5723:    <dd>
                   5724:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5725:     <!-- end tags are commented out because since they can never end
                   5726:     up on the stack anyway, the default end tag clause will
                   5727:     automatically handle them. we don't want to have text in the spec
                   5728:     that is just an optimisation, as that detracts from the spec
                   5729:     itself -->
                   5730:    </dd>
                   5731: 
                   5732:    <dt>Any other start tag</dt>
                   5733:    <dd>
                   5734: 
                   5735:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5736:     any.</p>
                   5737: 
                   5738:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5739: 
                   5740:     <p class="note">This element will be a <a href="#phrasing">phrasing</a>
                   5741:     element.</p>
                   5742: 
                   5743:    </dd>
                   5744: 
                   5745:    <dt>Any other end tag</dt>
                   5746:    <dd>
                   5747: 
                   5748:     <p>Run the following steps:</p>
                   5749: 
                   5750:     <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   5751:      node</a> (the bottommost node of the stack).</p></li>
                   5752: 
                   5753:      <li><p>If <var title="">node</var> has the same tag name as
                   5754:      the end tag token, then:</p>
                   5755: 
                   5756:       <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5757: 
                   5758:        <li><p>If the tag name of the end tag token does not match
                   5759:        the tag name of the <a href="#current-node">current node</a>, this is a
                   5760:        <a href="#parse-error">parse error</a>.</p></li>
                   5761: 
                   5762:        <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
                   5763:        to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
                   5764: 
                   5765:       </ol></li>
                   5766: 
                   5767:      <li><p>Otherwise, if <var title="">node</var> is in neither the
                   5768:      <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
                   5769:      category, then this is a <a href="#parse-error">parse error</a>; ignore the
                   5770:      token, and abort these steps.</p></li>
                   5771: 
                   5772:      <li><p>Set <var title="">node</var> to the previous entry in the
                   5773:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   5774: 
                   5775:      <li><p>Return to step 2.</p></li>
                   5776: 
                   5777:     </ol></dd>
                   5778: 
1.91      mike     5779:   </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     5780: 
                   5781:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.91      mike     5782:   mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>", tokens must be
1.1       mike     5783:   handled as follows:</p>
                   5784: 
                   5785:   <dl class="switch"><dt>A character token</dt>
                   5786:    <dd>
                   5787: 
                   5788:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   5789:     character</a> into the <a href="#current-node">current node</a>.</p>
                   5790: 
                   5791:    </dd>
                   5792: 
                   5793:    <dt>An end-of-file token</dt>
                   5794:    <dd>
                   5795: 
                   5796:     <!-- can't be the fragment case -->
                   5797:     <p><a href="#parse-error">Parse error</a>.</p>
                   5798: 
                   5799:     <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
1.484     mike     5800:     element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-started">"already
                   5801:     started"</a>.</p>
1.1       mike     5802: 
                   5803:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5804:     elements</a>.</p>
                   5805: 
                   5806:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5807:     insertion mode</a> and reprocess the current token.</p>
                   5808: 
                   5809:    </dd>
                   5810: 
                   5811:    <dt>An end tag whose tag name is "script"</dt>
                   5812:    <dd>
                   5813: 
                   5814:     <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
                   5815:     (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
                   5816: 
                   5817:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5818:     elements</a>.</p>
                   5819: 
                   5820:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5821:     insertion mode</a>.</p>
                   5822: 
                   5823:     <p>Let the <var title="">old insertion point</var> have the
                   5824:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   5825:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   5826:     input character</a>.</p>
                   5827: 
                   5828:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5829:     one.</p>
                   5830: 
                   5831:     <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     5832:     which might cause <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters
1.1       mike     5833:     to be inserted into the tokenizer</a>, and might cause the
                   5834:     tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
                   5835: 
                   5836:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5837:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   5838:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5839: 
                   5840:     <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
                   5841:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   5842:     might be the "undefined" value.)</p>
                   5843: 
                   5844:     <p id="scriptTagParserResumes">At this stage, if there is a
1.484     mike     5845:     <a href="semantics.html#pending-parsing-blocking-script">pending parsing-blocking script</a>, then:</p>
1.1       mike     5846: 
                   5847:     <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
                   5848: 
                   5849:      <dd>
                   5850: 
                   5851:       <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
                   5852:       processing of any nested invocations of the tokenizer, yielding
                   5853:       control back to the caller. (Tokenization will resume when the
                   5854:       caller returns to the "outer" tree construction stage.)</p>
                   5855: 
                   5856:       <p class="note">The tree construction stage of this particular
                   5857:       parser is <a href="#nestedParsing">being called reentrantly</a>,
1.159     mike     5858:       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     5859: 
                   5860:      </dd>
                   5861: 
                   5862: 
                   5863:      <dt>Otherwise:</dt>
                   5864: 
                   5865:      <dd>
                   5866: 
                   5867:       <p>Follow these steps:</p>
                   5868: 
1.484     mike     5869:       <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-parsing-blocking-script">pending
                   5870:        parsing-blocking script</a>. There is no longer a <a href="semantics.html#pending-parsing-blocking-script">pending
                   5871:        parsing-blocking script</a>.</p></li>
                   5872: 
                   5873:        <li><p>Block the <a href="#tokenization" title="tokenization">tokenizer</a>
                   5874:        for this instance of the <a href="#html-parser">HTML parser</a>, such that
                   5875:        the <a href="browsers.html#event-loop">event loop</a> will not run <a href="browsers.html#concept-task" title="concept-task">tasks</a> that invoke the <a href="#tokenization" title="tokenization">tokenizer</a>.</p></li>
                   5876: 
                   5877:        <li><p><a href="browsers.html#spin-the-event-loop">Spin the event loop</a> until there is no <a href="semantics.html#a-style-sheet-blocking-scripts" title="a style sheet blocking scripts">style sheet blocking
                   5878:        scripts</a> and <var title="">the script</var>'s
                   5879:        <a href="semantics.html#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag is set.</p></li>
                   5880: 
                   5881:        <li><p>Unblock the <a href="#tokenization" title="tokenization">tokenizer</a>
                   5882:        for this instance of the <a href="#html-parser">HTML parser</a>, such that
                   5883:        <a href="browsers.html#concept-task" title="concept-task">tasks</a> that invoke the <a href="#tokenization" title="tokenization">tokenizer</a> can again be
                   5884:        run.</p></li>
1.1       mike     5885: 
                   5886:        <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
                   5887:        <a href="#next-input-character">next input character</a>.</p></li>
                   5888: 
                   5889:        <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
                   5890:        by one (it should be zero before this step, so this sets it to
                   5891:        one).</p></li>
                   5892: 
1.484     mike     5893:        <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute</a>
                   5894:        <var title="">the script</var>.</p></li>
1.1       mike     5895: 
                   5896:        <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
                   5897:        by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
                   5898:        zero (which it always should be at this point), then set the
                   5899:        <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5900: 
                   5901:        </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
                   5902:        again.</p></li>
                   5903: 
1.484     mike     5904:        <li><p>If there is once again a <a href="semantics.html#pending-parsing-blocking-script">pending parsing-blocking
1.1       mike     5905:        script</a>, then repeat these steps from step 1.</p></li>
                   5906: 
                   5907:       </ol></dd>
                   5908: 
                   5909:     </dl></dd>
                   5910: 
                   5911:    <dt>Any other end tag</dt>
                   5912:    <dd>
                   5913: 
                   5914:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5915:     elements</a>.</p>
                   5916: 
                   5917:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5918:     insertion mode</a>.</p>
                   5919: 
                   5920:    </dd>
                   5921: 
                   5922:   </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>
                   5923: 
                   5924:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
                   5925:   mode: in table">in table</a>", tokens must be handled as follows:</p>
                   5926: 
                   5927:   <dl class="switch"><dt>A character token</dt>
                   5928:    <dd>
                   5929: 
                   5930:      <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
                   5931:      be an empty list of tokens.</p>
                   5932: 
                   5933:      <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   5934:      <a href="#insertion-mode">insertion mode</a>.</p>
                   5935: 
                   5936:      <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
                   5937:      reprocess the token.</p>
                   5938: 
                   5939:    </dd>
                   5940: 
                   5941:    <dt>A comment token</dt>
                   5942:    <dd>
                   5943:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   5944:     node</a> with the <code title="">data</code> attribute set to
                   5945:     the data given in the comment token.</p>
                   5946:    </dd>
                   5947: 
                   5948:    <dt>A DOCTYPE token</dt>
                   5949:    <dd>
                   5950:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5951:    </dd>
                   5952: 
                   5953:    <dt>A start tag whose tag name is "caption"</dt>
                   5954:    <dd>
                   5955: 
                   5956:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5957:     below.)</p>
                   5958: 
                   5959:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5960:     formatting elements</a>.</p>
                   5961: 
                   5962:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5963:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
                   5964: 
                   5965:    </dd>
                   5966: 
                   5967:    <dt>A start tag whose tag name is "colgroup"</dt>
                   5968:    <dd>
                   5969: 
                   5970:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5971:     below.)</p>
                   5972: 
                   5973:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5974:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
                   5975:     group</a>".</p>
                   5976: 
                   5977:    </dd>
                   5978: 
                   5979:    <dt>A start tag whose tag name is "col"</dt>
                   5980:    <dd>
                   5981:     <p>Act as if a start tag token with the tag name "colgroup"
                   5982:     had been seen, then reprocess the current token.</p>
                   5983:    </dd>
                   5984: 
                   5985:    <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
                   5986:    <dd>
                   5987: 
                   5988:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5989:     below.)</p>
                   5990: 
                   5991:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5992:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5993:     body</a>".</p>
                   5994: 
                   5995:    </dd>
                   5996: 
                   5997:    <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
                   5998:    <dd>
                   5999:     <p>Act as if a start tag token with the tag name "tbody" had
                   6000:     been seen, then reprocess the current token.</p>
                   6001:    </dd>
                   6002: 
                   6003:    <dt>A start tag whose tag name is "table"</dt>
                   6004:    <dd>
                   6005: 
                   6006:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
                   6007:     the tag name "table" had been seen, then, if that token wasn't
                   6008:     ignored, reprocess the current token.</p>
                   6009: 
                   6010:     <p class="note">The fake end tag token here can only be
                   6011:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6012: 
                   6013:    </dd>
                   6014: 
                   6015:    <dt>An end tag whose tag name is "table"</dt>
                   6016:    <dd>
                   6017: 
                   6018:     <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
                   6019:     scope</a> with the same tag name as the token, this is a
                   6020:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6021:     case</a>)</p>
                   6022: 
                   6023:     <p>Otherwise:</p>
                   6024: 
                   6025:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
                   6026:     element has been popped from the stack.</p>
                   6027: 
                   6028:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   6029: 
                   6030:    </dd>
                   6031: 
                   6032:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6033:    "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
                   6034:    "thead", "tr"</dt>
                   6035:    <dd>
                   6036:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6037:    </dd>
                   6038: 
                   6039:    <dt>A start tag whose tag name is one of: "style", "script"</dt>
                   6040:    <dd>
                   6041: 
                   6042:     <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
                   6043:     mode</a>.</p>
                   6044: 
                   6045:    </dd>
                   6046: 
                   6047:    <dt>A start tag whose tag name is "input"</dt>
                   6048:    <dd>
                   6049: 
                   6050:     <p>If the token does not have an attribute with the name "type",
                   6051:     or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   6052:     case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
                   6053:     else" entry below.</p>
                   6054: 
                   6055:     <p>Otherwise:</p>
                   6056: 
                   6057:     <p><a href="#parse-error">Parse error</a>.</p>
                   6058: 
                   6059:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6060: 
                   6061:     <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
                   6062:     open elements</a>.</p>
                   6063: 
                   6064:    </dd>
                   6065: 
                   6066:    <dt>An end-of-file token</dt>
                   6067:    <dd>
                   6068: 
                   6069:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     6070:     <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     6071:     error</a>.</p>
                   6072: 
                   6073:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6074:     the <a href="#fragment-case">fragment case</a>.</p>
                   6075: 
                   6076:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6077: 
                   6078:    </dd>
                   6079: 
                   6080:    <dt>Anything else</dt>
                   6081:    <dd>
                   6082: 
                   6083:     <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
                   6084:     rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   6085:     body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
                   6086:     <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   6087:     <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
                   6088:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
                   6089:     into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
                   6090: 
                   6091:    </dd>
                   6092: 
                   6093:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
                   6094:   back to a table context</dfn>, it means that the UA must, while
                   6095:   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     6096:   element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1       mike     6097:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6098: 
                   6099:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     6100:   <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     6101:   case</a>.</p>
                   6102: 
                   6103: 
                   6104: 
                   6105:   <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>
                   6106: 
                   6107:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
                   6108:   mode: in table text">in table text</a>", tokens must be handled
                   6109:   as follows:</p>
                   6110: 
                   6111:   <dl class="switch"><dt>A character token</dt>
                   6112:    <dd>
                   6113: 
                   6114:     <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
                   6115:     tokens</a></var> list.</p>
                   6116: 
                   6117:    </dd>
                   6118: 
                   6119: 
                   6120:    <dt>Anything else</dt>
                   6121:    <dd>
                   6122: 
                   6123:     <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
                   6124:     tokens</a></var> list are character tokens that are not one of U+0009
                   6125:     CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
                   6126:     (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
                   6127:     reprocess those character tokens using the rules given in the
                   6128:     "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
                   6129:     table">in table</a>" insertion mode.</p>
                   6130: 
                   6131:     <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
                   6132:     characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
                   6133:     tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
                   6134: 
                   6135:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   6136:     insertion mode</a> and reprocess the token.</p>
                   6137: 
                   6138:    </dd>
                   6139: 
                   6140:   </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>
                   6141: 
                   6142:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
                   6143:   mode: in caption">in caption</a>", tokens must be handled as follows:</p>
                   6144: 
                   6145:   <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
                   6146:    <dd>
                   6147: 
                   6148:     <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
                   6149:     scope</a> with the same tag name as the token, this is a
                   6150:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6151:     case</a>)</p>
                   6152: 
                   6153:     <p>Otherwise:</p>
                   6154: 
                   6155:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   6156: 
                   6157:     <p>Now, if the <a href="#current-node">current node</a> is not a
                   6158:     <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
                   6159:     error</a>.</p>
                   6160: 
                   6161:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
                   6162:     element has been popped from the stack.</p>
                   6163: 
                   6164:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   6165:     the last marker</a>.</p>
                   6166: 
                   6167:     <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>
                   6168: 
                   6169:    </dd>
                   6170: 
                   6171:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6172:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   6173:    <dt>An end tag whose tag name is "table"</dt>
                   6174:    <dd>
                   6175: 
                   6176:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   6177:     name "caption" had been seen, then, if that token wasn't
                   6178:     ignored, reprocess the current token.</p>
                   6179: 
                   6180:     <p class="note">The fake end tag token here can only be
                   6181:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6182: 
                   6183:    </dd>
                   6184: 
                   6185:    <dt>An end tag whose tag name is one of: "body", "col",
                   6186:    "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
                   6187:    "tr"</dt>
                   6188:    <dd>
                   6189:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6190:    </dd>
                   6191: 
                   6192:    <dt>Anything else</dt>
                   6193:    <dd>
                   6194:     <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
                   6195:     mode</a>.</p>
                   6196:    </dd>
                   6197: 
                   6198:   </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>
                   6199: 
                   6200:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
                   6201:   mode: in column group">in column group</a>", tokens must be handled as follows:</p>
                   6202: 
                   6203:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6204:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6205:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6206:    <dd>
                   6207:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6208:     the <a href="#current-node">current node</a>.</p>
                   6209:    </dd>
                   6210: 
                   6211:    <dt>A comment token</dt>
                   6212:    <dd>
                   6213:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6214:     node</a> with the <code title="">data</code> attribute set to
                   6215:     the data given in the comment token.</p>
                   6216:    </dd>
                   6217: 
                   6218:    <dt>A DOCTYPE token</dt>
                   6219:    <dd>
                   6220:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6221:    </dd>
                   6222: 
                   6223:    <dt>A start tag whose tag name is "html"</dt>
                   6224:    <dd>
                   6225:     <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
                   6226:     mode</a>.</p>
                   6227:    </dd>
                   6228: 
                   6229:    <dt>A start tag whose tag name is "col"</dt>
                   6230:    <dd>
                   6231: 
                   6232:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   6233:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6234:     elements</a>.</p>
                   6235: 
                   6236:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   6237:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   6238: 
                   6239:    </dd>
                   6240: 
                   6241:    <dt>An end tag whose tag name is "colgroup"</dt>
                   6242:    <dd>
                   6243: 
                   6244:     <p>If the <a href="#current-node">current node</a> is the root
1.159     mike     6245:     <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     6246:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   6247:     case</a>)</p>
                   6248: 
                   6249:     <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
                   6250:     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
                   6251:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   6252:     "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   6253: 
                   6254:    </dd>
                   6255: 
                   6256:    <dt>An end tag whose tag name is "col"</dt>
                   6257:    <dd>
                   6258:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6259:    </dd>
                   6260: 
                   6261:    <dt>An end-of-file token</dt>
                   6262:    <dd>
                   6263: 
1.159     mike     6264:     <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     6265:     element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
                   6266:     case</a>)</p>
                   6267: 
                   6268:     <p>Otherwise, act as described in the "anything else" entry
                   6269:     below.</p>
                   6270: 
                   6271:    </dd>
                   6272: 
                   6273:    <dt>Anything else</dt>
                   6274:    <dd>
                   6275: 
                   6276:     <p>Act as if an end tag with the tag name "colgroup" had been
                   6277:     seen, and then, if that token wasn't ignored, reprocess the
                   6278:     current token.</p>
                   6279: 
                   6280:     <p class="note">The fake end tag token here can only be
                   6281:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6282: 
                   6283:    </dd>
                   6284: 
                   6285:   </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>
                   6286: 
                   6287:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
                   6288:   mode: in table body">in table body</a>", tokens must be handled as follows:</p>
                   6289: 
                   6290:   <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
                   6291:    <dd>
                   6292: 
                   6293:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6294:     context</a>. (See below.)</p>
                   6295: 
                   6296:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   6297:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
                   6298:     in row">in row</a>".</p>
                   6299: 
                   6300:    </dd>
                   6301: 
                   6302:    <dt>A start tag whose tag name is one of: "th", "td"</dt>
                   6303:    <dd>
                   6304:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
                   6305:     the tag name "tr" had been seen, then reprocess the current
                   6306:     token.</p>
                   6307:    </dd>
                   6308: 
                   6309:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   6310:    "thead"</dt>
                   6311:    <dd>
                   6312: 
                   6313:     <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
                   6314:     scope</a> with the same tag name as the token, this is a
                   6315:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   6316: 
                   6317:     <p>Otherwise:</p>
                   6318: 
                   6319:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6320:     context</a>. (See below.)</p>
                   6321: 
                   6322:     <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
                   6323:     open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   6324:     to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   6325: 
                   6326:    </dd>
                   6327: 
                   6328:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6329:    "colgroup", "tbody", "tfoot", "thead"</dt>
                   6330:    <dt>An end tag whose tag name is "table"</dt>
                   6331:    <dd>
                   6332: 
                   6333:     <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
                   6334:     <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
                   6335:     element in table scope</a>, this is a <a href="#parse-error">parse
                   6336:     error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6337:     case</a>)</p>
                   6338: 
                   6339:     <p>Otherwise:</p>
                   6340: 
                   6341:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6342:     context</a>. (See below.)</p>
                   6343: 
                   6344:     <p>Act as if an end tag with the same tag name as the
                   6345:     <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
                   6346:     been seen, then reprocess the current token.</p>
                   6347: 
                   6348:    </dd>
                   6349: 
                   6350:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6351:    "col", "colgroup", "html", "td", "th", "tr"</dt>
                   6352:    <dd>
                   6353:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6354:    </dd>
                   6355: 
                   6356:    <dt>Anything else</dt>
                   6357:    <dd>
                   6358:     <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
                   6359:     mode</a>.</p>
                   6360:    </dd>
                   6361: 
                   6362:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
                   6363:   back to a table body context</dfn>, it means that the UA must,
                   6364:   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     6365:   <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     6366:   element, pop elements from the <a href="#stack-of-open-elements">stack of open
                   6367:   elements</a>.</p>
                   6368: 
                   6369:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     6370:   <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     6371:   case</a>.</p>
                   6372: 
                   6373: 
                   6374:   <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>
                   6375: 
                   6376:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   6377:   mode: in row">in row</a>", tokens must be handled as follows:</p>
                   6378: 
                   6379:   <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
                   6380:    <dd>
                   6381: 
                   6382:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   6383:     context</a>. (See below.)</p>
                   6384: 
                   6385:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   6386:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
                   6387:     in cell">in cell</a>".</p>
                   6388: 
                   6389:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   6390:     formatting elements</a>.</p>
                   6391: 
                   6392:    </dd>
                   6393: 
                   6394:    <dt>An end tag whose tag name is "tr"</dt>
                   6395:    <dd>
                   6396: 
                   6397:     <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
                   6398:     scope</a> with the same tag name as the token, this is a
                   6399:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6400:     case</a>)</p>
                   6401: 
                   6402:     <p>Otherwise:</p>
                   6403: 
                   6404:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   6405:     context</a>. (See below.)</p>
                   6406: 
                   6407:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   6408:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   6409:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   6410:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   6411:     body</a>".</p>
                   6412: 
                   6413:    </dd>
                   6414: 
                   6415:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6416:    "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
                   6417:    <dt>An end tag whose tag name is "table"</dt>
                   6418:    <dd>
                   6419: 
                   6420:     <p>Act as if an end tag with the tag name "tr" had been seen,
                   6421:     then, if that token wasn't ignored, reprocess the current
                   6422:     token.</p>
                   6423: 
                   6424:     <p class="note">The fake end tag token here can only be
                   6425:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6426: 
                   6427:    </dd>
                   6428: 
                   6429:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   6430:    "thead"</dt>
                   6431:    <dd>
                   6432: 
                   6433:     <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
                   6434:     scope</a> with the same tag name as the token, this is a
                   6435:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   6436: 
                   6437:     <p>Otherwise, act as if an end tag with the tag name "tr" had
                   6438:     been seen, then reprocess the current token.</p>
                   6439: 
                   6440:    </dd>
                   6441: 
                   6442:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6443:    "col", "colgroup", "html", "td", "th"</dt>
                   6444:    <dd>
                   6445:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6446:    </dd>
                   6447: 
                   6448:    <dt>Anything else</dt>
                   6449:    <dd>
                   6450:     <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
                   6451:     mode</a>.</p>
                   6452:    </dd>
                   6453: 
                   6454:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
                   6455:   back to a table row context</dfn>, it means that the UA must,
                   6456:   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     6457:   element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1       mike     6458:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6459: 
                   6460:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     6461:   <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     6462:   case</a>.</p>
                   6463: 
                   6464: 
                   6465:   <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>
                   6466: 
                   6467:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
                   6468:   mode: in cell">in cell</a>", tokens must be handled as follows:</p>
                   6469: 
                   6470:   <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
                   6471:    <dd>
                   6472: 
                   6473:     <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
                   6474:     scope</a> with the same tag name as that of the token, then
                   6475:     this is a <a href="#parse-error">parse error</a> and the token must be
                   6476:     ignored.</p>
                   6477: 
                   6478:     <p>Otherwise:</p>
                   6479: 
                   6480:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   6481: 
                   6482:     <p>Now, if the <a href="#current-node">current node</a> is not an element
                   6483:     with the same tag name as the token, then this is a
                   6484:     <a href="#parse-error">parse error</a>.</p>
                   6485: 
                   6486:     <p>Pop elements from this stack until an element with the same
                   6487:     tag name as the token has been popped from the stack.</p>
                   6488: 
                   6489:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   6490:     the last marker</a>.</p>
                   6491: 
                   6492:     <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
                   6493:     <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
                   6494:     this point.)</p>
                   6495: 
                   6496:    </dd>
                   6497: 
                   6498:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6499:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   6500:    <dd>
                   6501: 
                   6502:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
                   6503:     <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
                   6504:     a <code>td</code> or <code>th</code> element in table
                   6505:     scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
                   6506:     the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6507: 
                   6508:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6509:     reprocess the current token.</p>
                   6510: 
                   6511:    </dd>
                   6512: 
                   6513:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6514:    "col", "colgroup", "html"</dt>
                   6515:    <dd>
                   6516:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6517:    </dd>
                   6518: 
                   6519:    <dt>An end tag whose tag name is one of: "table", "tbody",
                   6520:    "tfoot", "thead", "tr"</dt>
                   6521:    <dd>
                   6522: 
                   6523:     <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
                   6524:     scope</a> with the same tag name as that of the token
                   6525:     (which can only happen for "tbody", "tfoot" and "thead", or,
                   6526:     in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
                   6527:     error</a> and the token must be ignored.</p>
                   6528: 
                   6529:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6530:     reprocess the current token.</p>
                   6531: 
                   6532:    </dd>
                   6533: 
                   6534:    <dt>Anything else</dt>
                   6535:    <dd>
                   6536:     <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
                   6537:     mode</a>.</p>
                   6538:    </dd>
                   6539: 
                   6540:   </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
                   6541:   mean to run the following algorithm:</p>
                   6542: 
                   6543:   <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>
                   6544:    element in table scope</a>, then act as if an end tag token
                   6545:    with the tag name "td" had been seen.</p></li>
                   6546: 
                   6547:    <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
                   6548:    <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
                   6549:    <code>th</code> element in table scope</a>; act as if an end
                   6550:    tag token with the tag name "th" had been seen.</p></li>
                   6551: 
                   6552:   </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
                   6553:   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
                   6554:   the same time, nor can it have neither when the <a href="#insertion-mode">insertion
                   6555:   mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   6556:   cell</a>".</p>
                   6557: 
                   6558: 
                   6559:   <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>
                   6560: 
                   6561:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
                   6562:   mode: in select">in select</a>", tokens must be handled as follows:</p>
                   6563: 
                   6564:   <dl class="switch"><dt>A character token</dt>
                   6565:    <dd>
                   6566:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6567:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6568:    </dd>
                   6569: 
                   6570:    <dt>A comment token</dt>
                   6571:    <dd>
                   6572:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6573:     node</a> with the <code title="">data</code> attribute set to
                   6574:     the data given in the comment token.</p>
                   6575:    </dd>
                   6576: 
                   6577:    <dt>A DOCTYPE token</dt>
                   6578:    <dd>
                   6579:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6580:    </dd>
                   6581: 
                   6582:    <dt>A start tag whose tag name is "html"</dt>
                   6583:    <dd>
                   6584:     <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
                   6585:     mode</a>.</p>
                   6586:    </dd>
                   6587: 
                   6588:    <dt>A start tag whose tag name is "option"</dt>
                   6589:    <dd>
                   6590: 
                   6591:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6592:     element, act as if an end tag with the tag name "option" had
                   6593:     been seen.</p>
                   6594: 
                   6595:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6596: 
                   6597:    </dd>
                   6598: 
                   6599:    <dt>A start tag whose tag name is "optgroup"</dt>
                   6600:    <dd>
                   6601: 
                   6602:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6603:     element, act as if an end tag with the tag name "option" had
                   6604:     been seen.</p>
                   6605: 
                   6606:     <p>If the <a href="#current-node">current node</a> is an
                   6607:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
                   6608:     tag name "optgroup" had been seen.</p>
                   6609: 
                   6610:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6611: 
                   6612:    </dd>
                   6613: 
                   6614:    <dt>An end tag whose tag name is "optgroup"</dt>
                   6615:    <dd>
                   6616: 
                   6617:     <p>First, if the <a href="#current-node">current node</a> is an
                   6618:     <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
                   6619:     it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
                   6620:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
                   6621:     the tag name "option" had been seen.</p>
                   6622: 
                   6623:     <p>If the <a href="#current-node">current node</a> is an
                   6624:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
                   6625:     <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
                   6626:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   6627: 
                   6628:    </dd>
                   6629: 
                   6630:    <dt>An end tag whose tag name is "option"</dt>
                   6631:    <dd>
                   6632: 
                   6633:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6634:     element, then pop that node from the <a href="#stack-of-open-elements">stack of open
                   6635:     elements</a>. Otherwise, this is a <a href="#parse-error">parse
                   6636:     error</a>; ignore the token.</p>
                   6637: 
                   6638:    </dd>
                   6639: 
                   6640:    <dt>An end tag whose tag name is "select"</dt>
                   6641:    <dd>
                   6642: 
                   6643:     <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
                   6644:     scope</a> with the same tag name as the token, this is a
                   6645:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6646:     case</a>)</p>
                   6647: 
                   6648:     <p>Otherwise:</p>
                   6649: 
                   6650:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   6651:     until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
                   6652:     stack.</p>
                   6653: 
                   6654:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   6655: 
                   6656:    </dd>
                   6657: 
                   6658:    <dt>A start tag whose tag name is "select"</dt>
                   6659:    <dd>
                   6660: 
                   6661:     <p><a href="#parse-error">Parse error</a>. Act as if the token had been
                   6662:     an end tag with the tag name "select" instead.</p>
                   6663: 
                   6664:    </dd>
                   6665: 
                   6666:    <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
                   6667:    <dd>
1.73      mike     6668: 
                   6669:     <p><a href="#parse-error">Parse error</a>.</p>
                   6670: 
1.124     mike     6671:     <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>
                   6672:     element in table scope</a>, ignore the token. (<a href="#fragment-case">fragment
                   6673:     case</a>)</p>
1.73      mike     6674: 
                   6675:     <p>Otherwise, act as if an end tag with the tag name "select" had
                   6676:     been seen, and reprocess the token.</p>
                   6677: 
1.1       mike     6678:    </dd>
                   6679: 
                   6680:    <dt>A start tag token whose tag name is "script"</dt>
                   6681:    <dd>
                   6682:     <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
                   6683:     mode</a>.</p>
                   6684:    </dd>
                   6685: 
                   6686:    <dt>An end-of-file token</dt>
                   6687:    <dd>
                   6688: 
                   6689:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     6690:     <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     6691:     error</a>.</p>
                   6692: 
                   6693:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6694:     the <a href="#fragment-case">fragment case</a>.</p>
                   6695: 
                   6696:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6697: 
                   6698:    </dd>
                   6699: 
                   6700:    <dt>Anything else</dt>
                   6701:    <dd>
                   6702:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6703:    </dd>
                   6704: 
                   6705:   </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>
                   6706: 
                   6707:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
                   6708:   mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
                   6709: 
                   6710:   <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
                   6711:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6712:    <dd>
                   6713:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   6714:     name "select" had been seen, and reprocess the token.</p>
                   6715:    </dd>
                   6716: 
                   6717:    <dt>An end tag whose tag name is one of: "caption", "table",
                   6718:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6719:    <dd>
                   6720: 
                   6721:     <p><a href="#parse-error">Parse error</a>.</p>
                   6722: 
                   6723:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
                   6724:     element in table scope</a> with the same tag name as that
                   6725:     of the token, then act as if an end tag with the tag name
                   6726:     "select" had been seen, and reprocess the token. Otherwise,
                   6727:     ignore the token.</p>
                   6728: 
                   6729:    </dd>
                   6730: 
                   6731:    <dt>Anything else</dt>
                   6732:    <dd>
                   6733:     <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
                   6734:     mode</a>.</p>
                   6735:    </dd>
                   6736: 
1.168     mike     6737:   </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     6738: 
                   6739:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
                   6740:   mode: in foreign content">in foreign content</a>", tokens must be
                   6741:   handled as follows:</p>
                   6742: 
                   6743:   <dl class="switch"><dt>A character token</dt>
                   6744:    <dd>
                   6745: 
                   6746:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6747:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6748: 
                   6749:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   6750:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   6751:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   6752:     flag</a> to "not ok".</p>
                   6753: 
                   6754:    </dd>
                   6755: 
                   6756:    <dt>A comment token</dt>
                   6757:    <dd>
                   6758:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6759:     node</a> with the <code title="">data</code> attribute set to
                   6760:     the data given in the comment token.</p>
                   6761:    </dd>
                   6762: 
                   6763:    <dt>A DOCTYPE token</dt>
                   6764:    <dd>
                   6765:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6766:    </dd>
                   6767: 
                   6768:    <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>
                   6769:    <dd>
                   6770: 
                   6771:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6772:     elements</a>.</p>
                   6773: 
                   6774:     <p>Let the <var title="">old insertion point</var> have the
                   6775:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   6776:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   6777:     input character</a>.</p>
                   6778: 
                   6779:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6780:     one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
                   6781: 
                   6782:     <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
                   6783:     the <code title="">script</code> element</a> according to the SVG
1.187     mike     6784:     rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
1.1       mike     6785: 
1.159     mike     6786:     <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     6787:     tokenizer</a>, the parser will not be executed reentrantly,
                   6788:     since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
                   6789: 
                   6790:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6791:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   6792:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   6793: 
                   6794:     <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
                   6795:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   6796:     might be the "undefined" value.)</p>
                   6797: 
                   6798:    </dd>
                   6799: 
                   6800:    <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>
                   6801:    <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>
                   6802:    <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>
                   6803:    <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>
                   6804:    <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>
                   6805:    <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>
                   6806:    <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>
                   6807:    <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>
                   6808:    <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>
                   6809:    <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>
                   6810:    <dt>An end tag</dt>
                   6811:    <dd>
                   6812: 
                   6813:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
                   6814:     <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6815: 
                   6816:     <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
                   6817:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
1.336     mike     6818:     content</a>", but there is no element <a href="#has-an-element-in-scope" title="has an
                   6819:     element in scope">in scope</a> that has a namespace other than
                   6820:     the <a href="#html-namespace-0">HTML namespace</a>, switch the <a href="#insertion-mode">insertion
1.1       mike     6821:     mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6822: 
                   6823:    </dd>
                   6824: 
                   6825:    <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
                   6826:    "blockquote", "body"<!--by inspection-->, "br", "center", "code",
1.422     mike     6827:    "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
                   6828:    uniformly throughout the parser -->, "em", "embed", "h1", "h2",
                   6829:    "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
1.1       mike     6830:    completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
                   6831:    "li", "listing"<!-- so that pre and listing can be handled
                   6832:    uniformly throughout the parser -->, "menu", "meta", "nobr",
                   6833:    "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
                   6834:    the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
                   6835:    "span", "strong", "strike"<!-- so that s and strike can be handled
                   6836:    uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
1.305     mike     6837:    "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt> <!-- this
                   6838:    list was determined empirically by studying over 6,000,000,000
1.422     mike     6839:    pages that were specifically not XML pages -->
                   6840:    <dt>A start tag whose tag name is "font", if the token has any
                   6841:    attributes named "color", "face", or "size"</dt> <!-- the
                   6842:    attributes here are required so that SVG <font> will go through as
                   6843:    SVG but legacy <font>s won't -->
                   6844:    <dt>An end-of-file token</dt> <dd>
1.1       mike     6845: 
                   6846:     <p><a href="#parse-error">Parse error</a>.</p>
                   6847: 
                   6848:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
                   6849:     the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
                   6850:     namespace</a>.</p>
                   6851: 
                   6852:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
                   6853:     insertion mode</a>, and reprocess the token.</p>
                   6854: 
                   6855:    </dd>
                   6856: 
                   6857:    <dt>Any other start tag</dt>
                   6858:    <dd>
                   6859: 
                   6860:     <p>If the <a href="#current-node">current node</a> is an element in the
                   6861:     <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
                   6862:     attributes</a> for the token. (This fixes the case of MathML
                   6863:     attributes that are not all lowercase.)</p>
                   6864: 
                   6865:     <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6866:     namespace</a>, and the token's tag name is one of the ones in
                   6867:     the first column of the following table, change the tag name to
                   6868:     the name given in the corresponding cell in the second
                   6869:     column. (This fixes the case of SVG elements that are not all
                   6870:     lowercase.)</p>
                   6871: 
                   6872:     <table><thead><tr><th> Tag name </th><th> Element name
                   6873:      </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
                   6874:       </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
                   6875:       </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
                   6876:       </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
                   6877:       </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
                   6878:       </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
                   6879:       </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
                   6880:       </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
                   6881:       </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
                   6882:       </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
                   6883:       </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
                   6884:       </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
                   6885:       </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
                   6886:       </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
                   6887:       </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
                   6888:       </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
                   6889:       </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
                   6890:       </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
                   6891:       </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
                   6892:       </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
                   6893:       </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
                   6894:       </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
                   6895:       </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
                   6896:       </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
                   6897:       </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
                   6898:       </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
                   6899:       </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
                   6900:       </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
                   6901:       </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
                   6902:       </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
                   6903:       </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
                   6904:       </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
                   6905:       </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   6906:       </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
                   6907:       </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
                   6908:       <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
                   6909:       </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
                   6910:     </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6911:     namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
                   6912:     token. (This fixes the case of SVG attributes that are not all
                   6913:     lowercase.)</p>
                   6914: 
                   6915:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   6916:     fixes the use of namespaced attributes, in particular XLink in
                   6917:     SVG.)</p>
                   6918: 
                   6919:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   6920:     same namespace as the <a href="#current-node">current node</a>.</p>
                   6921: 
                   6922:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   6923:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6924:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   6925:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   6926: 
                   6927:    </dd>
                   6928: 
                   6929:   </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>
                   6930: 
                   6931:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
                   6932:   mode: after body">after body</a>", tokens must be handled as follows:</p>
                   6933: 
                   6934:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6935:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6936:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6937:    <dd>
                   6938:     <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
                   6939:     mode</a>.</p>
                   6940:    </dd>
                   6941: 
                   6942:    <dt>A comment token</dt>
                   6943:    <dd>
                   6944:     <p>Append a <code>Comment</code> node to the first element in
1.159     mike     6945:     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     6946:     element), with the <code title="">data</code> attribute set to
                   6947:     the data given in the comment token.</p>
                   6948:    </dd>
                   6949: 
                   6950:    <dt>A DOCTYPE token</dt>
                   6951:    <dd>
                   6952:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6953:    </dd>
                   6954: 
                   6955:    <dt>A start tag whose tag name is "html"</dt>
                   6956:    <dd>
                   6957:     <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
                   6958:     mode</a>.</p>
                   6959:    </dd>
                   6960: 
                   6961:    <dt>An end tag whose tag name is "html"</dt>
                   6962:    <dd>
                   6963: 
                   6964:     <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
                   6965:     fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
                   6966:     error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6967: 
                   6968:     <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
                   6969:     body</a>".</p>
                   6970: 
                   6971:    </dd>
                   6972: 
                   6973:    <dt>An end-of-file token</dt>
                   6974:    <dd>
                   6975:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6976:    </dd>
                   6977: 
                   6978:    <dt>Anything else</dt>
                   6979:    <dd>
                   6980: 
                   6981:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
                   6982:     mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   6983:     body</a>" and reprocess the token.</p>
                   6984: 
                   6985:    </dd>
                   6986: 
                   6987:   </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>
                   6988: 
                   6989:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
                   6990:   mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
                   6991: 
                   6992:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6993:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6994:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6995:    <dd>
                   6996:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6997:     the <a href="#current-node">current node</a>.</p>
                   6998:    </dd>
                   6999: 
                   7000:    <dt>A comment token</dt>
                   7001:    <dd>
                   7002:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   7003:     node</a> with the <code title="">data</code> attribute set to
                   7004:     the data given in the comment token.</p>
                   7005:    </dd>
                   7006: 
                   7007:    <dt>A DOCTYPE token</dt>
                   7008:    <dd>
                   7009:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   7010:    </dd>
                   7011: 
                   7012:    <dt>A start tag whose tag name is "html"</dt>
                   7013:    <dd>
                   7014:     <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
                   7015:     mode</a>.</p>
                   7016:    </dd>
                   7017: 
                   7018:    <dt>A start tag whose tag name is "frameset"</dt>
                   7019:    <dd>
                   7020:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   7021:    </dd>
                   7022: 
                   7023:    <dt>An end tag whose tag name is "frameset"</dt>
                   7024:    <dd>
                   7025: 
                   7026:     <p>If the <a href="#current-node">current node</a> is the root
1.159     mike     7027:     <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     7028:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   7029:     case</a>)</p>
                   7030: 
                   7031:     <p>Otherwise, pop the <a href="#current-node">current node</a> from the
                   7032:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   7033: 
                   7034:     <p>If the parser was <em>not</em> originally created as part
                   7035:     of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
                   7036:     (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5       mike     7037:     node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1       mike     7038:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
                   7039:     frameset</a>".</p>
                   7040: 
                   7041:    </dd>
                   7042: 
                   7043:    <dt>A start tag whose tag name is "frame"</dt>
                   7044:    <dd>
                   7045: 
                   7046:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
                   7047:     Immediately pop the <a href="#current-node">current node</a> off the
                   7048:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   7049: 
                   7050:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   7051:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   7052: 
                   7053:    </dd>
                   7054: 
                   7055:    <dt>A start tag whose tag name is "noframes"</dt>
                   7056:    <dd>
                   7057:     <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
                   7058:     mode</a>.</p>
                   7059:    </dd>
                   7060: 
                   7061:    <dt>An end-of-file token</dt>
                   7062:    <dd>
                   7063: 
                   7064:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     7065:     <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     7066:     error</a>.</p>
                   7067: 
                   7068:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   7069:     the <a href="#fragment-case">fragment case</a>.</p>
                   7070: 
                   7071:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   7072: 
                   7073:    </dd>
                   7074: 
                   7075:    <dt>Anything else</dt>
                   7076:    <dd>
                   7077:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   7078:    </dd>
                   7079: 
                   7080:   </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>
                   7081: 
                   7082:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
                   7083:   mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
                   7084: 
                   7085:   <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
                   7086:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   7087:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   7088:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   7089:    <dd>
                   7090:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   7091:     the <a href="#current-node">current node</a>.</p>
                   7092:    </dd>
                   7093: 
                   7094:    <dt>A comment token</dt>
                   7095:    <dd>
                   7096:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   7097:     node</a> with the <code title="">data</code> attribute set to
                   7098:     the data given in the comment token.</p>
                   7099:    </dd>
                   7100: 
                   7101:    <dt>A DOCTYPE token</dt>
                   7102:    <dd>
                   7103:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   7104:    </dd>
                   7105: 
                   7106:    <dt>A start tag whose tag name is "html"</dt>
                   7107:    <dd>
                   7108:     <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
                   7109:     mode</a>.</p>
                   7110:    </dd>
                   7111: 
                   7112:    <dt>An end tag whose tag name is "html"</dt>
                   7113:    <dd>
                   7114:     <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
                   7115:     frameset</a>".</p>
                   7116:    </dd>
                   7117: 
                   7118:    <dt>A start tag whose tag name is "noframes"</dt>
                   7119:    <dd>
                   7120:     <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
                   7121:     mode</a>.</p>
                   7122:    </dd>
                   7123: 
                   7124:    <dt>An end-of-file token</dt>
                   7125:    <dd>
                   7126:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   7127:    </dd>
                   7128: 
                   7129:    <dt>Anything else</dt>
                   7130:    <dd>
                   7131:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   7132:    </dd>
                   7133: 
1.336     mike     7134:   </dl><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>
1.1       mike     7135: 
                   7136:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
                   7137:   mode: after after body">after after body</a>", tokens must be handled as follows:</p>
                   7138: 
                   7139:   <dl class="switch"><dt>A comment token</dt>
                   7140:    <dd>
                   7141:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   7142:     object with the <code title="">data</code> attribute set to the
                   7143:     data given in the comment token.</p>
                   7144:    </dd>
                   7145: 
                   7146:    <dt>A DOCTYPE token</dt>
                   7147:    <dt>A character token that is one of U+0009 CHARACTER
                   7148:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   7149:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   7150:    <dt>A start tag whose tag name is "html"</dt>
                   7151:    <dd>
                   7152:     <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
                   7153:     mode</a>.</p>
                   7154:    </dd>
                   7155: 
                   7156:    <dt>An end-of-file token</dt>
                   7157:    <dd>
                   7158:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   7159:    </dd>
                   7160: 
                   7161:    <dt>Anything else</dt>
                   7162:    <dd>
                   7163:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   7164:     to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
                   7165:     reprocess the token.</p>
                   7166:    </dd>
                   7167: 
                   7168:   </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>
                   7169: 
                   7170:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
                   7171:   mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
                   7172: 
                   7173:   <dl class="switch"><dt>A comment token</dt>
                   7174:    <dd>
                   7175:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   7176:     object with the <code title="">data</code> attribute set to the
                   7177:     data given in the comment token.</p>
                   7178:    </dd>
                   7179: 
                   7180:    <dt>A DOCTYPE token</dt>
                   7181:    <dt>A character token that is one of U+0009 CHARACTER
                   7182:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   7183:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   7184:    <dt>A start tag whose tag name is "html"</dt>
                   7185:    <dd>
                   7186:     <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
                   7187:     mode</a>.</p>
                   7188:    </dd>
                   7189: 
                   7190:    <dt>An end-of-file token</dt>
                   7191:    <dd>
                   7192:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   7193:    </dd>
                   7194: 
                   7195:    <dt>A start tag whose tag name is "noframes"</dt>
                   7196:    <dd>
                   7197:     <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
                   7198:     mode</a>.</p>
                   7199:    </dd>
                   7200: 
                   7201:    <dt>Anything else</dt>
                   7202:    <dd>
                   7203:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   7204:    </dd>
                   7205: 
1.266     mike     7206:   </dl></div><div class="impl">
                   7207: 
                   7208:   <h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4>
1.1       mike     7209: 
                   7210:   <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
1.484     mike     7211:   the document, the user agent must run the following steps:</p>
1.1       mike     7212: 
1.484     mike     7213:   <ol><!-- this happens as part of one of the tasks that runs the parser --><li><p>Set the <a href="dom.html#current-document-readiness">current document readiness</a> to
                   7214:    "interactive" <!-- this also synchronously fires an event --> and
                   7215:    the <a href="#insertion-point">insertion point</a> to undefined.</p></li>
                   7216: 
                   7217:    <li><p>If the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the
                   7218:    document has finished parsing</a> is not empty, run these
                   7219:    substeps:</p>
                   7220: 
                   7221:     <ol><li><p><a href="browsers.html#spin-the-event-loop">Spin the event loop</a> until the first
                   7222:      <code><a href="semantics.html#script">script</a></code> in the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will
                   7223:      execute when the document has finished parsing</a> has its
                   7224:      <a href="semantics.html#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag set <em>and</em> there
                   7225:      is no <a href="semantics.html#a-style-sheet-blocking-scripts" title="a style sheet blocking scripts">style sheet
                   7226:      blocking scripts</a>.</p></li>
                   7227: 
                   7228:      <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute</a> the
                   7229:      first <code><a href="semantics.html#script">script</a></code> in the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will
                   7230:      execute when the document has finished parsing</a>.</p></li>
                   7231: 
                   7232:      <li><p>Remove the first <code><a href="semantics.html#script">script</a></code> element from the
                   7233:      <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the document has
                   7234:      finished parsing</a> (i.e. shift out the first entry in the
                   7235:      list).</p></li>
                   7236:  
                   7237:      <li><p>If the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the
                   7238:      document has finished parsing</a> is still not empty, repeat
                   7239:      these substeps again from substep 1.</p>
                   7240: 
                   7241:     </li></ol></li>
                   7242: 
                   7243:    <li><p><a href="browsers.html#spin-the-event-loop">Spin the event loop</a> until the the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of
                   7244:    scripts that will execute as soon as possible</a> is
                   7245:    empty.</p></li>
                   7246: 
                   7247:    <li><p><a href="browsers.html#queue-a-task">Queue a task</a> to <a href="browsers.html#fire-a-simple-event">fire a simple
                   7248:    event</a> named <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
                   7249:    <code>Document</code>.</p></li>
                   7250: 
                   7251:    <li><p><a href="browsers.html#spin-the-event-loop">Spin the event loop</a> until there is nothing that
                   7252:    <dfn id="delay-the-load-event" title="delay the load event">delays the load event</dfn> in
                   7253:    the <code>Document</code>.</p></li>
                   7254: 
                   7255:    <li><p><a href="browsers.html#queue-a-task">Queue a task</a> to set the <a href="dom.html#current-document-readiness">current document
                   7256:    readiness</a> to "complete". <!-- this also fires an event
                   7257:    synchronously during the task --></p></li>
1.1       mike     7258: 
1.484     mike     7259:    <li><p>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
1.1       mike     7260:    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
1.460     mike     7261:    simple event</a> named <code title="event-load">load</code> at
1.1       mike     7262:    the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
                   7263:    its <code title="dom-event-target">target</code> set to the
                   7264:    <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
1.484     mike     7265:    <code><a href="browsers.html#window">Window</a></code> object).</p></li>
1.1       mike     7266: 
1.484     mike     7267:    <li><p>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
1.1       mike     7268:    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
                   7269:    <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
                   7270:    <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
                   7271:    current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
1.484     mike     7272:    must bubble but not be cancelable and has no default
                   7273:    action.</p></li>
1.1       mike     7274: 
1.484     mike     7275:   </ol><p>The <a href="browsers.html#task-source">task source</a> for the <a href="browsers.html#concept-task" title="concept-task">tasks</a> mentioned in this section is the
                   7276:   <a href="browsers.html#dom-manipulation-task-source">DOM manipulation task source</a>.</p>
1.1       mike     7277: 
1.266     mike     7278:   </div><div class="impl">
1.1       mike     7279: 
                   7280:   <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4>
                   7281: 
                   7282:   <p>When an application uses an <a href="#html-parser">HTML parser</a> in
                   7283:   conjunction with an XML pipeline, it is possible that the
                   7284:   constructed DOM is not compatible with the XML tool chain in certain
                   7285:   subtle ways. For example, an XML toolchain might not be able to
                   7286:   represent attributes with the name <code title="">xmlns</code>,
                   7287:   since they conflict with the Namespaces in XML syntax. There is also
                   7288:   some data that the <a href="#html-parser">HTML parser</a> generates that isn't
                   7289:   included in the DOM itself. This section specifies some rules for
                   7290:   handling these issues.</p>
                   7291: 
                   7292:   <p>If the XML API being used doesn't support DOCTYPEs, the tool may
                   7293:   drop DOCTYPEs altogether.</p>
                   7294: 
                   7295:   <p>If the XML API doesn't support attributes in no namespace that
                   7296:   are named "<code title="">xmlns</code>", attributes whose names
                   7297:   start with "<code title="">xmlns:</code>", or attributes in the
                   7298:   <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
                   7299:   attributes.</p>
                   7300: 
                   7301:   <p>The tool may annotate the output with any namespace declarations
                   7302:   required for proper operation.</p>
                   7303: 
                   7304:   <p>If the XML API being used restricts the allowable characters in
                   7305:   the local names of elements and attributes, then the tool may map
                   7306:   all element and attribute local names that the API wouldn't support
                   7307:   to a set of names that <em>are</em> allowed, by replacing any
                   7308:   character that isn't supported with the uppercase letter U and the
                   7309:   six digits of the character's Unicode code point when expressed in
                   7310:   hexadecimal, using digits 0-9 and capital letters A-F as the
                   7311:   symbols, in increasing numeric order.</p>
                   7312: 
                   7313:   <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
                   7314:   parser</a>, though it is neither a legal HTML element name nor a
                   7315:   well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
                   7316:   element name (though it's still not legal in HTML by any means).</p>
                   7317: 
                   7318:   <p class="example">As another example, consider the attribute
                   7319:   <code>xlink:href</code>. Used on a MathML element, it becomes, after
                   7320:   being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
                   7321:   attribute with a prefix "<code title="">xlink</code>" and a local
                   7322:   name "<code title="">href</code>". However, used on an HTML element,
                   7323:   it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
                   7324:   might not be accepted by an XML API. It could thus get converted,
                   7325:   becoming "<code title="">xlinkU00003Ahref</code>".</p>
                   7326: 
                   7327:   <p class="note">The resulting names from this conversion
                   7328:   conveniently can't clash with any attribute generated by the
                   7329:   <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
                   7330:   those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
                   7331:   algorithm's table.</p>
                   7332: 
                   7333:   <p>If the XML API restricts comments from having two consecutive
                   7334:   U+002D HYPHEN-MINUS characters (--), the tool may insert a single
                   7335:   U+0020 SPACE character between any such offending characters.</p>
                   7336: 
                   7337:   <p>If the XML API restricts comments from ending in a
                   7338:   U+002D HYPHEN-MINUS character (-), the tool may insert a single
                   7339:   U+0020 SPACE character at the end of such comments.</p>
                   7340: 
                   7341:   <p>If the XML API restricts allowed characters in character data,
1.439     mike     7342:   attribute values, or comments, the tool may replace any U+000C FORM
                   7343:   FEED (FF) character with a U+0020 SPACE character, and any other
                   7344:   literal non-XML character with a U+FFFD REPLACEMENT CHARACTER.</p>
1.1       mike     7345: 
                   7346:   <p>If the tool has no way to convey out-of-band information, then
                   7347:   the tool may drop the following information:</p>
                   7348: 
                   7349:   <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
                   7350:    <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>
                   7351: 
                   7352:    <li>The association between form controls and forms that aren't
                   7353:    their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
                   7354:    <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
                   7355: 
                   7356:   </ul><p class="note">The mutations allowed by this section apply
                   7357:   <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
                   7358:   applied. For example, a <code title="">&lt;a::&gt;</code> start tag
                   7359:   will be closed by a <code title="">&lt;/a::&gt;</code> end tag, and
                   7360:   never by a <code title="">&lt;/aU00003AU00003A&gt;</code> end tag, even
                   7361:   if the user agent is using the rules above to then generate an
                   7362:   actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
                   7363: 
1.266     mike     7364:   </div><div class="impl">
1.1       mike     7365: 
1.35      mike     7366:   <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     7367: 
                   7368:   <p><i>This section is non-normative.</i></p>
                   7369: 
                   7370:   <p>This section examines some erroneous markup and discusses how
                   7371:   the <a href="#html-parser">HTML parser</a> handles these cases.</p>
                   7372: 
                   7373: 
                   7374:   <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>
                   7375: 
                   7376:   <p><i>This section is non-normative.</i></p>
                   7377: 
                   7378:   <p>The most-often discussed example of erroneous markup is as
                   7379:   follows:</p>
                   7380: 
                   7381:   <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>
                   7382: 
                   7383:   <p>The parsing of this markup is straightforward up to the "3". At
                   7384:   this point, the DOM looks like this:</p>
                   7385: 
1.159     mike     7386:   <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
                   7387:   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     7388:   <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
                   7389:   formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
                   7390:   <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>
                   7391: 
                   7392:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
                   7393:   invoked. This is a simple case, in that the <var title="">formatting
                   7394:   element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
                   7395:   <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
1.159     mike     7396:   elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element-0">html</a></code>,
                   7397:   <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     7398:   active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
                   7399:   DOM tree is unmodified at this point.</p>
                   7400: 
                   7401:   <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
                   7402:   the active formatting elements</a>, in this case just the
                   7403:   <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
                   7404:   for the "4" text node. After the end tag token for the "i" is also
                   7405:   received, and the "5" text node is inserted, the DOM looks as
                   7406:   follows:</p>
                   7407: 
1.159     mike     7408:   <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     7409: 
                   7410:   <p><i>This section is non-normative.</i></p>
                   7411: 
                   7412:   <p>A case similar to the previous one is the following:</p>
                   7413: 
                   7414:   <pre>&lt;b&gt;1&lt;p&gt;2&lt;/b&gt;3&lt;/p&gt;</pre>
                   7415: 
                   7416:   <p>Up to the "2" the parsing here is straightforward:</p>
                   7417: 
1.159     mike     7418:   <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     7419:   "b" is parsed.</p>
                   7420: 
                   7421:   <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
1.159     mike     7422:   elements</a> has four elements on it: <code><a href="semantics.html#the-html-element-0">html</a></code>,
                   7423:   <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     7424:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
                   7425:   <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>
                   7426: 
                   7427:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
                   7428:   in the previous example. However, in this case, there <em>is</em> a
                   7429:   <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
                   7430:   this time the adoption agency algorithm isn't skipped over.</p>
                   7431: 
1.159     mike     7432:   <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1       mike     7433:   element. A conceptual "bookmark" marks the position of the
                   7434:   <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
                   7435:   elements</a>, but since that list has only one element in it,
                   7436:   it won't have much effect.</p>
                   7437: 
                   7438:   <p>As the algorithm progresses, <var title="">node</var> ends up set
                   7439:   to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
                   7440:   node</var> ends up set to the <var title="">furthest block</var>
                   7441:   (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7442: 
                   7443:   <p>The <var title="">last node</var> gets appended (moved) to the
                   7444:   <var title="">common ancestor</var>, so that the DOM looks like:</p>
                   7445: 
1.159     mike     7446:   <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     7447:   <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
                   7448: 
1.159     mike     7449:   <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     7450:   <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
                   7451: 
1.159     mike     7452:   <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     7453:   active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
                   7454:   elements</a>, so that when the "3" is parsed, it is appended to
                   7455:   the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
                   7456: 
1.159     mike     7457:   <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     7458: 
                   7459:   <p><i>This section is non-normative.</i></p>
                   7460: 
                   7461:   <p>Error handling in tables is, for historical reasons, especially
                   7462:   strange. For example, consider the following markup:</p>
                   7463: 
                   7464:   <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>
                   7465: 
                   7466:   <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
                   7467:   directly inside a table like that, and the parser handles this case
                   7468:   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
                   7469:   examining the DOM tree as it stands just after the
                   7470:   <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
                   7471: 
1.159     mike     7472:   <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     7473:   tag has been seen:</p>
                   7474: 
1.159     mike     7475:   <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
                   7476:   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     7477:   <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
                   7478:   resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
                   7479:   elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
                   7480:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
                   7481:   table">in table</a>".</p>
                   7482: 
                   7483:   <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
                   7484:   to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
                   7485:   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
                   7486:   then handled in a rather straight-forward manner, taking the parser
                   7487:   through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   7488:   body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   7489:   row</a>" insertion modes, after which the DOM looks as
                   7490:   follows:</p>
                   7491: 
1.159     mike     7492:   <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
                   7493:   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     7494:   <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
                   7495:   formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
                   7496:   it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   7497:   mode: in row">in row</a>".</p>
                   7498: 
                   7499:   <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
                   7500:   <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
                   7501:   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
                   7502:   mode</a>).</p>
                   7503: 
1.159     mike     7504:   <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     7505:   no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
                   7506:   node:</p>
                   7507: 
1.159     mike     7508:   <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     7509:   handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
1.159     mike     7510:   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     7511:   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
                   7512:   elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
                   7513:   marker having been removed by the "td" end tag token); and the
                   7514:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
                   7515:   table body">in table body</a>".</p>
                   7516: 
                   7517:   <p>Thus it is that the "bbb" character tokens are found. These
                   7518:   trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
                   7519:   text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
                   7520:   insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
                   7521:   body">in table body</a>"). The character tokens are collected,
                   7522:   and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
                   7523:   seen, they are processed as a group. Since they are not all spaces,
                   7524:   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,
                   7525:   which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   7526:   body</a>" insertion mode but with <a href="#foster-parent" title="foster
                   7527:   parent">foster parenting</a>.</p>
                   7528: 
                   7529:   <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
                   7530:   active formatting elements are reconstructed</a>, a
                   7531:   <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
                   7532:   parent">foster parented</a>, and then the "bbb" text node is
                   7533:   appended to it:</p>
                   7534: 
1.159     mike     7535:   <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
                   7536:   <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     7537:   <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
                   7538:   this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
                   7539:   formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
                   7540:   and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
                   7541:   mode: in table body">in table body</a>".</p>
                   7542: 
                   7543:   <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
                   7544:   character">space characters</a> instead of "bbb", then those
                   7545:   <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
                   7546:   appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
                   7547: 
                   7548:   <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
                   7549:   tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
                   7550:   elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   7551:   but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
                   7552:   elements</a>, so the "ccc" character tokens after the table
                   7553:   result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
                   7554:   time after the table:</p>
                   7555: 
1.159     mike     7556:   <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     7557: 
                   7558:   <p><i>This section is non-normative.</i></p>
                   7559: 
                   7560:   <p>Consider the following markup, which for this example we will
                   7561:   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     7562:   content of an <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code> in another document with the
1.1       mike     7563:   <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
                   7564: 
                   7565:   <pre>&lt;div id=a&gt;
                   7566:  &lt;script&gt;
                   7567:   var div = document.getElementById('a');
                   7568:   parent.document.body.appendChild(div);
                   7569:  &lt;/script&gt;
                   7570:  &lt;script&gt;
                   7571:   alert(document.URL);
                   7572:  &lt;/script&gt;
                   7573: &lt;/div&gt;
                   7574: &lt;script&gt;
                   7575:  alert(document.URL);
                   7576: &lt;/script&gt;</pre>
                   7577: 
                   7578:   <p>Up to the first "script" end tag, before the script is parsed,
                   7579:   the result is relatively straightforward:</p>
                   7580: 
1.306     mike     7581:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-div-element">div</a></code> <span class="t2" title=""><code class="attribute name">id</code>="<code class="attribute value"><a href="text-level-semantics.html#the-a-element">a</a></code>"</span><ul><li class="t3"><code>#text</code>: <span title="">
                   7582:  </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="semantics.html#the-div-element">div</a></code> element
1.1       mike     7583:   and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
                   7584: 
1.159     mike     7585:   <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     7586:   aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
                   7587:   <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
1.306     mike     7588:   <code><a href="semantics.html#the-div-element">div</a></code> element</em>.</p>
1.1       mike     7589: 
                   7590:   <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
                   7591:   is inserted <em>into the outer <code>Document</code>
                   7592:   object</em>.</p>
                   7593: 
                   7594:   <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
                   7595:   the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
                   7596:   object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
1.159     mike     7597:   <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>.</p>
1.1       mike     7598: 
                   7599:   <p class="note">This isn't a security problem since the script that
1.306     mike     7600:   moves the <code><a href="semantics.html#the-div-element">div</a></code> into the outer <code>Document</code> can
1.1       mike     7601:   only do so because they have the two <code>Document</code> object
1.159     mike     7602:   have the same <a href="browsers.html#origin">origin</a>.</p>
1.1       mike     7603: 
                   7604:   <p>Thus, the first alert says "http://example.com/outer".</p>
                   7605: 
1.306     mike     7606:   <p>Once the <code><a href="semantics.html#the-div-element">div</a></code> element's end tag is parsed, the
                   7607:   <code><a href="semantics.html#the-div-element">div</a></code> element is popped off the stack, and so the next
1.1       mike     7608:   <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
                   7609: 
1.159     mike     7610:   <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     7611: 
                   7612: 
                   7613: 
1.215     mike     7614:   <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3>
1.1       mike     7615: 
                   7616:   <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
                   7617: 
                   7618:   <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
                   7619: 
                   7620:   <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
                   7621: 
                   7622:   <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
                   7623: 
                   7624:   <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
                   7625: 
                   7626:   <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
                   7627: 
                   7628:   <hr><p>Data mining tools and other user agents that perform operations
1.83      mike     7629:   on <code><a href="iana-considerations.html#text-html">text/html</a></code> content without running scripts,
1.1       mike     7630:   evaluating CSS or XPath expressions, or otherwise exposing the
                   7631:   resulting DOM to arbitrary content, may "support namespaces" by just
                   7632:   asserting that their DOM node analogues are in certain namespaces,
                   7633:   without actually exposing the above strings.</p>
                   7634: 
                   7635: 
                   7636: 
                   7637: 
                   7638:   <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3>
                   7639: 
                   7640:   <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
                   7641:   algorithm</dfn>. The algorithm takes as input a DOM
                   7642:   <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
                   7643:   exception.</p>
                   7644: 
                   7645:   <p class="note">This algorithm serializes the <em>children</em> of
                   7646:   the node being serialized, not the node itself.</p>
                   7647: 
                   7648:   <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
                   7649:    the empty string.</p></li>
                   7650: 
                   7651:    <li>
                   7652: 
                   7653:     <p>For each child node of <var title="">the node</var>, in
                   7654:     <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
                   7655: 
                   7656:     </p><ol><li><p>Let <var title="">current node</var> be the child node
                   7657:      being processed.</p></li>
                   7658: 
                   7659:      <li>
                   7660: 
                   7661:       <p>Append the appropriate string from the following list to
                   7662:       <var title="">s</var>:</p>
                   7663: 
                   7664:       <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
                   7665: 
                   7666:        <dd>
                   7667: 
                   7668:         <p>Append a U+003C LESS-THAN SIGN (<code title="">&lt;</code>)
                   7669:         character, followed by the element's tag name. (For nodes
                   7670:         created by the <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
                   7671:         lowercase.)</p>
                   7672: 
                   7673:         <p>For each attribute that the element has, append a U+0020
                   7674:         SPACE character, the attribute's name (which, for attributes
                   7675:         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
                   7676:         U+003D EQUALS SIGN (<code title="">=</code>) character, a
                   7677:         U+0022 QUOTATION MARK (<code title="">"</code>)
                   7678:         character, the attribute's value, <a href="#escapingString" title="escaping a
                   7679:         string">escaped as described below</a> in <i>attribute
                   7680:         mode</i>, and a second U+0022 QUOTATION MARK (<code title="">"</code>) character.</p>
                   7681: 
                   7682:         <p>While the exact order of attributes is UA-defined, and may
                   7683:         depend on factors such as the order that the attributes were
                   7684:         given in the original markup, the sort order must be stable,
                   7685:         such that consecutive invocations of this algorithm serialize an
                   7686:         element's attributes in the same order.</p>
                   7687: 
                   7688:         <p>Append a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>)
                   7689:         character.</p>
                   7690: 
                   7691:         <p>If <var title="">current node</var> is an
1.5       mike     7692:         <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     7693:         <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     7694:         <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>,
                   7695:         <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>,
                   7696:         <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     7697:         <code><a href="obsolete.html#spacer">spacer</a></code>, or <code>wbr</code> element, then
1.1       mike     7698:         continue on to the next child node at this point.</p> <!--
                   7699:         also, i guess: image and isindex, but we don't list those
                   7700:         because we don't consider those "elements", more "macros", and
                   7701:         thus we should never serialize them -->
                   7702: 
                   7703:         <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42      mike     7704:         <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     7705:         a U+000A LINE FEED (LF) character.</p>
                   7706: 
                   7707:         <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
                   7708:         serialization algorithm</a> on the <var title="">current
                   7709:         node</var> element (thus recursing into this algorithm for
                   7710:         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,
                   7711:         and finally a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>) character.</p>
                   7712: 
                   7713:        </dd>
                   7714: 
                   7715: 
                   7716:        <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
                   7717:        node</dt>
                   7718: 
                   7719:        <dd>
                   7720: 
1.19      mike     7721:         <p>If the parent of <var title="">current node</var> is a
1.42      mike     7722:         <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     7723:         <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     7724:         <code><a href="obsolete.html#noframes">noframes</a></code>, or <code><a href="obsolete.html#plaintext">plaintext</a></code> element, or
                   7725:         if the parent of <var title="">current node</var> is
                   7726:         <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
                   7727:         node, then append the value of <var title="">current
                   7728:         node</var>'s <code title="">data</code> IDL attribute
                   7729:         literally.</p>
1.1       mike     7730: 
                   7731:         <p>Otherwise, append the value of <var title="">current
1.192     mike     7732:         node</var>'s <code title="">data</code> IDL attribute, <a href="#escapingString" title="escaping a string">escaped as described
1.1       mike     7733:         below</a>.</p>
                   7734: 
                   7735:        </dd>
                   7736: 
                   7737: 
                   7738:        <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
                   7739: 
                   7740:        <dd>
                   7741: 
                   7742:         <p>Append the literal string <code>&lt;!--</code> (U+003C
                   7743:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
1.192     mike     7744:         U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1       mike     7745:         attribute, followed by the literal string <code>--&gt;</code>
                   7746:         (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
                   7747:         SIGN).</p>
                   7748: 
                   7749:        </dd>
                   7750: 
                   7751: 
                   7752:        <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
                   7753: 
                   7754:        <dd>
                   7755: 
                   7756:         <p>Append the literal string <code>&lt;?</code> (U+003C
                   7757:         LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
1.192     mike     7758:         of <var title="">current node</var>'s <code title="">target</code> IDL attribute, followed by a single
                   7759:         U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1       mike     7760:         attribute, followed by a single U+003E GREATER-THAN SIGN
1.464     mike     7761:         character (&gt;).</p>
1.1       mike     7762: 
                   7763:        </dd>
                   7764: 
                   7765: 
                   7766:        <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
                   7767: 
                   7768:        <dd>
                   7769: 
                   7770:         <p>Append the literal string <code>&lt;!DOCTYPE</code> (U+003C
                   7771:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
                   7772:         LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
                   7773:         LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
                   7774:         LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
                   7775:         LETTER E), followed by a space (U+0020 SPACE), followed by the
1.192     mike     7776:         value of <var title="">current node</var>'s <code title="">name</code> IDL attribute, followed by the literal
1.1       mike     7777:         string <code>&gt;</code> (U+003E GREATER-THAN SIGN).</p>
                   7778: 
                   7779:        </dd>
                   7780: 
                   7781: 
                   7782:       </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
                   7783:       occur as children of elements. If, despite this, they somehow do
                   7784:       occur, this algorithm must raise an
                   7785:       <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
                   7786: 
                   7787:      </li>
                   7788: 
                   7789:     </ol></li>
                   7790: 
                   7791:    <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
                   7792: 
                   7793:   </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
                   7794:   purposes of the algorithm above) consists of replacing any
                   7795:   occurrences of the "<code title="">&amp;</code>" character by the
                   7796:   string "<code title="">&amp;amp;</code>", any occurrences of the
                   7797:   U+00A0 NO-BREAK SPACE character by the string "<code title="">&amp;nbsp;</code>", and, if the algorithm was invoked in
                   7798:   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
                   7799:   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>
                   7800: 
                   7801:   <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
                   7802:   agent, and are therefore not covered in the algorithm above.</p>
                   7803: 
                   7804:   <p class="note">It is possible that the output of this algorithm, if
                   7805:   parsed with an <a href="#html-parser">HTML parser</a>, will not return the
                   7806:   original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
                   7807:   element to which a <code title="">Comment</code> node has been
                   7808:   appended is serialized and the output is then reparsed, the comment
                   7809:   will end up being displayed in the text field. Similarly, if, as a
                   7810:   result of DOM manipulation, an element contains a comment that
                   7811:   contains the literal string "<code title="">--&gt;</code>", then
                   7812:   when the result of serializing the element is parsed, the comment
                   7813:   will be truncated at that point and the rest of the comment will be
                   7814:   interpreted as markup. More examples would be making a
                   7815:   <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
                   7816:   "<code>&lt;/script&gt;</code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
                   7817:   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
                   7818:   <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
                   7819:   tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7820: 
                   7821: 
                   7822:   <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3>
                   7823: 
                   7824:   <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
                   7825:   algorithm</dfn>. The algorithm optionally takes as input an
                   7826:   <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
                   7827:   parser, as well as <var title="">input</var>, a string to parse, and
                   7828:   returns a list of zero or more nodes.</p>
                   7829: 
                   7830:   <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
                   7831:   in the parser section are parts that only occur if the parser was
                   7832:   created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
                   7833:   with such markings for informational purposes only; such markings
                   7834:   have no normative weight. If it is possible for a condition
                   7835:   described as a <a href="#fragment-case">fragment case</a> to occur even when the
                   7836:   parser wasn't created for the purposes of handling this algorithm,
                   7837:   then that is an error in the specification.</p>
                   7838: 
                   7839:   <ol><li>
                   7840: 
                   7841:     <p>Create a new <code>Document</code> node, and mark it as being
                   7842:     an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                   7843: 
                   7844:    </li>
                   7845: 
                   7846:    <li>
                   7847: 
                   7848:     <p>If there is a <var title="">context</var> element, and the
                   7849:     <code>Document</code> of the <var title="">context</var> element
                   7850:     is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
                   7851:     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
                   7852:     the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
                   7853:     mode</a>, then let the <code>Document</code> be in
                   7854:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
                   7855:     <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
                   7856: 
                   7857:    </li>
                   7858: 
                   7859:    <li>
                   7860: 
                   7861:     <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
                   7862:     the just created <code>Document</code> node.</p>
                   7863: 
                   7864:    </li>
                   7865: 
                   7866:    <li>
                   7867: 
                   7868:     <p>If there is a <var title="">context</var> element, run these
                   7869:     substeps:</p>
                   7870: 
                   7871:     <ol><li>
                   7872: 
                   7873:       <p>Set the <a href="#html-parser">HTML parser</a>'s <a href="#tokenization">tokenization</a>
                   7874:       stage's <a href="#content-model-flag">content model flag</a> according to the <var title="">context</var> element, as follows:</p>
                   7875: 
1.159     mike     7876:       <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     7877:        element</dt>
                   7878: 
                   7879:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7880:        the RCDATA state.</dd>
                   7881: 
                   7882: 
                   7883:        <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     7884:        <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     7885:        <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1       mike     7886: 
                   7887:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
1.91      mike     7888:        the RAWTEXT state.</dd>
1.1       mike     7889: 
                   7890: 
                   7891:        <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
                   7892: 
                   7893:        <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, set the
1.91      mike     7894:        <a href="#content-model-flag">content model flag</a> to the RAWTEXT
1.1       mike     7895:        state. Otherwise, set the <a href="#content-model-flag">content model flag</a> to the
                   7896:        PCDATA state.</dd>
                   7897: 
                   7898: 
1.42      mike     7899:        <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1       mike     7900: 
                   7901:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7902:        PLAINTEXT.</dd>
                   7903: 
                   7904: 
                   7905:        <dt>Otherwise</dt>
                   7906: 
                   7907:        <dd>Leave the <a href="#content-model-flag">content model flag</a> in the PCDATA
                   7908:        state.</dd>
                   7909: 
                   7910:       </dl></li>
                   7911: 
                   7912:      <li>
                   7913: 
1.159     mike     7914:       <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     7915:       with no attributes.</p>
                   7916: 
                   7917:      </li>
                   7918: 
                   7919:      <li>
                   7920: 
                   7921:       <p>Append the element <var title="">root</var> to the
                   7922:       <code>Document</code> node created above.</p>
                   7923: 
                   7924:      </li>
                   7925: 
                   7926:      <li>
                   7927: 
                   7928:       <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
                   7929:       it contains just the single element <var title="">root</var>.</p>
                   7930: 
                   7931:      </li>
                   7932: 
                   7933:      <li>
                   7934: 
                   7935:       <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
                   7936:       parser's insertion mode appropriately</a>.</p>
                   7937: 
                   7938:       <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
                   7939: 
                   7940:      </li>
                   7941: 
                   7942:      <li>
                   7943: 
                   7944:       <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
                   7945:       to the nearest node to the <var title="">context</var> element
                   7946:       that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
                   7947:       ancestor chain, and including the element itself, if it is a
                   7948:       <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
                   7949:       <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
                   7950: 
                   7951:      </li>
                   7952: 
                   7953:     </ol></li>
                   7954: 
                   7955:    <li>
                   7956: 
                   7957:     <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
                   7958:     parser</a> just created the <var title="">input</var>. The
                   7959:     encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   7960:     <i>irrelevant</i>.</p>
                   7961: 
                   7962:    </li>
                   7963: 
                   7964:    <li>
                   7965: 
                   7966:     <p>Start the parser and let it run until it has consumed all the
                   7967:     characters just inserted into the input stream.</p>
                   7968: 
                   7969:    </li>
                   7970: 
                   7971:    <li>
                   7972: 
                   7973:     <p>If there is a <var title="">context</var> element, return the
                   7974:     child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
                   7975:     order</a>.</p>
                   7976: 
                   7977:     <p>Otherwise, return the children of the <code>Document</code>
                   7978:     object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
                   7979: 
                   7980:    </li>
                   7981: 
1.123     mike     7982:   </ol></div></body></html>

Webmaster